/**
  * @param ContentTypeInterface           $value
  * @param UniqueContentTypeId|Constraint $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     $result = $this->repository->findOneByContentTypeIdInLastVersion($value->getContentTypeId());
     if (null !== $result && $value->getVersion() <= 1) {
         $this->context->buildViolation($constraint->message)->atPath('contentTypeId')->addViolation();
     }
 }
 /**
  * @param ContentInterface $content
  *
  * @return array
  */
 protected function extractMediasFromContentType(ContentTypeInterface $contentType)
 {
     $mediaIds = array();
     $fields = $contentType->getFields();
     foreach ($fields as $field) {
         if ($this->isMediaAttribute($field->getDefaultValue())) {
             $mediaIds[] = $field->getDefaultValue()['id'];
         }
     }
     return $mediaIds;
 }
 /**
  * @param ContentTypeInterface                $value
  * @param UniqueFieldIdContentType|Constraint $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     $fields = $value->getFields();
     $fieldsId = array();
     foreach ($fields as $field) {
         $fieldId = $field->getFieldId();
         if (in_array($fieldId, $fieldsId)) {
             $this->context->buildViolation($constraint->message)->atPath("fields")->addViolation();
         }
         $fieldsId[] = $fieldId;
     }
 }
 /**
  * @param ContentTypeInterface $contentType
  *
  * @return ContentTypeInterface
  */
 public function duplicate(ContentTypeInterface $contentType)
 {
     $newContentType = clone $contentType;
     foreach ($contentType->getFields() as $field) {
         $newField = clone $field;
         foreach ($field->getOptions() as $option) {
             $newOption = clone $option;
             $newField->addOption($newOption);
         }
         $newContentType->addFieldType($newField);
     }
     return $newContentType;
 }
 /**
  * @param ContentInterface $content
  *
  * @return array
  */
 protected function extractKeywordsFromContentType(ContentTypeInterface $contentType)
 {
     $keywordIds = array();
     $fields = $contentType->getFields();
     foreach ($fields as $field) {
         $fieldOptions = $field->getOptions();
         foreach ($fieldOptions as $option) {
             if ($this->isKeywordsConditionAttribute($option->getValue())) {
                 $keywordIds = array_merge($keywordIds, $this->extractKeywordIdsFromConditionAttribute($option->getValue()));
             }
         }
     }
     return $keywordIds;
 }
 /**
  * Create a elasticSearch linked to the object
  *
  * @param null|ContentTypeInterface $contentType
  */
 public function createMapping($contentType)
 {
     $index = $this->client->getIndex($this->indexName);
     $type = $index->getType(self::INDEX_TYPE . $contentType->getContentTypeId());
     $mappingProperties = array('id' => array('type' => 'string', 'include_in_all' => true), 'elementId' => array('type' => 'string', 'include_in_all' => true), 'contentId' => array('type' => 'string', 'include_in_all' => true), 'name' => array('type' => 'string', 'include_in_all' => true), 'siteId' => array('type' => 'string', 'include_in_all' => true), 'linkedToSite' => array('type' => 'boolean', 'include_in_all' => false), 'language' => array('type' => 'string', 'include_in_all' => true), 'contentType' => array('type' => 'string', 'include_in_all' => true), 'keywords' => array('type' => 'string', 'include_in_all' => true), 'updatedAt' => array('type' => 'long', 'include_in_all' => false));
     /** @var FieldTypeInterface $field */
     foreach ($contentType->getFields() as $field) {
         if ($field->isSearchable()) {
             $mappingProperties['attribute_' . $field->getFieldId()] = array('type' => $this->formMapper->map($field->getType()), 'include_in_all' => false);
             $mappingProperties['attribute_' . $field->getFieldId() . '_stringValue'] = array('type' => 'string', 'include_in_all' => true);
         }
     }
     $mapping = $this->mappingFactory->create($type);
     $mapping->setProperties($mappingProperties);
     $mapping->send();
 }
 /**
  * @param ContentTypeInterface $contentType
  *
  * @return FacadeInterface
  *
  * @throws TransformerParameterTypeException
  */
 public function transform($contentType)
 {
     if (!$contentType instanceof ContentTypeInterface) {
         throw new TransformerParameterTypeException();
     }
     $facade = $this->newFacade();
     $facade->id = $contentType->getId();
     $facade->contentTypeId = $contentType->getContentTypeId();
     $facade->name = $this->multiLanguagesChoiceManager->choose($contentType->getNames());
     $facade->version = $contentType->getVersion();
     $facade->linkedToSite = $contentType->isLinkedToSite();
     if ($this->hasGroup(CMSGroupContext::FIELD_TYPES)) {
         foreach ($contentType->getFields() as $field) {
             $facade->addField($this->getTransformer('field_type')->transform($field));
         }
     }
     $facade->addLink('_self', $this->generateRoute('open_orchestra_api_content_type_show', array('contentTypeId' => $contentType->getContentTypeId())));
     if (0 == $this->contentRepository->countByContentType($contentType->getContentTypeId()) && $this->authorizationChecker->isGranted(AdministrationPanelStrategy::ROLE_ACCESS_DELETE_CONTENT_TYPE)) {
         $facade->addLink('_self_delete', $this->generateRoute('open_orchestra_api_content_type_delete', array('contentTypeId' => $contentType->getContentTypeId())));
     }
     if ($this->authorizationChecker->isGranted(AdministrationPanelStrategy::ROLE_ACCESS_UPDATE_CONTENT_TYPE)) {
         $facade->addLink('_self_form', $this->generateRoute('open_orchestra_backoffice_content_type_form', array('contentTypeId' => $contentType->getContentTypeId())));
     }
     return $facade;
 }
 /**
  * @param string               $message
  * @param ContentTypeInterface $contentType
  */
 protected function sendLog($message, ContentTypeInterface $contentType)
 {
     $this->logger->info($message, array('content_type_id' => $contentType->getContentTypeId(), 'content_type_name' => $contentType->getName($this->context->getCurrentLocale())));
 }