@param ContentGroup           $contentGroup
@param ContentGroupDefinition $contentGroupSchema

@return ContentGroup
969958
private function syncContentGroupWithSchema(ContentGroup $contentGroup, ContentGroupDefinition $contentGroupSchema)
    {
        $contentGroup->htmlContentAreas->removeWhere(function (HtmlContentArea $area) use ($contentGroupSchema) {
            return !isset($contentGroupSchema->htmlAreas[$area->name]);
        });

        $htmlNames = $contentGroup->htmlContentAreas->indexBy(function (HtmlContentArea $area) {
            return $area->name;
        })->asArray();

        foreach (array_diff_key($contentGroupSchema->htmlAreas, $htmlNames) as $area) {
            $contentGroup->htmlContentAreas[] = new HtmlContentArea($area['name'], new Html(''));
        }

        $contentGroup->imageContentAreas->removeWhere(function (ImageContentArea $area) use ($contentGroupSchema) {
            return !isset($contentGroupSchema->images[$area->name]);
        });

        $imageNames = $contentGroup->imageContentAreas->indexBy(function (ImageContentArea $area) {
            return $area->name;
        })->asArray();

        foreach (array_diff_key($contentGroupSchema->images, $imageNames) as $area) {
            $contentGroup->imageContentAreas[] = new ImageContentArea($area['name'], new Image(''));
        }

        $validTextOptions = array_fill_keys(array_column($contentGroupSchema->textAreas, 'name'), true);
        $contentGroup->textContentAreas->removeWhere(function (TextContentArea $contentArea) use ($validTextOptions) {
            return !isset($validTextOptions[$contentArea->name]);
        });

        $textNames = $contentGroup->textContentAreas->indexBy(function (TextContentArea $contentArea) {
            return $contentArea->name;
        })->asArray();

        foreach (array_diff_key($validTextOptions, $textNames) as $name => $unusedVariable) {
            $contentGroup->textContentAreas[] = new TextContentArea($name, '');
        }

        
        $contentGroup->fileContentAreas->removeWhere(function (FileContentArea $area) use ($contentGroupSchema) {
            return !isset($contentGroupSchema->fileAreas[$area->name]);
        });

        $fileNames = $contentGroup->fileContentAreas->indexBy(function (FileContentArea $area) {
            return $area->name;
        })->asArray();

        foreach (array_diff_key($contentGroupSchema->fileAreas, $fileNames) as $area) {
            $contentGroup->fileContentAreas[] = new FileContentArea($area['name'], new File(''));
        }

        $validMetadataOptions = array_fill_keys(array_column($contentGroupSchema->metadata, 'name'), true);
        $contentGroup->metadata->removeWhere(function (ContentMetadata $metadata) use ($validMetadataOptions) {
            return !isset($validMetadataOptions[$metadata->name]);
        });

        $metadataNames = $contentGroup->metadata->indexBy(function (ContentMetadata $content) {
            return $content->name;
        })->asArray();

        foreach (array_diff_key($validMetadataOptions, $metadataNames) as $name => $unusedVariable) {
            $contentGroup->metadata[] = new ContentMetadata($name, '');
        }

        $validArrayOptions = array_fill_keys(array_column($contentGroupSchema->nestedArrayContentGroups, 'name'), true);
        $contentGroup
            ->nestedArrayContentGroups
            ->removeWhere(function (ContentGroup $group) use ($validArrayOptions) {
                return !isset($validArrayOptions[$group->name]);
            });
    }
1121568
public function setContentType($contentType, $charset = null)
    {
        if ($charset === null) {
            $this->setHeader('Content-Type', $contentType);
        } else {
            $this->setHeader('Content-Type', $contentType . '; charset=' . $charset);
        }

        return $this;
    }
302762
public function getObjectStatesForContent($contentId)
    {
        $groups = $this->objectStateService->loadObjectStateGroups();
        $contentInfo = $this->contentService->loadContentInfo($contentId);

        $contentObjectStates = array();

        foreach ($groups as $group) {
            try {
                $state = $this->objectStateService->getContentState($contentInfo, $group);
                $contentObjectStates[] = new RestObjectState($state, $group->id);
            } catch (NotFoundException $e) {
                // Do nothing
            }
        }

        return new ContentObjectStates($contentObjectStates);
    }
915512
public function setContentType($contentType)
    {
        if (is_bool(strpos($contentType, 'charset=')) && $this->charset) {
            $contentType .= '; charset=' . $this->charset;
        }
        
        $this->headers['Content-Type'] = $contentType;
        return $this;
    }
1051177
public function deleteContentTypeGroup($contentTypeGroupId)
    {
        $contentTypeGroup = $this->contentTypeService->loadContentTypeGroup($contentTypeGroupId);

        $contentTypes = $this->contentTypeService->loadContentTypes($contentTypeGroup);
        if (!empty($contentTypes)) {
            throw new ForbiddenException('Only empty content type groups can be deleted');
        }

        $this->contentTypeService->deleteContentTypeGroup($contentTypeGroup);

        return new Values\NoContent();
    }
471190
protected function createResponse($content, $contentType)
    {
        $resp = new HttpResponse();

        $resp->setStatusCode(200)
             ->setContent($content);
        $resp->getHeaders()->addHeaders(array(
            'Content-Length'    => strlen($content),
            'Content-Type'      => $contentType
        ));
        return $resp;
    }
