madeyourday / contao-rocksolid-custom-elements

RockSolid Custom Elements Contao Extension
http://rocksolidthemes.com/de/contao/plugins/custom-content-elements
MIT License
48 stars 12 forks source link

Sortierung bei Listenelement #141

Closed zonky2 closed 1 year ago

zonky2 commented 3 years ago

Eine Option zur Sortierung der Listenelemente wäre prima - könnte z.B. so aussehen:

<?php
// rsce_boxes_config.php
return array(
    'label' => array('Textboxen mit Überschrift', 'Erzeugt eine...'),
    'types' => array('content'),
    'contentCategory' => 'texts',
    'standardFields' => array('headline', 'cssID'),
    'fields' => array(
        'boxes' => array(
            'label' => array('Textboxen', ''),
            'elementLabel' => '%s. Box',
            'inputType' => 'list',
            'minItems' => 1,
            'maxItems' => 5,
            'sorting'  => ['field' => 'text', 'direction' => 'asc', 'type' => 'natsort']
            'fields' => array(
                'text' => array(
                    'label' => array('Text', ''),
                    'eval' => array('rte' => 'tinyMCE'),
                    'inputType' => 'textarea',
                ),
            ),
        ),
    ),
);

mit type als sort, natsort und random sowie direction als asc (Standard) oder desc - braucht man nicht bei random

... bin aber noch nicht auf den Trichter gekommen, wo man das am Besten einbaut

m. E. wohl hier bei der Templateübergabe https://github.com/madeyourday/contao-rocksolid-custom-elements/blob/42c0b5c8e24895d763bda500e680566e7307f161/src/Element/CustomElement.php#L155-L159

ausi commented 3 years ago

Sorting an array can be done in the template relatively easy:

usort($this->arrData['boxes'], function($a, $b) {
    return strnatcasecmp($a->text, $b->text);
});

And because the custom element does not have access to the element config this would be hard to do in the element itself.

zonky2 commented 3 years ago

das ist schon klar ;-) war die Frage, ob man das aus dem Template raus hält/halten möchte - das bearbeiten nach meiner Erfahrung auch durchaus ambitionierte Redakeure, die mit den "PHP-Zeugs" ggf. nichts anzufangen wissen