Skip to content

Commit 734c019

Browse files
committed
Merge PR #36 from @zonky2
- Reactivate widget types and sorting
2 parents 5fbf4c2 + 74e3c9a commit 734c019

File tree

4 files changed

+121
-3
lines changed

4 files changed

+121
-3
lines changed

Diff for: .check-author.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ exclude:
77
mapping:
88
"Ingolf Steinhardt <[email protected]>":
99
- "Ingolf Steinhardt <[email protected]>"
10+
- "e-spin <[email protected]>"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
/**
4+
* This file is part of MetaModels/attribute_translatedfile.
5+
*
6+
* (c) 2012-2023 The MetaModels team.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* This project is provided in good faith and hope to be usable by anyone.
12+
*
13+
* @package MetaModels/attribute_translatedfile
14+
* @author Ingolf Steinhardt <[email protected]>
15+
* @copyright 2012-2023 The MetaModels team.
16+
* @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later
17+
* @filesource
18+
*/
19+
20+
declare(strict_types=1);
21+
22+
namespace MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\DcaSetting;
23+
24+
use ContaoCommunityAlliance\DcGeneral\Contao\RequestScopeDeterminator;
25+
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent;
26+
use Doctrine\DBAL\Connection;
27+
use MetaModels\CoreBundle\EventListener\DcGeneral\Table\DcaSetting\AbstractListener;
28+
use MetaModels\IFactory;
29+
30+
/**
31+
* Add the options for the file widget mode.
32+
*/
33+
class FileWidgetModeOptions extends AbstractListener
34+
{
35+
/**
36+
* Invoke the event.
37+
*
38+
* @param GetPropertyOptionsEvent $event The event.
39+
*
40+
* @return void
41+
*/
42+
public function __invoke(GetPropertyOptionsEvent $event): void
43+
{
44+
if (('file_widgetMode' !== $event->getPropertyName())
45+
|| (false === $this->wantToHandle($event))
46+
|| (false === $this->isAttributeTranslatedFile($event))
47+
) {
48+
return;
49+
}
50+
51+
$this->addOptions($event);
52+
}
53+
54+
/**
55+
* Add the options.
56+
*
57+
* @param GetPropertyOptionsEvent $event The event.
58+
*
59+
* @return void
60+
*/
61+
private function addOptions(GetPropertyOptionsEvent $event): void
62+
{
63+
$addOptions = ['downloads', 'gallery'];
64+
65+
$event->setOptions(\array_values(\array_unique(\array_merge($event->getOptions(), $addOptions))));
66+
}
67+
68+
/**
69+
* If used attribute type of file.
70+
*
71+
* @param GetPropertyOptionsEvent $event The event.
72+
*
73+
* @return bool
74+
*/
75+
private function isAttributeTranslatedFile(GetPropertyOptionsEvent $event): bool
76+
{
77+
$builder = $this->connection->createQueryBuilder();
78+
$builder
79+
->select('t.type')
80+
->from('tl_metamodel_attribute', 't')
81+
->where($builder->expr()->eq('t.id', ':id'))
82+
->setParameter('id', $event->getModel()->getProperty('attr_id'));
83+
84+
$statement = $builder->execute();
85+
if (0 === $statement->columnCount()) {
86+
return false;
87+
}
88+
89+
$result = $statement->fetch(\PDO::FETCH_OBJ);
90+
return 'translatedfile' === $result->type;
91+
}
92+
}

Diff for: src/Resources/config/event_listeners.yml

+10
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ services:
3636
event: dc-general.view.contao2backend.get-property-options
3737
method: removeOption
3838
priority: -1
39+
40+
MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\DcaSetting\FileWidgetModeOptions:
41+
public: false
42+
arguments:
43+
$scopeDeterminator: '@cca.dc-general.scope-matcher'
44+
$factory: '@MetaModels\IFactory'
45+
$connection: '@database_connection'
46+
tags:
47+
- name: kernel.event_listener
48+
event: dc-general.view.contao2backend.get-property-options

Diff for: tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php

+18-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of MetaModels/attribute_translatedfile.
55
*
6-
* (c) 2012-2021 The MetaModels team.
6+
* (c) 2012-2023 The MetaModels team.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -14,7 +14,8 @@
1414
* @author David Molineus <[email protected]>
1515
* @author Sven Baumann <[email protected]>
1616
* @author Christian Schiffler <[email protected]>
17-
* @copyright 2012-2021 The MetaModels team.
17+
* @author Ingolf Steinhardt <[email protected]>
18+
* @copyright 2012-2023 The MetaModels team.
1819
* @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later
1920
* @filesource
2021
*/
@@ -27,6 +28,7 @@
2728
use MetaModels\AttributeTranslatedFileBundle\EventListener\BuildAttributeListener;
2829
use MetaModels\AttributeTranslatedFileBundle\EventListener\BuildDataDefinitionListener;
2930
use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\Attribute\RemoveTypeOptions;
31+
use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\DcaSetting\FileWidgetModeOptions;
3032
use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\FilterSetting\RemoveAttIdOptions;
3133
use MetaModels\AttributeTranslatedFileBundle\EventListener\Factory\AddAttributeInformation;
3234
use MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions;
@@ -65,7 +67,7 @@ public function testFactoryIsRegistered()
6567
$container = $this->getMockBuilder(ContainerBuilder::class)->getMock();
6668

6769
$container
68-
->expects(self::exactly(8))
70+
->expects(self::exactly(9))
6971
->method('setDefinition')
7072
->withConsecutive(
7173
[
@@ -168,6 +170,19 @@ function ($value) {
168170
$this->assertEquals(RemoveAttIdOptions::class, $value->getClass());
169171
$this->assertCount(1, $value->getTag('kernel.event_listener'));
170172

173+
return true;
174+
}
175+
)
176+
],
177+
[
178+
FileWidgetModeOptions::class,
179+
self::callback(
180+
function ($value) {
181+
/** @var Definition $value */
182+
$this->assertInstanceOf(Definition::class, $value);
183+
$this->assertEquals(null, $value->getClass());
184+
$this->assertCount(1, $value->getTag('kernel.event_listener'));
185+
171186
return true;
172187
}
173188
)

0 commit comments

Comments
 (0)