[TYPO3-german] Re: Extbase: Sortierung von Kindobjekten
David Brünner
david.bruenner at t-online.de
Sun Mar 11 17:19:47 CET 2018
/**
* Removes all children of given property and attaches them again in right order
* @param $obj
* @param $forProperty
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
*/
public function setSorting($obj, $forProperty) {
if ($this->request->hasArgument('swappedItems')) {
$swappedItems = (array)json_decode($this->request->getArgument('swappedItems'));
if ($swappedItems) {
// remove all childs
$obj->removeAllAttachedObjects($forProperty);
// attach in correct order
foreach ($swappedItems as $uid => $childs) {
$model = new ReflectionClass($obj);
if (property_exists($obj, $forProperty)) {
$propertDocComment = $model->getProperty($forProperty)->getDocComment();
preg_match('/.*\\\(.+)>/', $propertDocComment, $matches);
$repositoryName = $matches[1];
$repository = $this->objectManager->get('KKSoftware\Kkbaybw\Domain\Repository\\' . $repositoryName . 'Repository');
foreach ($childs as $child) {
$childObj = $repository->findByUid((int)$child);
$method = 'add' . ucfirst($forProperty);
$obj->{$method}($childObj);
}
}
}
}
}
}
More information about the TYPO3-german
mailing list