Returns paged content based on ContentType ids.

@param array $contentTypeIds
@param \Symfony\Component\HttpFoundation\Request $request

@return array
973181
protected function prepareContentByContentTypeIds($contentTypeIds, Request $request)
    {
        $options = $this->parseParameters($request->query, ['page_size', 'page', 'path', 'hidden', 'lang', 'sa', 'image']);

        $pageSize = (int)$options->get('page_size', self::PAGE_SIZE);
        $page = (int)$options->get('page', 1);
        $offset = $page * $pageSize - $pageSize;
        $path = $options->get('path');
        $hidden = $options->get('hidden');
        $lang = $options->get('lang');
        $siteAccess = $options->get('sa');

        $rootLocationPathString = $this->locationService->loadLocation(
            $this->siteAccessHelper->getRootLocationBySiteAccessName($siteAccess)
        )->pathString;

        $contentItems = array();

        foreach ($contentTypeIds as $contentTypeId) {
            $criteria = array(new Criterion\ContentTypeId($contentTypeId));

            if ($path) {
                $criteria[] = new Criterion\Subtree($path);
            }

            if (!$hidden) {
                $criteria[] = new Criterion\Visibility(Criterion\Visibility::VISIBLE);
            }

            $criteria[] = new Criterion\Subtree($rootLocationPathString);

            $query = new Query();
            $query->query = new Criterion\LogicalAnd($criteria);
            $query->limit = $pageSize;
            $query->offset = $offset;

            $contentItems[$contentTypeId] = $this->searchService->findContent(
                $query,
                (!empty($lang) ? array('languages' => array($lang)) : array())
            )->searchHits;
        }

        $contentOptions = $this->parseParameters($request->query, ['lang', 'fields', 'image']);

        return $this->content->prepareContent($contentItems, $contentOptions);
    }
106395
public function getAllRecords($contentTypeName = null, DataDimensions $dataDimensions = null)
    {
        if ($contentTypeName == null)
        {
            $contentTypeName = $this->getCurrentContentTypeName();
        }

        if ($dataDimensions == null)
        {
            $dataDimensions = $this->getCurrentDataDimensions();
        }

        if ($this->hasContentType($contentTypeName))
        {
            if ($this->hasStashedAllRecords($contentTypeName, $dataDimensions, $this->getRecordClassForContentType($contentTypeName)))
            {
                return $this->getStashedAllRecords($contentTypeName, $dataDimensions, $this->getRecordClassForContentType($contentTypeName));
            }

            $records = $this->requestRecords($contentTypeName, $dataDimensions, '');

            $this->stashAllRecords($records, $dataDimensions);

            return $records;
        }

        throw new AnyContentClientException ('Unknown content type ' . $contentTypeName);
    }
135334
private function loadContentType(int $contentTypeId, array $languageCodes): ContentType
    {
        return $this->repository->getContentTypeService()->loadContentType($contentTypeId, $languageCodes);
    }
1181920
public function viewNgCategory(Request $request, ContentView $view, array $params = [])
    {
        $content = $view->getSiteContent();
        $location = $view->getSiteLocation();
        if (!$location instanceof Location) {
            $location = $content->mainLocation;
        }

        $response = $this->checkCategoryRedirect($location);
        if ($response instanceof Response) {
            return $response;
        }

        $criteria = [
            new Criterion\Subtree($location->pathString),
            new Criterion\Visibility(Criterion\Visibility::VISIBLE),
            new Criterion\LogicalNot(new Criterion\LocationId($location->id)),
        ];

        if (!$content->getField('fetch_subtree')->value->bool) {
            $criteria[] = new Criterion\Location\Depth(Criterion\Operator::EQ, $location->depth + 1);
        }

        if (!$content->getField('children_class_filter_include')->isEmpty()) {
            $contentTypeFilter = $content->getField('children_class_filter_include')->value;
            $criteria[] = new Criterion\ContentTypeIdentifier(
                array_map(
                    'trim',
                    explode(',', $contentTypeFilter->text)
                )
            );
        }

        $query = new LocationQuery();
        $query->filter = new Criterion\LogicalAnd($criteria);
        $query->sortClauses = $location->innerLocation->getSortClauses();

        $pager = new Pagerfanta(
            new FilterAdapter(
                $query,
                $this->getSite()->getFilterService()
            )
        );

        $pager->setNormalizeOutOfRangePages(true);

        /** @var \eZ\Publish\Core\FieldType\Integer\Value $pageLimitValue */
        $pageLimitValue = $content->getField('page_limit')->value;

        $defaultLimit = 12;

        $childrenLimit = (int) ($params['childrenLimit'] ?? $defaultLimit);
        $childrenLimit = $childrenLimit > 0 ? $childrenLimit : $defaultLimit;

        $pager->setMaxPerPage($pageLimitValue->value > 0 ? (int) $pageLimitValue->value : $childrenLimit);

        $currentPage = (int) $request->get('page', 1);
        $pager->setCurrentPage($currentPage > 0 ? $currentPage : 1);

        $view->addParameters([
            'pager' => $pager,
        ]);

        return $view;
    }
