Browse code

Add text align options to content elements

Benjamin Roth authored on01/04/2019 19:02:18
Showing3 changed files
... ...
@@ -16,21 +16,25 @@ use Contao\Template;
16 16
 
17 17
 class TemplateListener implements FrameworkAwareInterface
18 18
 {
19
-    use FrameworkAwareTrait;
19
+  use FrameworkAwareTrait;
20 20
 
21
-    public function onParseTemplate(Template $template)
21
+  public function onParseTemplate(Template $template)
22
+  {
23
+    if ($template->es_spacing)
22 24
     {
23
-        if ($template->es_spacing)
24
-        {
25
-            $template->class = trim($template->class.' spc_'.$template->es_spacing);
26
-        }
27
-        if ($template->es_padding)
28
-        {
29
-            $template->class = trim($template->class.' pad_default');
30
-        }
31
-        if ($template->es_col_text)
32
-        {
33
-            $template->class = trim($template->class.' layout_'.$template->es_col_text);
34
-        }
25
+      $template->class = trim($template->class . ' spc_' . $template->es_spacing);
35 26
     }
27
+    if ($template->es_padding)
28
+    {
29
+      $template->class = trim($template->class . ' pad_default');
30
+    }
31
+    if ($template->es_textAlign)
32
+    {
33
+      $template->class = trim($template->class . ' align_'.$template->es_textAlign);
34
+    }
35
+    if ($template->es_col_text)
36
+    {
37
+      $template->class = trim($template->class . ' layout_' . $template->es_col_text);
38
+    }
39
+  }
36 40
 }
... ...
@@ -15,7 +15,7 @@ foreach ($GLOBALS['TL_DCA']['tl_content']['palettes'] as $key => $palette)
15 15
 {
16 16
     if ($key != '__selector__')
17 17
     {
18
-        \Contao\CoreBundle\DataContainer\PaletteManipulator::create()->addField('es_spacing', 'cssID')->addField('es_padding', 'es_spacing')->applyToPalette($key, 'tl_content');
18
+        \Contao\CoreBundle\DataContainer\PaletteManipulator::create()->addField('es_textAlign', 'cssID')->addField('es_spacing', 'es_textAlign')->addField('es_padding', 'es_spacing')->applyToPalette($key, 'tl_content');
19 19
         \Contao\CoreBundle\DataContainer\PaletteManipulator::create()->addField('es_col_text','text',\Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_BEFORE)->applyToPalette($key,'tl_content');
20 20
     }
21 21
 }
... ...
@@ -58,6 +58,17 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['es_padding'] = array
58 58
     'sql'                     => "char(1) NOT NULL default ''"
59 59
 );
60 60
 
61
+$GLOBALS['TL_DCA']['tl_content']['fields']['es_textAlign'] = array
62
+(
63
+  'label'                   => &$GLOBALS['TL_LANG']['tl_content']['es_textAlign'],
64
+  'exclude'                 => true,
65
+  'inputType'               => 'select',
66
+  'options'                 => array('left','center','right'),
67
+  'reference'               => &$GLOBALS['TL_LANG']['tl_content']['REF']['es_textAlign'],
68
+  'eval'                    => array('tl_class'=>'w50','mandatory'=>false,'includeBlankOption'=>true),
69
+  'sql'                     => "varchar(32) NOT NULL default ''"
70
+);
71
+
61 72
 $GLOBALS['TL_DCA']['tl_content']['fields']['es_rs_columns_valign'] = array
62 73
 (
63 74
     'label'                   => &$GLOBALS['TL_LANG']['tl_content']['es_rs_columns_valign'],
... ...
@@ -41,3 +41,6 @@ $GLOBALS['TL_LANG']['tl_content']['REF']['es_rs_columns_valign']['top'] = 'Oben'
41 41
 $GLOBALS['TL_LANG']['tl_content']['REF']['es_rs_columns_valign']['center'] = 'Mitte';
42 42
 $GLOBALS['TL_LANG']['tl_content']['REF']['es_rs_columns_valign']['bottom'] = 'Unten';
43 43
 $GLOBALS['TL_LANG']['tl_content']['REF']['es_rs_columns_valign']['stretch'] = 'Gleiche Höhe';
44
+$GLOBALS['TL_LANG']['tl_content']['REF']['es_textAlign']['left'] = 'Linksbündig';
45
+$GLOBALS['TL_LANG']['tl_content']['REF']['es_textAlign']['center'] = 'Zentriert';
46
+$GLOBALS['TL_LANG']['tl_content']['REF']['es_textAlign']['right'] = 'Rechtsbündig';
44 47
\ No newline at end of file