Browse code

Add an optional subheadline field to content elements

Benjamin Roth authored on17/06/2025 13:43:21
Showing5 changed files
... ...
@@ -346,3 +346,9 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['vr_gpw_mobile_vAlign'] = [
346 346
     'eval'      => ['tl_class' => 'w33'],
347 347
     'sql'       => "varchar(20) NOT NULL default ''"
348 348
 ];
349
+
350
+$GLOBALS['TL_DCA']['tl_content']['fields']['vr_subline'] = [
351
+    'inputType' => 'text',
352
+    'eval'                    => array('maxlength'=>255, 'tl_class'=>'w50'),
353
+    'sql'                     => "varchar(255) NOT NULL default ''"
354
+];
... ...
@@ -223,6 +223,15 @@
223 223
                 <target>Die vertikale Ausrichtung innerhalb des ausgewählten Zellen-Rechtecks auf Mobil.</target>
224 224
             </trans-unit>
225 225
 
226
+            <trans-unit id="tl_content.vr_subline.0">
227
+                <source>Subline</source>
228
+                <target>Unterüberschrift</target>
229
+            </trans-unit>
230
+            <trans-unit id="tl_content.vr_subline.1">
231
+                <source>You can define a subheadline for the element which is only shown if the element also has a headline.</source>
232
+                <target>Sie können eine Unterüberschrift für das Element definieren, die nur angezeigt wird, wenn das Element auch eine Überschrift hat.</target>
233
+            </trans-unit>
234
+
226 235
             <trans-unit id="tl_content.grid_placement_legend">
227 236
                 <source>Grid placement</source>
228 237
                 <target>Raster-Platzierung</target>
... ...
@@ -116,6 +116,13 @@
116 116
                 <source>Set the vertical alignment in the selected cell rectangle for mobile.</source>
117 117
             </trans-unit>
118 118
 
119
+            <trans-unit id="tl_content.vr_subline.0">
120
+                <source>Subline</source>
121
+            </trans-unit>
122
+            <trans-unit id="tl_content.vr_subline.1">
123
+                <source>You can define a subheadline for the element which is only shown if the element also has a headline.</source>
124
+            </trans-unit>
125
+
119 126
             <trans-unit id="tl_content.grid_placement_legend">
120 127
                 <source>Grid placement</source>
121 128
             </trans-unit>
122 129
new file mode 100644
... ...
@@ -0,0 +1,12 @@
1
+{% use "@Contao/component/_headline.html.twig" %}
2
+
3
+{% block headline_component %}
4
+    <div class="block-headline">
5
+        {{ parent() }}
6
+        {% set level = min((headline.tag_name|default('h1')|split('h')[1] + 1),6) %}
7
+
8
+        {% if headline.text and data.vr_subline is defined and data.vr_subline is not empty %}
9
+            <div class="content-subline" aria-level="{{ level }}" role="heading">{{data.vr_subline|insert_tag_raw}}</div>
10
+        {% endif %}
11
+    </div>
12
+{% endblock %}
0 13
new file mode 100644
... ...
@@ -0,0 +1,33 @@
1
+<?php
2
+
3
+namespace vonRotenberg\CoretoolsBundle\EventListener\DataContainer;
4
+
5
+use Contao\CoreBundle\DataContainer\PaletteManipulator;
6
+use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
7
+use Contao\DataContainer;
8
+use Symfony\Component\HttpFoundation\RequestStack;
9
+#[AsCallback(table: 'tl_content', target: 'config.onload')]
10
+class ContentOnloadAddSublineCallback
11
+{
12
+    private RequestStack $requestStack;
13
+
14
+    public function __construct(RequestStack $requestStack)
15
+    {
16
+        $this->requestStack = $requestStack;
17
+    }
18
+    public function __invoke(DataContainer|null $dc = null): void
19
+    {
20
+        if (null === $dc || !$dc->id || !in_array($this->requestStack->getCurrentRequest()->query->get('act'),['edit','editAll'])) {
21
+            return;
22
+        }
23
+
24
+        foreach ($GLOBALS['TL_DCA'][$dc->table]['palettes'] as $palette => $fields) {
25
+            if ('__selector__' === $palette) {
26
+                continue;
27
+            }
28
+            PaletteManipulator::create()
29
+                ->addField('vr_subline', 'headline', PaletteManipulator::POSITION_AFTER)
30
+                ->applyToPalette($palette, $dc->table);
31
+        }
32
+    }
33
+}