TYPO3 Extbase: how to sort child objects

I have an Extbase model article and a 1: n relationship product. In the TCA article, I have a built-in field. In my article template, I want to display all related products. They are supported by uid. How can I change the order of children in sorting fields to sort them manually. (In backend forms, sorting is possible, only sorting by sorting by sorting fields is not possible)

thanks Lukas

+4
source share
4 answers

Here's how I do it in the repository class:

class ItemRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {

    /**
     * http://www.typo3.net/forum/thematik/zeige/thema/114160/?show=1
     * Returns items of this repository, sorted by sorting
     *
     * @return array An array of objects, empty if no objects found
     * @api
     */

    public function findAll() {
        $orderings = array(
            'sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
        );

        $query = $this->createQuery();
        $query->setOrderings($orderings);

        $query->getQuerySettings()->setRespectSysLanguage(FALSE);
        $query->getQuerySettings()->setSysLanguageUid(0);

        $result = $query->execute();
        return $result;
    }

}
+3
source

The easiest way to sort children in an object store 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
            ),
        ),
    ),
),
...
);

'foreign_sortby' = > 'sorting', , childs.

+4

, :

$query->setOrderings(array(
    'sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
    'subobject.sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
));

: , , . , , , , . , , @Urs.

+1

(mvc).

ist, mvc, ( ) .

. ( ). .

public function findAllSorted() {
    $query = $this->createQuery();
    /* sort parents */
    $query->setOrderings(array('name' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING));
    $parents = $query->execute();
    foreach($parents as $parent){
        /* get children for every parent */
        $children = $this->getChildrenSorted($parent);
        // add children to parent TBD

    }
    /* Debug output */
    \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($parents);
}

public function getChildrenSorted(\mynamespace\ $parent) {
    /* Generate an object manager and use dependency injection to retrieve children repository */
    $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\TYPO3\CMS\Extbase\Object\ObjectManager');
    $childrenRepository= $objectManager->get('MYNAME\Extname\Domain\Repository\Repository');
    $children = $versionRepository->findSortedByName($parent);
    return $children;
}

findSortedByName

$query->matching($query->equals('parent', $parent));

$query->setOrderings(array('name' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING));

.

. .

-1