/**
  * @param \eZ\Publish\Core\FieldType\Selection\Value $value
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition
  * @param string $languageCode
  *
  * @return string
  */
 public function getFieldName(SPIValue $value, FieldDefinition $fieldDefinition, $languageCode)
 {
     if (empty($value->selection)) {
         return '';
     }
     $names = [];
     $fieldSettings = $fieldDefinition->getFieldSettings();
     foreach ($value->selection as $optionIndex) {
         if (isset($fieldSettings['options'][$optionIndex])) {
             $names[] = $fieldSettings['options'][$optionIndex];
         }
     }
     return implode(' ', $names);
 }
 /**
  * Renders the HTML for the settings for the given field definition
  * $definition
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $definition
  * @return string
  */
 public function renderFieldDefinitionSettings(FieldDefinition $definition)
 {
     if (!$this->template instanceof Twig_Template) {
         $tpl = reset($this->renderFieldDefinitionSettingsResources);
         $this->template = $this->environment->loadTemplate($tpl['template']);
     }
     $parameters = array('fielddefinition' => $definition, 'settings' => $definition->getFieldSettings());
     return $this->template->renderBlock($this->getRenderFieldDefinitionSettingsBlockName($definition), $parameters, $this->getBlockByFieldDefinition($definition));
 }
示例#3
0
 /**
  * Validates field value against 'isMultiple' setting.
  *
  * Does not use validators.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field
  * @param \eZ\Publish\Core\FieldType\Country\Value $fieldValue The field value for which an action is performed
  *
  * @return \eZ\Publish\SPI\FieldType\ValidationError[]
  */
 public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue)
 {
     $validationErrors = array();
     if ($this->isEmptyValue($fieldValue)) {
         return $validationErrors;
     }
     $fieldSettings = $fieldDefinition->getFieldSettings();
     if ((!isset($fieldSettings["isMultiple"]) || $fieldSettings["isMultiple"] === false) && count($fieldValue->countries) > 1) {
         $validationErrors[] = new ValidationError("Field definition does not allow multiple countries to be selected.", null, array());
     }
     foreach ($fieldValue->countries as $alpha2 => $countryInfo) {
         if (!isset($this->countriesInfo[$alpha2])) {
             $validationErrors[] = new ValidationError("Country with Alpha2 code '%alpha2%' is not defined in FieldType settings.", null, array("alpha2" => $alpha2));
         }
     }
     return $validationErrors;
 }
示例#4
0
 /**
  * Validates field value against 'isMultiple' and 'options' settings.
  *
  * Does not use validators.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field
  * @param \eZ\Publish\Core\FieldType\Selection\Value $fieldValue The field value for which an action is performed
  *
  * @return \eZ\Publish\SPI\FieldType\ValidationError[]
  */
 public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue)
 {
     $validationErrors = array();
     if ($this->isEmptyValue($fieldValue)) {
         return $validationErrors;
     }
     $fieldSettings = $fieldDefinition->getFieldSettings();
     if ((!isset($fieldSettings['isMultiple']) || $fieldSettings['isMultiple'] === false) && count($fieldValue->selection) > 1) {
         $validationErrors[] = new ValidationError('Field definition does not allow multiple options to be selected.', null, array(), 'selection');
     }
     foreach ($fieldValue->selection as $optionIndex) {
         if (!isset($fieldSettings['options'][$optionIndex])) {
             $validationErrors[] = new ValidationError('Option with index %index% does not exist in the field definition.', null, array('%index%' => $optionIndex), 'selection');
         }
     }
     return $validationErrors;
 }
 /**
  * @param FieldDefinition $fieldDefinition
  * @param array $params
  * @param int $type Either self::VIEW or self::EDIT
  *
  * @return string
  */
 private function renderFieldDefinition(FieldDefinition $fieldDefinition, array $params, $type)
 {
     if (is_string($this->baseTemplate)) {
         $this->baseTemplate = $this->twig->loadTemplate($this->baseTemplate);
     }
     $params += ['fielddefinition' => $fieldDefinition, 'settings' => $fieldDefinition->getFieldSettings()];
     return $this->baseTemplate->renderBlock($this->getRenderFieldDefinitionBlockName($fieldDefinition->fieldTypeIdentifier, $type), $this->twig->mergeGlobals($params), $this->getBlocksByFieldDefinition($fieldDefinition, $type));
 }
示例#6
0
 /**
  * Validates a field based on the validators in the field definition
  *
  * Does not use validators.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field
  * @param \eZ\Publish\Core\FieldType\ISBN\Value $fieldValue The field value for which an action is performed
  *
  * @return \eZ\Publish\SPI\FieldType\ValidationError[]
  */
 public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue)
 {
     $validationErrors = array();
     if ($this->isEmptyValue($fieldValue)) {
         return $validationErrors;
     }
     $fieldSettings = $fieldDefinition->getFieldSettings();
     $isbnTestNumber = preg_replace("/[\\s|\\-]/", "", trim($fieldValue->isbn));
     // Check if value and settings are inline
     if ((!isset($fieldSettings["isISBN13"]) || $fieldSettings["isISBN13"] === false) && strlen($isbnTestNumber) !== 10) {
         $validationErrors[] = new ValidationError("ISBN-10 must be 10 character length", null, array());
     } else {
         if (strlen($isbnTestNumber) === 10) {
             if (!$this->validateISBNChecksum($isbnTestNumber)) {
                 $validationErrors[] = new ValidationError("ISBN value must be in a valid ISBN-10 format", null, array());
             }
         } else {
             if (!$this->validateISBN13Checksum($isbnTestNumber, $error)) {
                 $validationErrors[] = new ValidationError($error, null, array());
             }
         }
     }
     return $validationErrors;
 }