879473
protected function getFieldIds($contentId, array $fieldIdentifiers)
    {
        $ids = [];
        foreach ($fieldIdentifiers as $identifier) {
            try {
                $ids[] = $this->contentTypeUtils->getFieldId($contentId, $identifier);
            } catch (OutOfBoundsException $e) {
                continue;
            }
        }

        return $ids;
    }
371741
public function deleteContentTypeDraft($contentTypeId)
    {
        $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
        $this->contentTypeService->deleteContentType($contentTypeDraft);

        return new Values\NoContent();
    }
965401
protected function getAllMultiViewRecords($contentTypeName = null, DataDimensions $dataDimensions)
    {

        $data = $this->readRecords($this->getConfiguration()->getUriRecords($contentTypeName));

        if ($data)
        {
            $data = json_decode($data, true);

            $data['records'] = array_filter($data['records']);

            $definition = $this->getContentTypeDefinition($contentTypeName);

            $records = $this->getRecordFactory()
                            ->createRecordsFromJSONRecordsArray($definition, $data['records']);

            return $records;
        }

        return [ ];

    }
1074005
public function show(Request $request, $contentId = null)
    {
        $contentFolder = $this->content->findById($contentId);

        if (! $contentFolder) {
            return $this->respondNotFound(trans('soda::errors.not-found', ['object' => trans('soda::terminology.content')]));
        } elseif (! $contentFolder->is_folder) {
            return $this->respondNotAllowed(ucwords(trans('soda::terminology.content')).' is not a folder');
        }

        $content = $this->content->listFolder($request, $contentFolder);
        $contentTypes = $this->content->getCreatableContentTypes($contentFolder->id);

        return $this->respond(compact('contentFolder', 'content', 'contentTypes'));
    }
608013
public function getContentType(string $id): ?ContentType
    {
        foreach ($this->clientsConfig as $clientConfig) {
            /** @var \Contentful\Delivery\Client $client */
            $client = $clientConfig['service'];

            foreach ($client->getContentTypes()->getItems() as $contentType) {
                /** @var \Contentful\Delivery\Resource\ContentType $contentType */
                if ($contentType->getId() === $id) {
                    return $contentType;
                }
            }
        }

        return null;
    }
1218027
public function action($contentTypeName, array $changeRequest)
    {
        foreach ($changeRequest as $recordId => $actionData) {
            if ($actionData === null) {
                continue;
            }

            $repo = $this->em->getRepository($contentTypeName);
            foreach ($actionData as $action => $fieldData) {
                if (!$entity = $repo->find($recordId)) {
                    continue;
                }
                $this->modifyContentTypeRecord($repo, $entity, $action, $fieldData);
            }
        }
    }
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;
    }
1310244
protected function getIds( $request )
	{
		$ids = [];

		if( isset( $request->data ) )
		{
			foreach( (array) $request->data as $entry )
			{
				if( isset( $entry->id ) ) {
					$ids[] = $entry->id;
				}
			}
		}

		return $ids;
	}
360971
public function preview(Request $request, $contenttypeslug)
    {
        if (!$request->isMethod('POST')) {
            throw new MethodNotAllowedHttpException(['POST'], 'This route only accepts POST requests.');
        }

        $contenttype = $this->getContentType($contenttypeslug);
        $formValues = $request->request->all();

        $storage = $this->storage();
        if ($storage instanceof EntityManager) {
            /** @var EntityManager $storage */
            /** @var Content $content */
            $content = $storage->create($contenttypeslug, $formValues);

            /** @var Collection\Relations $related */
            $related = $storage->createCollection(Relations::class);
            $related->setFromPost($formValues, $content);
            $content->setRelation($related);

            /** @var Collection\Taxonomy $taxonomies */
            $taxonomies = $storage->createCollection(Taxonomy::class);
            $taxonomies->setFromPost($formValues, $content);
            $content->setTaxonomy($taxonomies);

        } else {
            $content = $storage->getContentObject($contenttypeslug, [], false);
            $content->setFromPost($formValues, $contenttype);
        }

        $this->fixBlockFieldsForPreview($content);
        $this->fixHTMLFieldsForPreview($content);

        $liveEditor = $request->get('_live-editor-preview');
        if (!empty($liveEditor)) {
            $jsFile = (new JavaScript('js/ckeditor/ckeditor.js', 'bolt'))
                ->setPriority(1)
                ->setLate(false);
            $cssFile = (new Stylesheet('css/liveeditor.css', 'bolt'))
                ->setPriority(5)
                ->setLate(false);
            $snippet = (new Snippet())
                ->setCallback('<script>window.boltIsEditing = true;</script>')
                ->setLocation(Target::BEFORE_HEAD_JS);

            $this->app['asset.queue.snippet']->add($snippet);
            $this->app['asset.queue.file']->add($jsFile);
            $this->app['asset.queue.file']->add($cssFile);
        }

        // Then, select which template to use, based on our 'cascading templates rules'
        $template = $this->templateChooser()->record($content);

        // Make sure we can also access it as {{ page.title }} for pages, etc. We set these in the global scope,
        // So that they're also available in menu's and templates rendered by extensions.
        $globals = [
            'record'                      => $content,
            $contenttype['singular_slug'] => $content,
        ];

        return $this->render($template, [], $globals);
    }
