eZ\Publish\Core\Repository\Repository::getContentTypeService PHP Method

getContentTypeService() public method

Get service object to perform operations on Content Type objects and it's aggregate members. ( Group, Field & FieldCategory )
public getContentTypeService ( ) : eZ\Publish\API\Repository\ContentTypeService
return eZ\Publish\API\Repository\ContentTypeService
    public function getContentTypeService()
    {
        if ($this->contentTypeService !== null) {
            return $this->contentTypeService;
        }
        $this->contentTypeService = new ContentTypeService($this, $this->persistenceHandler->contentTypeHandler(), $this->getDomainMapper(), $this->getContentTypeDomainMapper(), $this->getFieldTypeRegistry(), $this->serviceSettings['contentType']);
        return $this->contentTypeService;
    }

Usage Example

    /**
     * Validates sort clauses of a given $query.
     *
     * For the moment this validates only Field sort clauses.
     * Valid Field sort clause provides $languageCode if targeted field is translatable,
     * and the same in reverse - it does not provide $languageCode for non-translatable field.
     *
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If sort clauses are not valid
     *
     * @param \eZ\Publish\API\Repository\Values\Content\Query $query
     *
     * @return void
     */
    protected function validateSortClauses( Query $query )
    {
        foreach ( $query->sortClauses as $key => $sortClause )
        {
            if ( !$sortClause instanceof SortClause\Field && !$sortClause instanceof SortClause\MapLocationDistance )
            {
                continue;
            }

            /** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause\Target\FieldTarget|\eZ\Publish\API\Repository\Values\Content\Query\SortClause\Target\MapLocationTarget $fieldTarget */
            $fieldTarget = $sortClause->targetData;
            $contentType = $this->repository->getContentTypeService()->loadContentTypeByIdentifier(
                $fieldTarget->typeIdentifier
            );

            if ( $contentType->getFieldDefinition( $fieldTarget->fieldIdentifier )->isTranslatable )
            {
                if ( $fieldTarget->languageCode === null )
                {
                    throw new InvalidArgumentException(
                        "\$query->sortClauses[{$key}]", "No language is specified for translatable field"
                    );
                }
            }
            else if ( $fieldTarget->languageCode !== null )
            {
                throw new InvalidArgumentException(
                    "\$query->sortClauses[{$key}]", "Language is specified for non-translatable field, null should be used instead"
                );
            }
        }
    }
All Usage Examples Of eZ\Publish\Core\Repository\Repository::getContentTypeService