List all child element types.

@param Request $request

@return JsonResponse
@Route("/childelements", name="teasers_layout_childelements")
356605
public function childElementsAction(Request $request)
    {
        $tid = $request->get('tree_id');
        $layoutareaId = $request->get('layoutarea_id');
        $language = $request->get('language', 'de');

        $translator = $this->get('translator');
        $treeManager = $this->get('phlexible_tree.tree_manager');
        $teaserManager = $this->get('phlexible_teaser.teaser_manager');
        $elementService = $this->get('phlexible_element.element_service');
        $elementtypeService = $this->get('phlexible_elementtype.elementtype_service');
        $iconResolver = $this->get('phlexible_element.icon_resolver');

        $data = [];
        $data[] = [
            'id' => '0',
            'title' => $translator->trans('elements.first', [], 'gui'),
            'icon' => $iconResolver->resolveIcon('_top.gif'),
        ];

        $tree = $treeManager->getByNodeId($tid);
        $treeNode = $tree->get($tid);
        $treeNodePath = $tree->getPath($treeNode);

        $layoutarea = $elementtypeService->findElementtype($layoutareaId);
        $teasers = $teaserManager->findForLayoutAreaAndTreeNodePath($layoutarea, $treeNodePath);

        foreach ($teasers as $teaser) {
            $teaserElement = $elementService->findElement($teaser->getTypeId());
            $teaserElementVersion = $elementService->findLatestElementVersion($teaserElement);
            $data[] = [
                'id' => $teaser->getId(),
                'title' => $teaserElementVersion->getBackendTitle($language),
                'icon' => $iconResolver->resolveTeaser($teaser, $language),
            ];
        }

        return new JsonResponse(['elements' => $data]);
    }
1204598
protected function afterSaveElements(\Illuminate\Http\Request $request)
    {
        $this->getElements()->onlyActive()->each(function ($element) use ($request) {
            $element = $this->getElementContainer($element);

            if ($element instanceof FormElementInterface) {
                $element->afterSave($request);
            }
        });
    }
416921
public function listActionCustom(Request $request = null)
    {
        $this->admin->checkAccess('list');

        $preResponse = $this->preList($request);
        if (null !== $preResponse) {
            return $preResponse;
        }

        if ($listMode = $request->get('_list_mode')) {
            $this->admin->setListMode($listMode);
        }

        $datagrid = $this->admin->getDatagrid();
        $formView = $datagrid->getForm()->createView();

        return $this->renderWithExtraParams($this->admin->getTemplate('list'), [
            'action' => 'list',
            'form' => $formView,
            'batch_action_forms' => $this->getBatchActionFormViews(),

            'datagrid' => $datagrid,
            'csrf_token' => $this->getCsrfToken('sonata.batch'),
            'export_formats' => $this->admin->getExportFormats(),
        ], null);
    }
386249
public function getAjaxList(Request $request) // GET THE SLUG, ex. 'posts', 'pages', etc.
    {
        // GET THE SLUG, ex. 'posts', 'pages', etc.
        $slug = $request->slug;

        // GET THE DataType based on the slug
        $dataType = Admin::model('DataType')->where('slug', '=', $slug)->first();

        // Check permission
        $this->authorize('browse', app($dataType->model_name));

        $model = app($dataType->model_name);
        $query = $model->select('*');

        if (method_exists($model, 'adminList')) {
            $query = $model->adminList()->select('*');
        }

        if (!isset($request->order)) {
            if ($model->timestamps) {
                $query = $query->latest($model::CREATED_AT);
            } else {
                $relationships = $this->getRelationships($dataType);
                $query = $query->with($relationships)->orderBy($model->getKeyName(), 'DESC');
            }
        }

        $query = DataTables::of($query);

        foreach ($dataType->ajaxList() as $dataRow) {
            $query->editColumn($dataRow->field, function($dataTypeContent) use($request, $slug, $dataRow){
                $content = $dataTypeContent->{$dataRow->field};

                $handler = AbstractHandler::initial($dataRow->type);

                if (method_exists($handler, 'getContentForList')) {
                    $content = $handler->getContentForList($request, $slug, $dataRow, $dataTypeContent);
                }

                return $content;
            });

            if ($dataRow->type == 'relationship') {
                $query->filterColumn($dataRow->field, function ($query, $keyword) use($dataRow){
                    $relationship = json_decode($dataRow->details);
                    $ids = app($relationship->model)->where($relationship->label, 'like', "%$keyword%")->pluck($relationship->key);
                    $query->whereIn($relationship->column, $ids);
                });
            }
        }

        return $query
            ->addColumn('delete_checkbox', function($dataTypeContent) {
                return '<input type="checkbox" name="row_id" id="checkbox_' . $dataTypeContent->id . '" value="' . $dataTypeContent->id . '">';

            })
            ->addColumn('actions', function($dataTypeContent) use($dataType){
                return Admin::view('admin::list.datatable.buttons', ['data' => $dataTypeContent, 'dataType' => $dataType]);
            })
            ->rawColumns(array_merge($dataType->ajaxListFields(), ['delete_checkbox', 'actions']))
            ->make(true);
    }
