Heinz Schilling
Heinz Schilling

Reputation: 2252

Use sort order from TCA select to list items in fluid

In my TCA I use a select to an other table.

    'modules' => [
        'label' => 'LLL:EXT:myextension_module_table/Resources/Private/Language/locallang_db.xlf:tx_myextension_domain_model_semester.modules',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectMultipleSideBySide',
            'enableMultiSelectFilterTextfield' => true,
            'foreign_table' => 'tx_myextension_domain_model_module',
            'minitems' => 1,
            'maxitems' => 99,
        ],
    ],

Under "Selected Items" I can sort the items. Now I want to use this sort order in fluid. In database I see the right order 21,1,2,3,4,28. But in fluid the items are always sorted by uid.

Adding 'sortby' => 'sorting', with all needed changes doesn't solve my problem. In this case I can order records in list view. But I don't want this order. I want to show order from "Selected Items" in frontend.

In my ModuletableController.php I get the selected moduletable from Flexform.

/**
 * action show
 *
 * @param \Vendor\Myextension\Domain\Model\Moduletable $moduletable
 * @return void
 */
public function showAction(\Vendor\Myextension\Domain\Model\Moduletable $moduletable = NULL) {
    if (is_null($moduletable)) {
        $moduletable = $this->moduletableRepository->findByUid($this->settings['singleModuleTable']);
    }

    $this->view->assign('moduletable', $moduletable);
}

An in the template Show.html I loop through it.

<html xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers">
<f:layout name="Default" />

<f:section name="main">
    <h2>{moduletable.title}</h2>
    <f:for each="{moduletable.semester}" as="semester">
        <p>{semester.title}</p>
        <f:for each="{semester.modules}" as="module">
            <p{module.title}</p>
        </f:for>
    </f:for>
</f:section>

Upvotes: 0

Views: 2511

Answers (2)

Heinz Schilling
Heinz Schilling

Reputation: 2252

Solution is to use MM tables. Then sort order is set in TCA select field.

In TCA:

'modules' => [
    'label' => 'LLL:EXT:myextension/Resources/Private/Language/locallang_db.xlf:tx_myextension_domain_model_semester.modules',
    'config' => [
        'type' => 'select',
        'renderType' => 'selectMultipleSideBySide',
        'enableMultiSelectFilterTextfield' => true,
        'foreign_table' => 'tx_myextension_domain_model_module',
        'foreign_sortby' => 'sorting',
        'MM' => 'tx_myextension_semester_module_mm',
        'minitems' => 1,
        'maxitems' => 99,
    ],
],

In ext_tables.sql

CREATE TABLE tx_myextension_semester_module_mm (
    uid_local int(11) unsigned DEFAULT '0' NOT NULL,
    uid_foreign int(11) unsigned DEFAULT '0' NOT NULL,
    sorting int(11) unsigned DEFAULT '0' NOT NULL,
    sorting_foreign int(11) unsigned DEFAULT '0' NOT NULL,

    KEY uid_local (uid_local),
    KEY uid_foreign (uid_foreign)
);

Upvotes: 2

Paul Beck
Paul Beck

Reputation: 2685

How do you get the selected items in your Extbase controller? Maybe you can use this findByUidListOrderByList function here: http://blog.teamgeist-medien.de/2014/09/typo3-extbase-repository-find-by-multiple-uids-findbyuids.html#comment-90

Upvotes: 0

Related Questions