Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TYPO3 Extbase: How to sort child objects

Tags:

typo3

extbase

I have an Extbase Model Article and a 1:n Relation Product. In Article TCA i have an inline field configuered. In my Article Template I want to display all related Products. These are oredered by uid. How can i change the ordering of the child objects to the field sorting to be able to manually sort them. ( In the backend form the sorting is possible, only diplaying them sorted by field sorting is not possible )

thanks, Lukas

like image 847
LuJaks Avatar asked Sep 12 '14 11:09

LuJaks


1 Answers

The easiest way to sort child elements in a object storage is to manipulate the TCA.

Example:

$TCA['tx_myext_domain_model_ordering'] = array(
...
'columns' => array(
    'services' => array(
        'exclude' => 0,
        'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xml:tx_myext_domain_model_ordering.services',
        'config' => array(
            'type' => 'inline',
            'foreign_table' => 'tx_myext_domain_model_service',
            'foreign_field' => 'ordering',
            'foreign_sortby' => 'sorting',
            'maxitems'      => 9999,
            'appearance' => array(
                'collapseAll' => 0,
                'levelLinksPosition' => 'top',
                'showSynchronizationLink' => 1,
                'showPossibleLocalizationRecords' => 1,
                'showAllLocalizationLink' => 1
            ),
        ),
    ),
),
...
);

With the filed 'foreign_sortby' => 'sorting', you can easily say on which field the childs should be ordered.

like image 137
Sebastian Rieger Avatar answered Oct 15 '22 12:10

Sebastian Rieger