341021
public function loadAction(Request $request)
    {
        $treeId = (int) $request->get('id');
        $teaserId = (int) $request->get('teaser_id');
        $language = $request->get('language');
        $version = $request->get('version');
        $unlockId = $request->get('unlock');
        $doLock = (bool) $request->get('lock', false);

        $diff = $request->get('diff');
        $diffVersionFrom = (int) $request->get('diff_version_from');
        $diffVersionTo = (int) $request->get('diff_version_to');
        $diffLanguage = $request->get('diff_language');

        $teaserManager = $this->get('phlexible_teaser.teaser_manager');
        $treeManager = $this->get('phlexible_tree.tree_manager');
        $elementService = $this->get('phlexible_element.element_service');
        $iconResolver = $this->get('phlexible_element.icon_resolver');
        $elementHistoryManager = $this->get('phlexible_element.element_history_manager');
        $lockManager = $this->get('phlexible_element.element_lock_manager');
        $userManager = $this->get('phlexible_user.user_manager');
        $authorizationChecker = $this->get('security.authorization_checker');
        $linkFetcher = $this->get('phlexible_element.link_fetcher');

        $teaser = null;
        if ($teaserId) {
            $teaser = $teaserManager->find($teaserId);
            $eid = $teaser->getTypeId();
            $treeId = $teaser->getTreeId();
            $tree = $treeManager->getByNodeId($treeId);
            $node = $tree->get($treeId);
        } elseif ($treeId) {
            $tree = $treeManager->getByNodeId($treeId);
            $node = $tree->get($treeId);
            $eid = $node->getTypeId();
        } else {
            throw new InvalidArgumentException('Unknown data requested.');
        }

        $element = $elementService->findElement($eid);
        $elementMasterLanguage = $element->getMasterLanguage();

        if (!$language) {
            $language = $elementMasterLanguage;
        }

        if ($teaser) {
            $isPublished = $teaserManager->isPublished($teaser, $language);
            $onlineVersion = $teaserManager->getPublishedVersion($teaser, $language);
        } elseif ($treeId) {
            $isPublished = $tree->isPublished($node, $language);
            $onlineVersion = $tree->getPublishedVersion($node, $language);
        } else {
            throw new InvalidArgumentException('Unknown data requested.');
        }

        if ($version) {
            $elementVersion = $elementService->findElementVersion($element, $version);
        } else {
            $elementVersion = $elementService->findLatestElementVersion($element);
        }

        $elementStructure = $elementService->findElementStructure($elementVersion, $language);

        $elementtype = $elementService->findElementtype($element);
        $elementtypeStructure = $elementtype->getStructure();
        $type = $elementtype->getType();

        // versions

        if ($teaser) {
            $publishedVersions = $elementHistoryManager->findBy(
                [
                    'teaserId' => $teaser->getId(),
                    'action' => 'publishTeaser',
                ]
            );
        } else {
            $publishedVersions = $elementHistoryManager->findBy(
                [
                    'treeId' => $node->getId(),
                    'action' => 'publishNode',
                ]
            );
        }

        $versions = [];
        foreach ($elementService->findElementVersions($element, array('version' => 'DESC')) as $version) {
            $versions[$version->getVersion()] = [
                'version' => $version->getVersion(),
                'format' => 2,
                'create_date' => $version->getCreatedAt()->format('Y-m-d H:i:s'),
                'is_published' => false,
                'was_published' => false,
            ];
        }

        foreach ($publishedVersions as $publishedVersion) {
            if (!isset($versions[$publishedVersion->getVersion()])) {
                continue;
            }
            $versions[$publishedVersion->getVersion()]['online'] = true;
            if ($publishedVersion->getVersion() === $onlineVersion) {
                $versions[$publishedVersion->getVersion()]['is_published'] = true;
            } else {
                $versions[$publishedVersion->getVersion()]['was_published'] = true;
            }
        }

        $versions = array_values($versions);

        // instances

        $instances = [];
        if ($teaser) {
            foreach ($teaserManager->getInstances($teaser) as $instanceTeaser) {
                $instance = [
                    'id' => $instanceTeaser->getId(),
                    'instance_master' => false,
                    'modify_time' => $instanceTeaser->getCreatedAt()->format('Y-m-d H:i:s'),
                    'icon' => $iconResolver->resolveTeaser($instanceTeaser, $language),
                    'type' => 'teaser',
                    'link' => [],
                ];

                $instances[] = $instance;
            }
        } else {
            foreach ($treeManager->getInstanceNodes($node) as $instanceNode) {
                $instance = [
                    'id' => $instanceNode->getId(),
                    'instance_master' => false,
                    'modify_time' => $instanceNode->getCreatedAt()->format('Y-m-d H:i:s'),
                    'icon' => $iconResolver->resolveTreeNode($instanceNode, $language),
                    'type' => 'treenode',
                    'link' => [],
                ];

                if ($instanceNode->getTree()->getSiterootId() !== $tree->getSiterootId()) {
                    $instance['link'] = [
                        'start_tid_path' => '/'.implode('/', $instanceNode->getTree()->getIdPath($instanceNode)),
                    ];
                }

                $instances[] = $instance;
            }
        }

        // allowed child elements

        $allowedChildren = [];
        if (!$teaser) {
            foreach ($elementService->findAllowedChildren($elementtype) as $childElementtype) {
                if ($childElementtype->getType() !== 'full') {
                    continue;
                }

                $allowedChildren[] = [
                    $childElementtype->getId(),
                    $childElementtype->getTitle(),
                    $iconResolver->resolveElementtype($childElementtype),
                ];
            }
        }

        // diff

        if ($diff && $diffVersionFrom) {
            $fromElementVersion = $elementService->findElementVersion($element, $diffVersionFrom);
            $fromElementStructure = $elementService->findElementStructure($fromElementVersion, $diffLanguage);

            if ($diffVersionTo) {
                $toElementVersion = $elementService->findElementVersion($element, $diffVersionTo);
                $toElementStructure = $elementService->findElementStructure($toElementVersion, $diffLanguage);
            } else {
                $toElementStructure = $elementStructure;
            }

            if ($fromElementStructure !== $toElementStructure) {
                $differ = new Differ();
                $differ->diff($fromElementStructure, $toElementStructure);
            }

            $elementStructure = $fromElementStructure;
        }

        $diffInfo = null;
        if ($diff) {
            $diffInfo = [
                'enabled' => $diff,
                'version_from' => $diffVersionFrom,
                'version_to' => $diffVersionTo,
                'language' => $diffLanguage,
            ];
        }

        // lock

        if ($unlockId !== null) {
            $unlockElement = $elementService->findElement($unlockId);
            if ($unlockElement && $lockManager->isLockedByUser($unlockElement, $this->getUser()->getId())) {
                try {
                    $lockManager->unlock($unlockElement, $this->getUser()->getId());
                } catch (\Exception $e) {
                    // unlock failed
                }
            }
        }

        if ($node instanceof DomainObjectInterface) {
            if (!$authorizationChecker->isGranted('ROLE_SUPER_ADMIN') &&
                !$authorizationChecker->isGranted(['permission' => 'EDIT', 'language' => $language], $node)
            ) {
                $doLock = false;
            }
        }

        $lock = null;
        if ($doLock && !$diff) {
            if (!$lockManager->isLockedByOtherUser($element, $this->getUser()->getId())) {
                $lock = $lockManager->lock($element, $this->getUser()->getId());
            }
        }

        if (!$lock) {
            $lock = $lockManager->findLock($element);
        }

        $lockInfo = null;

        if ($lock && !$diff) {
            $lockUser = $userManager->find($lock->getUserId());

            $lockInfo = [
                'status' => 'locked',
                'id' => $lock->getElement()->getEid(),
                'username' => $lockUser->getDisplayName(),
                'time' => $lock->getLockedAt()->format('Y-m-d H:i:s'),
                'age' => time() - $lock->getLockedAt()->format('U'),
                'type' => $lock->getType(),
            ];

            if ($lock->getUserId() === $this->getUser()->getId()) {
                $lockInfo['status'] = 'edit';
            } elseif ($lock->getType() === ElementLock::TYPE_PERMANENTLY) {
                $lockInfo['status'] = 'locked_permanently';
            }
        } elseif ($diff) {
            // Workaround for loading diffs without locking and view-mask
            // TODO: introduce new diff lock mode

            $lockInfo = [
                'status' => 'edit',
                'id' => '',
                'username' => '',
                'time' => '',
                'age' => 0,
                'type' => ElementLock::TYPE_TEMPORARY,
            ];
        }

        // meta

        $meta = [];
        $elementMetaSetResolver = $this->get('phlexible_element.element_meta_set_resolver');
        $elementMetaDataManager = $this->get('phlexible_element.element_meta_data_manager');
        $optionResolver = $this->get('phlexible_meta_set.option_resolver');
        $metaSetId = $elementtype->getMetaSetId();

        if ($metaSetId) {
            $metaSet = $elementMetaSetResolver->resolve($elementVersion);
            $metaData = $elementMetaDataManager->findByMetaSetAndElementVersion($metaSet, $elementVersion);

            $fieldDatas = [];

            foreach ($metaSet->getFields() as $field) {
                $options = $optionResolver->resolve($field);

                $fieldData = [
                    'key' => $field->getName(),
                    'type' => $field->getType(),
                    'options' => $options,
                    'readonly' => $field->isReadonly(),
                    'required' => $field->isRequired(),
                    'synchronized' => $field->isSynchronized(),
                ];

                if ($metaData) {
                    foreach ($metaData->getLanguages() as $metaLanguage) {
                        if ($language === $metaLanguage) {
                            $fieldData['value'] = $metaData->get($field->getName(), $language);
                            break;
                        }
                    }
                }

                $fieldDatas[] = $fieldData;
            }

            $meta = [
                'set_id' => $metaSetId,
                'title' => $metaSet->getName(),
                'fields' => $fieldDatas,
            ];
        }

        // redirects
        // TODO: auslagern

        $redirects = [];
        if (!$teaser && $this->container->has('redirectsManager')) {
            $redirectsManager = $this->get('redirectsManager');
            $redirects = $redirectsManager->getForTidAndLanguage($treeId, $language);
        }

        // preview / online url

        $urls = [
            'preview' => '',
            'online' => '',
        ];

        $publishDate = null;
        $publishUser = null;
        $onlineVersion = null;
        $latestVersion = null;

        if (in_array($elementtype->getType(), [Elementtype::TYPE_FULL, Elementtype::TYPE_STRUCTURE, Elementtype::TYPE_PART])) {
            if ($type === Elementtype::TYPE_FULL || $type === Elementtype::TYPE_PART) {
                $nodeUrlGenerator = $this->get('phlexible_tree.node_url_generator');
                $urls['preview'] = $nodeUrlGenerator->generatePreviewUrl($node, $language);

                if ($isPublished) {
                    $urls['online'] = $nodeUrlGenerator->generateOnlineUrl($node, $language);
                }
            }

            if ($isPublished) {
                if ($teaser) {
                    $teaserOnline = $teaserManager->findOneOnlineByTeaserAndLanguage($teaser, $language);
                    $publishDate = $teaserOnline->getPublishedAt()->format('Y-m-d H:i:s');
                    $publishUser = $userManager->find($teaserOnline->getPublishUserId());
                    $onlineVersion = $teaserOnline->getVersion();
                } else {
                    $treeNodeOnline = $tree->findOneOnlineByTreeNodeAndLanguage($node, $language);
                    $publishDate = $treeNodeOnline->getPublishedAt()->format('Y-m-d H:i:s');
                    $publishUser = $userManager->find($treeNodeOnline->getPublishUserId());
                    $onlineVersion = $treeNodeOnline->getVersion();
                }
            }

            $latestVersion = $element->getLatestVersion();
        }

        // configuration

        if ($teaser) {
            $configuration = $teaser->getAttributes();
        } else {
            $configuration = $node->getAttributes();
            $configuration['navigation'] = $node->getInNavigation() ? true : false;
        }

        // context
        // TODO: repair element context

        $context = [];
        if (0) {
            $contextManager = $this->get('phlexible_element.context.manager');

            if ($contextManager->useContext()) {
                $contextCountries = $contextManager->getAllCountries();

                $activeContextCountries = $teaserId
                    ? $contextManager->getActiveCountriesByTeaserId($teaserId)
                    : $contextManager->getActiveCountriesByTid($node->getId());

                foreach ($contextCountries as $contextKey => $contextValue) {
                    $context[] = [
                        'id' => $contextKey,
                        'country' => $contextValue,
                        'active' => in_array($contextKey, $activeContextCountries) ? 1 : 0,
                    ];
                }
            }
        }

        // pager

        $pager = [];
        if (!$teaser) {
            $parentNode = $tree->getParent($node);
            if ($parentNode) {
                $parentElement = $elementService->findElement($parentNode->getTypeId());
                $parentElementtype = $elementService->findElementtype($parentElement);
                if ($parentElementtype->getHideChildren()) {
                    $filter = new TreeFilter(
                        $this->get('doctrine.dbal.default_connection'),
                        $request->getSession(),
                        $this->get('event_dispatcher'),
                        $parentNode->getId(),
                        $language
                    );
                    $pager = $filter->getPager($node->getId());
                }
            }
        }

        // rights

        $permissionResolver = $this->get('phlexible_tree.node_permission_resolver');
        $tokenStorage = $this->get('security.token_storage');

        $userRights = $permissionResolver->resolve($node, $language, $tokenStorage->getToken());
        if ($userRights === null) {
            return new JsonResponse(array('success' => false, 'message' => 'no permission'));
        }

        // state

        $status = '';
        if ($teaser) {
            $stateManager = $this->get('phlexible_teaser.state_manager');
            if ($stateManager->isPublished($teaser, $language)) {
                $status = $stateManager->isAsync($teaser, $language) ? 'async' : 'online';
            }
        } else {
            $stateManager = $this->get('phlexible_tree.state_manager');
            if ($stateManager->isPublished($node, $language)) {
                $status = $stateManager->isAsync($node, $language) ? 'async' : 'online';
            }
        }

        $icon = $iconResolver->resolveTreeNode($node, $language);

        $createUser = $userManager->find($elementVersion->getCreateUserId());

        // glue together

        $properties = [
            'tid' => $treeId,
            'eid' => $eid,
            'siteroot_id' => empty($teaserId) ? $node->getTree()->getSiterootId() : null,
            'teaser_id' => $teaserId,
            'language' => $language,
            'version' => $elementVersion->getVersion(),
            'is_published' => $isPublished,
            'master' => $language === $element->getMasterLanguage() ? true : false,
            'status' => $status,
            'backend_title' => mb_substr(
                strip_tags($elementVersion->getBackendTitle($language, $elementMasterLanguage)),
                0,
                30,
                'UTF-8'
            ),
            'page_title' => mb_substr(
                strip_tags($elementVersion->getPageTitle($language, $elementMasterLanguage)),
                0,
                30,
                'UTF-8'
            ),
            'navigation_title' => mb_substr(
                strip_tags($elementVersion->getNavigationTitle($language, $elementMasterLanguage)),
                0,
                30,
                'UTF-8'
            ),
            'unique_id' => $element->getUniqueID(),
            'et_id' => $elementtype->getId(),
            'et_title' => $elementtype->getTitle(),
            'et_version' => $elementVersion->getElementTypeVersion().' ['.$elementtype->getRevision().']',
            'et_unique_id' => $elementtype->getUniqueId(),
            'et_type' => $elementtype->getType(),
            'author' => $createUser ? $createUser->getDisplayName() : 'Unknown',
            'create_date' => $elementVersion->getCreatedAt()->format('Y-m-d H:i:s'),
            'publish_date' => $publishDate,
            'publisher' => $publishUser ? $publishUser->getDisplayName() : null,
            'latest_version' => (int) $latestVersion,
            'online_version' => (int) $onlineVersion,
            'masterlanguage' => $elementMasterLanguage,
            'sort_mode' => $node->getSortMode(),
            'sort_dir' => $node->getSortDir(),
            'icon' => $icon,
            'navigation' => $node->getInNavigation(),
        ];

        $elementtypeSerializer = new ElementtypeArraySerializer();
        $serializedStructure = $elementtypeSerializer->serialize($elementtypeStructure);

        $elementSerializer = new ElementArraySerializer();
        $serializedValues = $elementSerializer->serialize($elementStructure, $language, $element->getMasterLanguage());

        $links = $linkFetcher->fetch($elementVersion, $language);

        $data = [
            'success' => true,
            'properties' => $properties,
            'configuration' => $configuration,
            'comment' => $elementVersion->getComment(),
            'meta' => $meta,
            'redirects' => $redirects,
            'default_tab' => $elementtype->getDefaultTab(),
            'default_content_tab' => $elementtype->getDefaultContentTab(),
            'lockinfo' => $lockInfo,
            'diff' => $diffInfo,
            'urls' => $urls,
            'context' => $context,
            'pager' => $pager,
            'rights' => $userRights,
            'instances' => $instances,
            'children' => $allowedChildren,
            'versions' => $versions,
            'valueStructure' => $serializedValues,
            'structure' => $serializedStructure,
            'links' => $links,
        ];

        $data = (object) $data;
        $event = new LoadDataEvent($node, $teaser, $language, $data);
        $this->get('event_dispatcher')->dispatch(ElementEvents::LOAD_DATA, $event);
        $data = (array) $data;

        return new JsonResponse($data);
    }
