/** * Validates a field based on the validators in the field definition. * * This is a base implementation, returning an empty array() that indicates * that no validation errors occurred. Overwrite in derived types, if * validation is supported. * * @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\RichText\Value $value The field value for which an action is performed * * @return \eZ\Publish\SPI\FieldType\ValidationError[] */ public function validate(FieldDefinition $fieldDefinition, SPIValue $value) { $validationErrors = array(); $errors = $this->internalFormatValidator->validate($value->xml); if (!empty($errors)) { $validationErrors[] = new ValidationError("Validation of XML content failed:\n" . implode("\n", $errors)); } return $validationErrors; }
/** * Inspects given $inputValue and potentially converts it into a dedicated value object. * * @param \eZ\Publish\Core\FieldType\RichText\Value|\DOMDocument|string $inputValue * * @return \eZ\Publish\Core\FieldType\RichText\Value The potentially converted and structurally plausible value. */ protected function createValueFromInput($inputValue) { if (is_string($inputValue)) { if (empty($inputValue)) { $inputValue = Value::EMPTY_VALUE; } $inputValue = $this->loadXMLString($inputValue); } if ($inputValue instanceof DOMDocument) { $errors = $this->validatorDispatcher->dispatch($inputValue); if (!empty($errors)) { throw new InvalidArgumentException("\$inputValue", "Validation of XML content failed: " . join("\n", $errors)); } $inputValue = $this->inputConverterDispatcher->dispatch($inputValue); $errors = $this->validatorDispatcher->dispatch($inputValue); if (!empty($errors)) { throw new InvalidArgumentException("\$inputValue", "Validation of XML content failed: " . join("\n", $errors)); } $inputValue = new Value($inputValue); } return $inputValue; }