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

Respect order field in fileTree widget #131

Closed bezin closed 3 years ago

bezin commented 3 years ago

Hi there and once again thank you for this extension :-)

I would like to suggest a little improvement: I have a file tree widget in one of my custom elements that has an orderField. However, RSCE does not consider this when handing the field value to the template (as Contao does itself in the core).

It would be nice though, if RSCE would consider orderField and hand the images to the template in the correct order.

// rsce_page_footer_config.php
// ...
'partnerLogos' => [
    'label' => ['Partner Logos', ''],
    'inputType' => 'fileTree',
    'eval' => [
        'extensions' => join(',', $imageExtensions),
        'fieldType' => 'checkbox',
        'filesOnly' => true,
        'multiple' => true,
        'isGallery' => true,
        'orderField' => 'orderSRC'
    ],
],
// ...

Now one needs to deserialize orderSRC and handle the binary uuids manually manually in the template:

// rsce_page_footer.html5
<?php if ($this->partnerLogos && $this->orderSRC) {
    $order = \Contao\StringUtil::deserialize($this->orderSRC);

    $this->partnerLogos = array_map(function($uuid) {
        return \Contao\StringUtil::binToUuid($uuid);
    }, $order);
} ?>

I would prefer if $this->partnerLogos is sorted by orderField right away:

<?php foreach ($this->partnerLogos as $logo): ?>
<?php // $logo is now the first logo
<?php endforeach; ?>

I know this is the same behaviour as in the core, but RSCE simplifies so many things that I would appreciate this, too :-)

Happy to her your thoughts.

Cheers

ausi commented 3 years ago

This was actually simplified in the core itself: https://github.com/contao/contao/pull/1468

With removing 'orderField' => 'orderSRC' and adding 'isSortable' => true you should get the result you need.

bezin commented 3 years ago

Uh, nice, did not know that. Even better :-) Thanks for the hint 👍

ausi commented 3 years ago

The best part is, this makes sortable fileTrees now also available inside list elements. This was not possible with orderField.

bezin commented 3 years ago

Ah, now I know why I did not now about it: It is only available from 4.10 ;-)