1256517
public function listAction(Request $request): Response
    {
        $deletableContentTypeGroup = [];
        $count = [];

        $page = $request->query->get('page') ?? 1;

        $pagerfanta = new Pagerfanta(
            new ArrayAdapter($this->contentTypeService->loadContentTypeGroups())
        );

        $pagerfanta->setMaxPerPage($this->defaultPaginationLimit);
        $pagerfanta->setCurrentPage(min($page, $pagerfanta->getNbPages()));

        /** @var \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] $contentTypeGroupList */
        $contentTypeGroupList = $pagerfanta->getCurrentPageResults();

        $deleteContentTypeGroupsForm = $this->formFactory->deleteContentTypeGroups(
            new ContentTypeGroupsDeleteData($this->getContentTypeGroupsNumbers($contentTypeGroupList))
        );

        foreach ($contentTypeGroupList as $contentTypeGroup) {
            $contentTypesCount = count($this->contentTypeService->loadContentTypes($contentTypeGroup));
            $deletableContentTypeGroup[$contentTypeGroup->id] = !(bool)$contentTypesCount;
            $count[$contentTypeGroup->id] = $contentTypesCount;
        }

        return $this->render('@ezdesign/admin/content_type_group/list.html.twig', [
            'pager' => $pagerfanta,
            'form_content_type_groups_delete' => $deleteContentTypeGroupsForm->createView(),
            'deletable' => $deletableContentTypeGroup,
            'content_types_count' => $count,
            'can_create' => $this->isGranted(new Attribute('class', 'create')),
            'can_update' => $this->isGranted(new Attribute('class', 'update')),
            'can_delete' => $this->isGranted(new Attribute('class', 'delete')),
        ]);
    }
400474
public function searchAction(Request $request, $contentId)
    {
        $this->denyAccessUnlessGranted('ez:infocollector:read');

        $content = $this->contentService->loadContent($contentId);

        $query = new Query([
            'contentId' => $contentId,
            'searchText' => $request->query->get('searchText'),
        ]);
        $adapter = new InformationCollectionCollectionListSearchAdapter($this->service, $query);
        $pager = $this->getPager($adapter, (int)$request->query->get('page'));

        return $this->render("NetgenInformationCollectionBundle:admin:collection_list.html.twig",
            [
                'objects' => $pager,
                'content' => $content,
            ]
        );
    }
1194272
private function getRelatedContentItems(array $relatedContentIds, array $contentTypeIdentifiers)
    {
        if (count($relatedContentIds) === 0) {
            return [];
        }

        $criteria = new ContentId($relatedContentIds);

        if (!empty($contentTypeIdentifiers)) {
            $criteria = new LogicalAnd([
                $criteria,
                new ContentTypeIdentifier($contentTypeIdentifiers),
            ]);
        }

        $query = new Query([
            'filter' => $criteria,
            'limit' => count($relatedContentIds),
        ]);

        $searchResult = $this->site->getFilterService()->filterContent($query);
        /** @var \eZ\Publish\API\Repository\Values\Content\Content[] $contentItems */
        $contentItems = $this->extractValueObjects($searchResult);

        return $contentItems;
    }
1339846
public function resolveContentId($contentTypeId, $contentId)
    {
        // content type ?
        if (!$contentType = $this->contentTypeLoader->retrieve($contentTypeId)) {
            throw new InvalidContentException(sprintf(
                'No content type registered under "%s" id, check you configuration.',
                $contentTypeId
            ));
        }

        // content object
        if (!$content = $contentType->retrieveContent($contentId)) {
            throw new InvalidContentException(sprintf(
                'Unable to get a "%s" content under "%s" id.',
                $contentType->getName(),
                $contentId
            ));
        }

        return $this->wrap($contentType, $content);
    }