/**
  * Set parameters from post data, expects post data to be validated by
  * {@link eZNovaSeoMetasType::validateObjectAttributeHTTPInput()}
  *
  * @param eZHTTPTool               $http
  * @param string                   $base
  * @param eZContentObjectAttribute $contentObjectAttribute
  *
  * @return boolean
  */
 function fetchObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     $metas = [];
     if ($http->hasPostVariable("{$base}_data_novaseometas_{$contentObjectAttribute->attribute('contentclass_attribute_identifier')}_keyvalue_{$contentObjectAttribute->attribute('id')}")) {
         $metasKv = $http->postVariable("{$base}_data_novaseometas_{$contentObjectAttribute->attribute('contentclass_attribute_identifier')}_keyvalue_{$contentObjectAttribute->attribute('id')}");
         foreach ($metasKv as $metaKey => $metaValue) {
             $meta = new Meta();
             $meta->setName($metaKey);
             $meta->setContent($metaValue);
             $metas[] = $meta;
         }
     }
     $contentObjectAttribute->setContent(new FieldValue($metas));
     return true;
 }
Exemple #2
0
 /**
  * Converts an $hash to the Value defined by the field type
  *
  * @param mixed $hash
  *
  * @return Value
  */
 public function fromHash($hash)
 {
     if (!is_array($hash)) {
         return new Value([]);
     }
     $metas = [];
     foreach ($hash as $hashItem) {
         if (!is_array($hashItem)) {
             continue;
         }
         $meta = new Meta();
         $meta->setName($hashItem["meta_name"]);
         $meta->setContent($hashItem["meta_content"]);
         $metas[] = $meta;
     }
     return new Value($metas);
 }
 /**
  * Compute Meta by reference
  *
  * @param Content      $content
  * @param string|Field $fieldDefIdentifier
  * @param ContentType  $contentType
  * @param bool         $needFallback
  *
  * @return Meta[]
  */
 protected function innerComputeMetas(Content $content, $fieldDefIdentifier, ContentType $contentType, &$needFallback = false)
 {
     if ($fieldDefIdentifier instanceof Field) {
         $metasFieldValue = $fieldDefIdentifier->value;
         $fieldDefIdentifier = $fieldDefIdentifier->fieldDefIdentifier;
     } else {
         $metasFieldValue = $content->getFieldValue($fieldDefIdentifier);
     }
     if ($metasFieldValue instanceof MetasFieldValue) {
         $metasConfig = $this->configResolver->getParameter('fieldtype_metas', 'novae_zseo');
         // as the configuration is the last fallback we need to loop on it.
         foreach ($metasConfig as $metaName => $metasSettings) {
             if ($metasFieldValue->nameExists($metaName)) {
                 $meta = $metasFieldValue->metas[$metaName];
             } else {
                 $meta = new Meta($metaName);
                 $metasFieldValue->metas[$metaName] = $meta;
             }
             /** @var Meta $meta */
             if ($meta->isEmpty()) {
                 $meta->setContent($metasConfig[$meta->getName()]['default_pattern']);
                 $fieldDefinition = $contentType->getFieldDefinition($fieldDefIdentifier);
                 $configuration = $fieldDefinition->getFieldSettings()['configuration'];
                 // but if we need something is the configuration we take it
                 if ($configuration[$meta->getName()]) {
                     $meta->setContent($configuration[$meta->getName()]);
                 }
             }
             if (!$this->metaNameSchema->resolveMeta($meta, $content, $contentType)) {
                 $needFallback = true;
             }
         }
         return $metasFieldValue->metas;
     }
     return [];
 }
 /**
  * Resolve a Meta Value
  *
  * @param Meta        $meta
  * @param Content     $content
  * @param ContentType $contentType
  *
  * @return boolean
  */
 public function resolveMeta(Meta $meta, Content $content, ContentType $contentType = null)
 {
     $this->settings = array('limit' => $this->fieldContentMaxLength, 'sequence' => '...');
     if ($contentType === null) {
         $contentType = $this->repository->getContentTypeService()->loadContentType($content->contentInfo->contentTypeId);
     }
     $resolveMultilingue = $this->resolve($meta->getContent(), $contentType, $content->fields, $content->versionInfo->languageCodes);
     // we don't fallback on the other languages... it would be very bad for SEO to mix the languages
     if (array_key_exists($this->languages[0], $resolveMultilingue) && $resolveMultilingue[$this->languages[0]] != '') {
         $meta->setContent($resolveMultilingue[$this->languages[0]]);
         return true;
     }
     $meta->setContent("");
     return false;
 }