33/**
44 * This file is part of MetaModels/attribute_checkbox.
55 *
6- * (c) 2012-2019 The MetaModels team.
6+ * (c) 2012-2020 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.
1515 * @author Christopher Boelter <c.boelter@cogizz.de>
1616 * @author Sven Baumann <baumann.sv@gmail.com>
1717 * @author David Molineus <david.molineus@netzmacht.de>
18- * @copyright 2012-2019 The MetaModels team.
18+ * @author Ingolf Steinhardt <info@e-spin.de>
19+ * @copyright 2012-2020 The MetaModels team.
1920 * @license https://github.com/MetaModels/attribute_checkbox/blob/master/LICENSE LGPL-3.0-or-later
2021 * @filesource
2122 */
3132use ContaoCommunityAlliance \DcGeneral \DataDefinition \Definition \View \ToggleCommandInterface ;
3233use MetaModels \Attribute \IAttribute ;
3334use MetaModels \AttributeCheckboxBundle \Attribute \Checkbox ;
35+ use MetaModels \CoreBundle \Assets \IconBuilder ;
3436use MetaModels \DcGeneral \Events \MetaModel \BuildMetaModelOperationsEvent ;
3537
3638/**
@@ -45,14 +47,24 @@ class BuildMetaModelOperationsListener
4547 */
4648 private $ scopeMatcher ;
4749
50+ /**
51+ * The icon builder.
52+ *
53+ * @var IconBuilder
54+ */
55+ private $ iconBuilder ;
56+
4857 /**
4958 * CreatePropertyConditionListener constructor.
5059 *
5160 * @param RequestScopeDeterminator $scopeMatcher Request scope determinator.
61+ *
62+ * @param IconBuilder $iconBuilder The icon builder.
5263 */
53- public function __construct (RequestScopeDeterminator $ scopeMatcher )
64+ public function __construct (RequestScopeDeterminator $ scopeMatcher, IconBuilder $ iconBuilder )
5465 {
5566 $ this ->scopeMatcher = $ scopeMatcher ;
67+ $ this ->iconBuilder = $ iconBuilder ;
5668 }
5769
5870 /**
@@ -66,7 +78,7 @@ public function __construct(RequestScopeDeterminator $scopeMatcher)
6678 * @SuppressWarnings(PHPMD.Superglobals)
6779 * @SuppressWarnings(PHPMD.CamelCaseVariableName)
6880 */
69- private function buildCommand ($ attribute , array $ propertyData )
81+ private function buildCommand (Checkbox $ attribute , array $ propertyData )
7082 {
7183 if ($ attribute ->get ('check_listview ' ) == 1 ) {
7284 $ commandName = 'listviewtoggle_ ' . $ attribute ->getColName ();
@@ -82,16 +94,18 @@ private function buildCommand($attribute, array $propertyData)
8294 $ attribute ->getName ()
8395 )
8496 );
97+
8598 $ extra = $ toggle ->getExtra ();
8699 $ extra ['icon ' ] = 'visible.svg ' ;
87100 $ objIconEnabled = FilesModel::findByUuid ($ attribute ->get ('check_listviewicon ' ));
88101 $ objIconDisabled = FilesModel::findByUuid ($ attribute ->get ('check_listviewicondisabled ' ));
89102
90- if ($ attribute ->get ('check_listview ' ) == 1 && $ objIconEnabled ->path && $ objIconDisabled ->path ) {
91- $ extra ['icon ' ] = $ objIconEnabled ->path ;
92- $ extra ['icon_disabled ' ] = $ objIconDisabled ->path ;
93- } else {
94- $ extra ['icon ' ] = 'visible.svg ' ;
103+ if ($ attribute ->get ('check_listview ' ) == 1 && $ objIconEnabled ->path ) {
104+ $ extra ['icon ' ] = $ this ->iconBuilder ->getBackendIcon ($ objIconEnabled ->path );
105+ }
106+
107+ if ($ attribute ->get ('check_listview ' ) == 1 && $ objIconDisabled ->path ) {
108+ $ extra ['icon_disabled ' ] = $ this ->iconBuilder ->getBackendIcon ($ objIconDisabled ->path );
95109 }
96110
97111 $ toggle ->setToggleProperty ($ attribute ->getColName ());
@@ -114,7 +128,7 @@ private function buildCommand($attribute, array $propertyData)
114128 *
115129 * @return Contao2BackendViewDefinition
116130 */
117- protected function createBackendViewDefinition ($ container )
131+ protected function createBackendViewDefinition (ContainerInterface $ container )
118132 {
119133 if ($ container ->hasDefinition (Contao2BackendViewDefinitionInterface::NAME )) {
120134 $ view = $ container ->getDefinition (Contao2BackendViewDefinitionInterface::NAME );
@@ -142,9 +156,12 @@ public function handle(BuildMetaModelOperationsEvent $event)
142156 return ;
143157 }
144158 $ allProps = $ event ->getScreen ()['properties ' ];
145- $ properties = \array_map (function ($ property ) {
146- return ($ property ['col_name ' ] ?? null );
147- }, $ allProps );
159+ $ properties = \array_map (
160+ function ($ property ) {
161+ return ($ property ['col_name ' ] ?? null );
162+ },
163+ $ allProps
164+ );
148165 foreach ($ event ->getMetaModel ()->getAttributes () as $ attribute ) {
149166 if (!$ this ->wantToAdd ($ attribute , $ properties )) {
150167 continue ;
@@ -153,6 +170,7 @@ public function handle(BuildMetaModelOperationsEvent $event)
153170 foreach ($ allProps as $ prop ) {
154171 if ($ prop ['col_name ' ] === $ attribute ->getColName ()) {
155172 $ info = $ prop ;
173+ break ;
156174 }
157175 }
158176
@@ -181,10 +199,10 @@ public function handle(BuildMetaModelOperationsEvent $event)
181199 *
182200 * @return bool
183201 */
184- private function wantToAdd ($ attribute , array $ properties ): bool
202+ private function wantToAdd (IAttribute $ attribute , array $ properties ): bool
185203 {
186204 return ($ attribute instanceof Checkbox)
187- && (($ attribute ->get ('check_publish ' ) === '1 ' ) || ($ attribute ->get ('check_listview ' ) === '1 ' ))
188- && (\in_array ($ attribute ->getColName (), $ properties , true ));
205+ && (($ attribute ->get ('check_publish ' ) === '1 ' ) || ($ attribute ->get ('check_listview ' ) === '1 ' ))
206+ && (\in_array ($ attribute ->getColName (), $ properties , true ));
189207 }
190208}
0 commit comments