Skip to content

Commit bd65e85

Browse files
committed
Adding support for layouts, forms, form fields and modules
1 parent e0390f0 commit bd65e85

23 files changed

+644
-79
lines changed

README.md

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
# Contao Component Style Manager
22

3-
Allows you to add your own groups of CSS classes provided in pages, articles, and content elements to your customers.
3+
Allows you to add your own groups of CSS classes provided in layouts, pages, articles, modules, forms, form elements and content elements to your customers.
44

55
This plugin is designed to simplify theme customizations without the need for customers to manually add classes or create new layouts.
66

7-
### Latest Updates
8-
#### 1.1.2
9-
- Categories
10-
- Better visualization in the backend
11-
- Rocksolid CustomElement Support
7+
### Overview
8+
- Many possibilities of use (grid, designs, animations, content properties, ...)
9+
- Clear representation in the backend
10+
- Groups and Categories
11+
- Available for
12+
- Layouts
13+
- Pages
14+
- Articles
15+
- Modules
16+
- Content-Elements
17+
- Forms
18+
- Form-Fields
19+
20+
> Feel free to use it as you need it.
1221
1322
### Examples
1423
#### Admin:
15-
##### List-View
16-
![Admin View: List](https://www.oveleon.de/share/github-assets/contao-component-style-manager/list-view.png)
24+
##### List-View: Groups
25+
![Admin View: List](https://www.oveleon.de/share/github-assets/contao-component-style-manager/list-view-120.png)
26+
##### List-View: Categories
27+
![Admin View: List](https://www.oveleon.de/share/github-assets/contao-component-style-manager/list-view-2-120.png)
1728
##### Mask-View: Content Elements
18-
![Admin View: Mask](https://www.oveleon.de/share/github-assets/contao-component-style-manager/content-elements.png)
19-
##### Mask-View: Article
20-
![Admin View: Mask](https://www.oveleon.de/share/github-assets/contao-component-style-manager/articles.png)
29+
![Admin View: Mask](https://www.oveleon.de/share/github-assets/contao-component-style-manager/content-elements-120.png)
2130

2231
#### Customer:
2332
##### Article
24-
![Customer View: Article](https://www.oveleon.de/share/github-assets/contao-component-style-manager/customer.png)
33+
![Customer View: Article](https://www.oveleon.de/share/github-assets/contao-component-style-manager/customer-120.png)
2534

26-
#### Support Rocksolid Custom Elements
35+
### Support Rocksolid Custom Elements
2736
see: https://github.com/madeyourday/contao-rocksolid-custom-elements
2837

2938
Use the callback function `onloadCallback` in your custom element configuration and reference the following function:
@@ -32,3 +41,20 @@ Use the callback function `onloadCallback` in your custom element configuration
3241
array('Oveleon\ContaoComponentStyleManager\Support', 'extendRockSolidCustomElementsPalettes')
3342
)
3443
```
44+
45+
### Latest Updates
46+
#### 1.2.0
47+
- Categories
48+
- Better visualization in the backend
49+
- Rocksolid CustomElement Support
50+
- Further availability for
51+
- Layouts
52+
- Forms
53+
- Form-Fields
54+
- Modules
55+
56+
##### Fixes
57+
- Multiple editing in the backend
58+
- Additional security - classes remain after deleting groups or their values
59+
- Alias has been removed from the palette and is created dynamically
60+
- Sort by category-title

src/Resources/contao/classes/StyleManager.php

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ class StyleManager
1111
{
1212
/**
1313
* Valid CSS-Class fields in tables
14+
*
15+
* field => size
16+
*
1417
* @var array
1518
*/
16-
public $validCssClassFields = array('cssID', 'cssClass');
19+
public $validCssClassFields = array(
20+
'cssID' => 2,
21+
'cssClass' => 1,
22+
'class' => 1,
23+
'attributes' => 2
24+
);
1725

1826
/**
1927
* Clear StyleManager classes from css class field
@@ -25,7 +33,7 @@ class StyleManager
2533
*/
2634
public function clearStyleManager($varValue, $dc)
2735
{
28-
if($dc->field === 'cssID')
36+
if($this->isMultipleField($dc->field))
2937
{
3038
$cssID = \StringUtil::deserialize($varValue, true);
3139
$varValue = $cssID[1];
@@ -42,7 +50,7 @@ public function clearStyleManager($varValue, $dc)
4250
$varValue = trim(preg_replace('#\s+#', ' ', $varValue));
4351
}
4452

45-
if($dc->field === 'cssID')
53+
if($this->isMultipleField($dc->field))
4654
{
4755
$varValue = serialize(array($cssID[0], $varValue));
4856
}
@@ -60,7 +68,7 @@ public function clearStyleManager($varValue, $dc)
6068
*/
6169
public function updateStyleManager($varValue, $dc)
6270
{
63-
if($dc->field === 'cssID')
71+
if($this->isMultipleField($dc->field))
6472
{
6573
$cssID = \StringUtil::deserialize($varValue, true);
6674
$varValue = $cssID[1];
@@ -70,7 +78,7 @@ public function updateStyleManager($varValue, $dc)
7078
$varValues = array_filter($varValues);
7179
$varValue .= ($varValue ? ' ' : '') . (count($varValues) ? implode(' ', $varValues) : '');
7280

73-
if($dc->field === 'cssID')
81+
if($this->isMultipleField($dc->field))
7482
{
7583
$varValue = array($cssID[0], $varValue);
7684
}
@@ -89,7 +97,7 @@ public function updateStyleManager($varValue, $dc)
8997
*/
9098
private function resetStyleManagerClasses($varValue, $dc, $strTable)
9199
{
92-
if($dc->field === 'cssID')
100+
if($this->isMultipleField($dc->field))
93101
{
94102
$cssID = \StringUtil::deserialize($varValue, true);
95103
$varValue = $cssID[1];
@@ -120,7 +128,7 @@ private function resetStyleManagerClasses($varValue, $dc, $strTable)
120128
$varValue = trim(preg_replace('#\s+#', ' ', $varValue));
121129
}
122130

123-
if($dc->field === 'cssID')
131+
if($this->isMultipleField($dc->field))
124132
{
125133
$varValue = serialize(array($cssID[0], $varValue));
126134
}
@@ -149,7 +157,7 @@ public function updateOnMultiEdit($varValue, $dc)
149157
// Get new value
150158
$value = $this->resetStyleManagerClasses($dc->activeRecord->{$field}, $stdClass, $dc->table);
151159
$value = $this->updateStyleManager($value, $stdClass);
152-
$value = $field === 'cssID' ? serialize($value) : $value;
160+
$value = $this->isMultipleField($field) ? serialize($value) : $value;
153161

154162
// Update css class field
155163
$dc->Database->prepare('UPDATE ' . $dc->table . ' SET ' . $field . '=? WHERE id=?')
@@ -171,7 +179,7 @@ public function getClassFieldNameByTable($strTable)
171179
{
172180
\Backend::loadDataContainer($strTable);
173181

174-
foreach ($this->validCssClassFields as $field)
182+
foreach ($this->validCssClassFields as $field => $size)
175183
{
176184
if(isset($GLOBALS['TL_DCA'][ $strTable ]['fields'][ $field ]))
177185
{
@@ -182,6 +190,18 @@ public function getClassFieldNameByTable($strTable)
182190
return false;
183191
}
184192

193+
/**
194+
* Checks the passed array and removes non-existent values
195+
*
196+
* @param $strField
197+
*
198+
* @return bool
199+
*/
200+
public function isMultipleField($strField)
201+
{
202+
return $this->validCssClassFields[ $strField ] > 1;
203+
}
204+
185205
/**
186206
* Checks the passed array and removes non-existent values
187207
*
@@ -225,6 +245,10 @@ public function cleanupClasses(&$arrValues, $strTable)
225245
}
226246
}
227247
}
248+
else
249+
{
250+
$arrValues = array();
251+
}
228252
}
229253
}
230254
}

src/Resources/contao/dca/tl_form.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/*
3+
* This file is part of ContaoComponentStyleManager.
4+
*
5+
* (c) https://www.oveleon.de/
6+
*/
7+
8+
// Extend the regular palette
9+
$palette = Contao\CoreBundle\DataContainer\PaletteManipulator::create()
10+
->addLegend('style_manager_legend', 'expert_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_BEFORE)
11+
->addField(array('styleManager'), 'style_manager_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_APPEND)
12+
->applyToPalette('default', 'tl_form');
13+
14+
// Extend fields
15+
$GLOBALS['TL_DCA']['tl_form']['fields']['styleManager'] = array
16+
(
17+
'label' => &$GLOBALS['TL_LANG']['tl_form']['styleManager'],
18+
'exclude' => true,
19+
'inputType' => 'stylemanager',
20+
'eval' => array('tl_class'=>'clr stylemanager'),
21+
'sql' => "blob NULL",
22+
'save_callback' => array(
23+
array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'updateOnMultiEdit')
24+
)
25+
);
26+
27+
$GLOBALS['TL_DCA']['tl_form']['fields']['attributes']['load_callback'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'clearStyleManager');
28+
$GLOBALS['TL_DCA']['tl_form']['fields']['attributes']['save_callback'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'updateStyleManager');
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/*
3+
* This file is part of ContaoComponentStyleManager.
4+
*
5+
* (c) https://www.oveleon.de/
6+
*/
7+
8+
// Extend the regular palette
9+
$palette = Contao\CoreBundle\DataContainer\PaletteManipulator::create()
10+
->addLegend('style_manager_legend', 'expert_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_BEFORE)
11+
->addField(array('styleManager'), 'style_manager_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_APPEND);
12+
13+
foreach ($GLOBALS['TL_DCA']['tl_form_field']['palettes'] as $key=>$value){
14+
if($key === '__selector__')
15+
{
16+
continue;
17+
}
18+
19+
$palette->applyToPalette($key, 'tl_form_field');
20+
}
21+
22+
// Extend fields
23+
$GLOBALS['TL_DCA']['tl_form_field']['fields']['styleManager'] = array
24+
(
25+
'label' => &$GLOBALS['TL_LANG']['tl_form_field']['styleManager'],
26+
'exclude' => true,
27+
'inputType' => 'stylemanager',
28+
'eval' => array('tl_class'=>'clr stylemanager'),
29+
'sql' => "blob NULL",
30+
'save_callback' => array(
31+
array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'updateOnMultiEdit')
32+
)
33+
);
34+
35+
$GLOBALS['TL_DCA']['tl_form_field']['fields']['class']['load_callback'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'clearStyleManager');
36+
$GLOBALS['TL_DCA']['tl_form_field']['fields']['class']['save_callback'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'updateStyleManager');
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/*
3+
* This file is part of ContaoComponentStyleManager.
4+
*
5+
* (c) https://www.oveleon.de/
6+
*/
7+
8+
// Extend the regular palette
9+
Contao\CoreBundle\DataContainer\PaletteManipulator::create()
10+
->addLegend('style_manager_legend', 'expert_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_BEFORE)
11+
->addField(array('styleManager'), 'style_manager_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_APPEND)
12+
->applyToPalette('default', 'tl_layout');
13+
14+
// Extend fields
15+
$GLOBALS['TL_DCA']['tl_layout']['fields']['styleManager'] = array
16+
(
17+
'label' => &$GLOBALS['TL_LANG']['tl_layout']['styleManager'],
18+
'exclude' => true,
19+
'inputType' => 'stylemanager',
20+
'eval' => array('tl_class'=>'clr stylemanager'),
21+
'sql' => "blob NULL",
22+
'save_callback' => array(
23+
array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'updateOnMultiEdit')
24+
)
25+
);
26+
27+
$GLOBALS['TL_DCA']['tl_layout']['fields']['cssClass']['load_callback'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'clearStyleManager');
28+
$GLOBALS['TL_DCA']['tl_layout']['fields']['cssClass']['save_callback'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'updateStyleManager');
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/*
3+
* This file is part of ContaoComponentStyleManager.
4+
*
5+
* (c) https://www.oveleon.de/
6+
*/
7+
8+
// Extend the regular palette
9+
$palette = Contao\CoreBundle\DataContainer\PaletteManipulator::create()
10+
->addLegend('style_manager_legend', 'expert_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_BEFORE)
11+
->addField(array('styleManager'), 'style_manager_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_APPEND);
12+
13+
foreach ($GLOBALS['TL_DCA']['tl_module']['palettes'] as $key=>$value){
14+
if($key === '__selector__')
15+
{
16+
continue;
17+
}
18+
19+
$palette->applyToPalette($key, 'tl_module');
20+
}
21+
22+
// Extend fields
23+
$GLOBALS['TL_DCA']['tl_module']['fields']['styleManager'] = array
24+
(
25+
'label' => &$GLOBALS['TL_LANG']['tl_module']['styleManager'],
26+
'exclude' => true,
27+
'inputType' => 'stylemanager',
28+
'eval' => array('tl_class'=>'clr stylemanager'),
29+
'sql' => "blob NULL",
30+
'save_callback' => array(
31+
array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'updateOnMultiEdit')
32+
)
33+
);
34+
35+
$GLOBALS['TL_DCA']['tl_module']['fields']['cssID']['load_callback'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'clearStyleManager');
36+
$GLOBALS['TL_DCA']['tl_module']['fields']['cssID']['save_callback'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'updateStyleManager');

0 commit comments

Comments
 (0)