922482
public function layoutAction(Request $request)
    {
        $block = $this->findBlockByRequest($request);

        $data = $request->request->get('data', []);

        try {
            $this->getEditor()->getLayoutAdapter()->updateBlockLayout($block, $data);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

        $this->validate($block);
        $this->persist($block);

        $data = [
            'blocks' => [$this->getViewBuilder()->buildBlock($block)],
        ];

        return $this->buildResponse($data, self::SERIALIZE_LAYOUT);
    }
1038466
public function treeAction(Request $request)
    {
        $language = $request->get('language');
        $treeId = (int) $request->get('tid');

        if (!$treeId || !$language) {
            return new Response('', 500);
        }

        $translator = $this->get('translator');
        $treeManager = $this->get('phlexible_tree.tree_manager');
        $teaserService = $this->get('phlexible_teaser.teaser_service');
        $elementService = $this->get('phlexible_element.element_service');
        $elementSourceManager = $this->get('phlexible_element.element_source_manager');
        $iconResolver = $this->get('phlexible_element.icon_resolver');

        $tree = $treeManager->getByNodeId($treeId);
        $treeNode = $tree->get($treeId);
        $element = $elementService->findElement($treeNode->getTypeId());
        $elementMasterLanguage = $element->getMasterLanguage();
        $elementtype = $elementService->findElementtype($element);

        $treeNodePath = $tree->getPath($treeNode);

        $layouts = [];
        $layoutareas = [];
        // TODO: repair
        foreach ($elementSourceManager->findElementtypesByType('layout') as $layoutarea) {
            if (in_array($elementtype, $elementService->findAllowedParents($layoutarea))) {
                $layoutareas[] = $layoutarea;
            }
        }

        foreach ($layoutareas as $layoutarea) {
            $teasers = $teaserService->findForLayoutAreaAndTreeNodePath($layoutarea, $treeNodePath);
            $areaRoot = [
                'id' => 'area_'.$layoutarea->getId(),
                'area_id' => $layoutarea->getId(),
                'parent_tid' => $treeId,
                'parent_eid' => $element->getEid(),
                'text' => $layoutarea->getTitle(),
                'icon' => $iconResolver->resolveElementtype($layoutarea),
                'type' => $layoutarea->getType(),
                'inherited' => null, //true,
                'cls' => 'siteroot-node',
                'leaf' => true,
                'expanded' => true,
                'allowDrag' => true,
                'allowDrop' => false,
                'children' => [],
                'qtip' => $translator->trans('elements.doubleclick_to_sort', [], 'gui'),
            ];

            foreach ($teasers as $teaser) {
                /* @var $teaser Teaser */
                $teaserData = [
                    'id' => $teaser->getId(),
                    'layoutarea_id' => $layoutarea->getId(),
                    'parent_tid' => $treeId,
                    'parent_eid' => $element->getEid(),
                    'type' => $teaser->getType(),
                    'sort' => $teaser->getInheritSort($treeId),
                    'inherited' => false,
                    'inherit' => false,
                    'leaf' => true,
                    'hide' => false,
                    'expanded' => false,
                    'cls' => '',
                    'children' => [],
                    'allowDrag' => false,
                    'allowDrop' => false,
                ];

                switch ($teaser->getType()) {
                    case 'inherited':
                    case 'teaser':
                    case 'element':
                        $teaserElement = $elementService->findElement($teaser->getTypeId());
                        $teaserElementVersion = $elementService->findLatestElementVersion($teaserElement);

                        $cls = '';
                        if (!$teaser->isStopped()) {
                            $cls .= 'inherit ';
                        }
                        if ($teaser->isHidden()) {
                            $cls .= 'dont-show ';
                        }
                        if ($teaser->getTreeId() !== $treeId) {
                            $cls .= 'inherited ';
                        }

                        $teaserData = array_merge(
                            $teaserData,
                            [
                                'text' => $teaserElementVersion->getBackendTitle($language),
                                'icon' => $iconResolver->resolveTeaser($teaser, $language),
                                'eid' => $teaserElement->getEid(),
                                'inherited' => $teaser->getTreeId() !== $treeId,
                                'inherit' => !$teaser->isStopped(),
                                'cls' => trim($cls),
                                'hide' => $teaser->isHidden(),
                            ]
                        );
                        break;

                    default:
                        continue;
                }

                $areaRoot['children'][] = $teaserData;
            }

            if (count($areaRoot['children'])) {
                $areaRoot['leaf'] = false;
            }

            $layouts[] = $areaRoot;
        }

        return new JsonResponse($layouts);
    }
383440
public function listContentTypes(Request $request)
    {
        if ($this->getMediaType($request) === 'application/vnd.ez.api.contenttypelist') {
            $return = new Values\ContentTypeList(array(), $request->getPathInfo());
        } else {
            $return = new Values\ContentTypeInfoList(array(), $request->getPathInfo());
        }

        if ($request->query->has('identifier')) {
            $return->contentTypes = array($this->loadContentTypeByIdentifier($request));

            return $return;
        }

        if ($request->query->has('remoteId')) {
            $return->contentTypes = array(
                $this->loadContentTypeByRemoteId($request),
            );

            return $return;
        }

        $limit = null;
        if ($request->query->has('limit')) {
            $limit = (int)$request->query->get('limit', null);
            if ($limit <= 0) {
                throw new BadRequestException('wrong value for limit parameter');
            }
        }
        $contentTypes = $this->getContentTypeList();
        $sort = $request->query->get('sort');
        if ($request->query->has('orderby')) {
            $orderby = $request->query->get('orderby');
            $this->sortContentTypeList($contentTypes, $orderby, $sort);
        }
        $offset = $request->query->get('offset', 0);
        $return->contentTypes = array_slice($contentTypes, $offset, $limit);

        return $return;
    }
999527
public function treeAction(Request $request)
    {
        $siterootId = $request->get('siteroot_id');
        $tid = $request->get('node');
        $language = $request->get('language');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $elementService = $this->get('phlexible_element.element_service');
        $nodeSerializer = $this->get('phlexible_tree.node_serializer');

        // TODO: switch to master language of element
        $defaultLanguage = $this->container->getParameter('phlexible_cms.languages.default');

        $tree = $treeManager->getBySiteRootId($siterootId);
        $rootNode = $tree->getRoot();

        $data = [];
        if ($rootNode) {
            if ($tid === null || $tid < 1) {
                $data = [$nodeSerializer->serializeNode($rootNode, $language, $this->container->get('security.token_storage')->getToken())];
            } else {
                $node = $tree->get($tid);

                // check if children of this node should be shown
                $element = $elementService->findElement($node->getTypeId());
                $elementtype = $elementService->findElementtype($element);

                $nodes = $tree->getChildren($node);
                if (!empty($nodes) && !$elementtype->getHideChildren()) {
                    $data = $nodeSerializer->serializeNodes($nodes, $language, $this->container->get('security.token_storage')->getToken());
                }
            }
        }

        return new JsonResponse($data);
    }
1241761
public function sortAction(Request $request)
    {
        $treeId = $request->get('tid');
        $layoutAreaId = $request->get('area_id');
        $sortIds = $request->get('sort_ids');
        $sortIds = json_decode($sortIds, true);

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $teaserManager = $this->get('phlexible_teaser.teaser_manager');
        $dispatcher = $this->get('event_dispatcher');

        $tree = $treeManager->getByNodeId($treeId);
        $node = $tree->get($treeId);

        $teasers = array();
        foreach ($sortIds as $sort => $teaserId) {
            $teaser = $teaserManager->find($teaserId);
            if ((int) $treeId === (int) $teaser->getTreeId()) {
                $teaser->setSort($sort);
            } else {
                $teaser->setInheritSort($treeId, $sort);
            }
            $teasers[] = $teaser;
        }

        $event = new ReorderTeasersEvent($node, $layoutAreaId, $teasers);
        if ($dispatcher->dispatch(TeaserEvents::REORDER_TEASERS, $event)->isPropagationStopped()) {
            throw new RuntimeException('Teaser sort cancelled by event');
        }

        $teaserManager->updateTeasers($teasers);

        $event = new ReorderTeasersEvent($node, $layoutAreaId, $teasers);
        $dispatcher->dispatch(TeaserEvents::BEFORE_REORDER_TEASERS, $event);

        return new ResultResponse(true, 'Teaser sort published.');
    }
1363698
public function listAction(Request $request)
    {
        $theme = $request->attributes->get(
            'synapse_theme',
            $this->container->get('synapse')
                ->enableDefaultTheme()
                ->getCurrentTheme()
        );

        $templateCollection = $this->container->get('synapse.template.loader')
            ->retrieveAll(array(
                'scope' => TemplateInterface::GLOBAL_SCOPE,
                'templateTypeId' => $theme->getTemplateTypes()->column('id')
            ))
        ;
        $templateMap = array();
        foreach ($templateCollection as $template) {
            $templateMap[$template->getTemplateType()->getName()][$template->getContentType()->getName()] = $template;
        }

        return $this->render('SynapseAdminBundle:Template:list.html.twig', array(
            'theme' => $theme,
            'content_types' => $this->container->get('synapse.content_type.loader')
                ->retrieveAll(),
            'templates' => $templateMap,
        ));
    }
1193222
public function listAction(Request $request)
    {
        return new JsonResponse(
            $this->finder->search(
                'UJM\ExoBundle\Entity\Item\Item',
                $request->query->all(),
                [Transfer::INCLUDE_SOLUTIONS, Transfer::INCLUDE_ADMIN_META]
            )
        );
    }
689490
public function listAction(Request $request)
    {
        $current_page = $request->get('page', 1);
        $current_page = $current_page > 1 ? $current_page : 1;
        $rep = $this->getRepository();

        // filter list notice
        $filter = $this->createForm('notices_filter')->handleRequest($request);
        if ($filter->isValid()) {
            $query = $rep->getFilteredQuery($filter->getData()['status'], $filter->getData()['type']);
        } else {
            $query = $rep->createQueryBuilder('n');
        }
        $query
            ->orderBy('n.date_created', 'DESC')
            ->setFirstResult(($current_page - 1) * self::NOTICE_PER_PAGE)
            ->setMaxResults(self::NOTICE_PER_PAGE);
        $list = $query->getQuery()->getResult();

        // get count all items
        $count = $query
            ->select('COUNT(n)')
            ->getQuery()
            ->getSingleScalarResult();

        // pagination
        $that = $this;
        $request_query = $request->query->all();
        unset($request_query['page']);
        $pagination = $this->get('anime_db.pagination')
            ->create(ceil($count / self::NOTICE_PER_PAGE), $current_page)
            ->setPageLink(function ($page) use ($that, $request_query) {
                return $that->generateUrl('notice_list', array_merge($request_query, ['page' => $page]));
            })
            ->setFirstPageLink($this->generateUrl('notice_list', $request_query))
            ->getView();

        return $this->render('AnimeDbCatalogBundle:Notice:list.html.twig', [
            'list' => $list,
            'pagination' => $pagination,
            'change_form' => $this->createForm(new ChangeNotice())->createView(),
            'filter' => $filter->createView(),
            'action_remove' => ChangeNotice::ACTION_REMOVE,
        ]);
    }
761743
public function newChildAction(Request $request)
    {
        $this->isGranted('CREATE');

        $context = $this->loadContext($request);

        $resourceName = $this->config->getResourceName();
        $resource = $context->getResource($resourceName);

        $child = $this->createNewFromParent($context, $resource);

        if (0 < strlen($referer = $request->headers->get('referer'))) {
            $cancelPath = $referer;
        } else {
            $cancelPath = $this->generateResourcePath($request);
        }

        $form = $this
            ->createForm($this->config->getFormType(), $child, [
                'action' => $this->generateUrl(
                    $this->config->getRoute('new_child'),
                    $context->getIdentifiers(true)
                ),
                'method' => 'POST',
                'attr' => [
                    'class' => 'form-horizontal form-with-tabs',
                ],
                'admin_mode' => true,
                '_redirect_enabled' => true,
            ])
            ->add('actions', 'form_actions', [
                'buttons' => [
                    'saveAndList' => [
                        'type' => 'submit', 'options' => [
                            'button_class' => 'primary',
                            'label' => 'ekyna_core.button.save_and_list',
                            'attr' => [
                                'icon' => 'list',
                            ],
                        ],
                    ],
                    'save' => [
                        'type' => 'submit', 'options' => [
                            'button_class' => 'primary',
                            'label' => 'ekyna_core.button.save',
                            'attr' => [
                                'icon' => 'ok',
                            ],
                        ],
                    ],
                    'cancel' => [
                        'type' => 'button', 'options' => [
                            'label' => 'ekyna_core.button.cancel',
                            'button_class' => 'default',
                            'as_link' => true,
                            'attr' => [
                                'class' => 'form-cancel-btn',
                                'icon' => 'remove',
                                'href' => $cancelPath,
                            ],
                        ],
                    ],
                ],
            ])
        ;

        $form->handleRequest($this->getRequest());
        if ($form->isValid()) {

            $this->getRepository()->persistAsLastChildOf($child, $resource);

            // TODO use ResourceManager
            $event = $this->getOperator()->create($child);

            /* if ($request->isXmlHttpRequest()) {
                if ($event->hasErrors()) {
                    $errorMessages = $event->getErrors();
                    $errors = [];
                    foreach ($errorMessages as $message) {
                        $errors[] = $message->getMessage();
                    }
                    return new JsonResponse(array('error' => implode(', ', $errors)));
                }

                return new JsonResponse(array(
                    'id' => $resource->getId(),
                    'name' => (string)$resource,
                ));
            }*/

            $event->toFlashes($this->getFlashBag());

            if (!$event->hasErrors()) {
                /** @noinspection PhpUndefinedMethodInspection */
                if ($form->get('actions')->get('saveAndList')->isClicked()) {
                    $redirectPath = $this->generateResourcePath($resource, 'list');
                } elseif (null === $redirectPath = $form->get('_redirect')->getData()) {
                    $redirectPath = $this->generateResourcePath($child);
                }
                return $this->redirect($redirectPath);
            }
        }

        return $this->render(
            $this->config->getTemplate('new_child.html'),
            $context->getTemplateVars([
                'child' => $child,
                'form' => $form->createView()
            ])
        );
    }
755063
public function parentPageListAction(Request $request)
    {
        $locale = $request->get('locale');
        $pages = [];
        $pageManager = $this->get('networking_init_cms.page_manager');

        if ($result = $pageManager->getParentPagesChoices($locale)) {
            foreach ($result as $page) {
                /* @var PageInterface $page */
                $pages[$page->getId()] = [$page->getAdminTitle()];
            }
        }

        return $this->renderJson($pages);
    }
718241
public function index(Request $request)
    {
        // Set roles that have access
        $request->user()->authorizeRoles(['admin']);

        // Get all pagetypes
        $pagetypes = PageType::orderBy('updated_at', 'desc')
            ->orderBy('created_at', 'desc')
            ->paginate(self::PAGINATION_ITEMS);

        return view('page::pagetypes.index', ['pagetypes' => $pagetypes]);
    }
188239
public function listSections(Request $request)
    {
        if ($request->query->has('identifier')) {
            $sections = array(
                $this->loadSectionByIdentifier($request),
            );
        } else {
            $sections = $this->sectionService->loadSections();
        }

        return new Values\SectionList($sections, $request->getPathInfo());
    }