1137654
public function load(string $moduleAndGroupName) : LoadedContentGroup
    {
        if (substr_count($moduleAndGroupName, '.') !== 1) {
            throw InvalidArgumentException::format(
                'Invalid content group name supplied to %s: expecting format \'module-name.group-name\', \'%s\' given',
                __METHOD__, $moduleAndGroupName
            );
        }

        list($moduleName, $groupName) = explode('.', $moduleAndGroupName);

        if (!isset($this->cache[$moduleAndGroupName])) {
            $groups = $this->contentGroupRepo->matching(
                $this->contentGroupRepo->criteria()
                    ->where(ContentGroup::NAMESPACE, '=', $moduleName)
                    ->where(ContentGroup::NAME, '=', $groupName)
            );

            $this->cache[$moduleAndGroupName] = new LoadedContentGroup($this->config, $groups[0] ?? new ContentGroup($moduleName, $groupName, $this->clock));
        }

        return $this->cache[$moduleAndGroupName];
    }
876825
public function load(string $moduleAndGroupName) : LoadedContentGroup
    {
        foreach ($this->previewContentGroups as $contentGroup) {
            if ($contentGroup->namespace . '.' . $contentGroup->name === $moduleAndGroupName) {
                return new LoadedContentGroup($this->config, $contentGroup);
            }
        }

        return $this->innerContentLoader->load($moduleAndGroupName);
    }
1047824
public function listContentTypesForGroup($contentTypeGroupId, Request $request)
    {
        $contentTypes = $this->contentTypeService->loadContentTypes(
            $this->contentTypeService->loadContentTypeGroup($contentTypeGroupId, Language::ALL),
            Language::ALL
        );

        if ($this->getMediaType($request) === 'application/vnd.ez.api.contenttypelist') {
            return new Values\ContentTypeList($contentTypes, $request->getPathInfo());
        }

        return new Values\ContentTypeInfoList($contentTypes, $request->getPathInfo());
    }
1227416
protected function contentTypeHasFieldDefinition(ContentType $contentType, $fieldIdentifier)
    {
        $existingFieldDefinitions = $contentType->fieldDefinitions;

        foreach ($existingFieldDefinitions as $existingFieldDefinition) {
            if ($fieldIdentifier == $existingFieldDefinition->identifier) {
                return $existingFieldDefinition;
            }
        }

        return null;
    }
1354484
private function detachContentTypeGroupsByIdentifiers(ContentType $contentType, array $contentTypeGroupsIdentifiers)
    {
        $contentTypeGroups = $this->loadContentTypeGroupsByIdentifiers($contentTypeGroupsIdentifiers);
        foreach ($contentTypeGroups as $contentTypeGroup) {
            $this->contentTypeService->unassignContentTypeGroup($contentType, $contentTypeGroup);
        }
    }
979900
public function getFieldById(ContentTypeInterface $contentType, $fieldId)
    {
        $field = $this->om->getRepository($this->configurationManager->getEntityClass('field'))->find($fieldId);


        if (!$field instanceof FieldInterface) {
            return null;
        }
        if ($field->getContentType() && $field->getContentType()->getId() == $contentType->getId()) {
            return $field;
        }

        $parent = $field;
        while ($parent && $parentLayout = $parent->getLayout()) {
            if ($parent = $parentLayout->getParent()) {
                if ($parent->getContentType() !== null && $parent->getContentType()->getId() == $contentType->getId()) {
                    return $field;
                }
            }
        }

        return null;
    }
1208992
public function createEditForm(ContentNode $contentNode, Node $rootNode = null)
    {

        $templateVars = array(
            'action' => $this->get('router')->generate('mm_cmf_content_node_update', array(
                'id' => $contentNode->getId()
            ))
        );

        if ($rootNode)
            $templateVars['root_node'] = $rootNode;

        return $this->createForm(
            ContentNodeType::class,
            $contentNode,
            $templateVars
        );
    }
653602
public function setContentType(ContentType $contentType)
    {
        $this->contentTypeName = $contentType->getName();
        $this->contentTypeId = null;

        return parent::setContentType($contentType);
    }
1127470
public function initAction(Request $request, $templateType, $contentType, $contentId = null)
    {
        $templateDomain = $this->container->get('synapse.template.domain');

        $template = empty($contentId)
            ? $templateDomain->createGlobal(
                $contentType,
                $templateType
            )
            : $templateDomain->createLocal(
                $this->container->get('synapse.content.resolver')->resolveContentId($contentType, $contentId),
                $templateType
            )
        ;

        return new RedirectResponse(empty($contentId)
            ? $this->container->get('router')->generate('synapse_admin_template_edition', array(
                'id' => $template->getId(),
            ))
            : $request->server->get('HTTP_REFERER')
        );
    }
1221692
public function moduleAsset($module, $path, $contentType = 'null')
    {
        $assetPath = base_path(Config::get('cms.module-directory').'/'.ucfirst($module).'/Assets/'.$path);

        if (!is_file($assetPath)) {
            $assetPath = config('cms.modules.'.$module.'.asset_path').'/'.$path;
        }

        return url(config('cms.backend-route-prefix', 'cms').'/asset/'.CryptoServiceFacade::url_encode($assetPath).'/'.CryptoServiceFacade::url_encode($contentType).'/?isModule=true');
    }
1277073
private function prepareFields(ApiContentType $contentType, $fields = null)
    {
        if ($fields !== null) {
            if (strpos($fields, ',') !== false) {
                return explode(',', $fields);
            }

            return array($fields);
        }

        $fields = array();
        $contentFields = $contentType->getFieldDefinitions();

        foreach ($contentFields as $field) {
            $fields[] = $field->identifier;
        }

        return $fields;
    }