protected function formatWithOptions(ItemFieldInterface $field, ItemInterface $item, $value)
{
$element = null;
$name = $field->getName();
if ($field->get('translatable')) {
$value = $this->translate($value);
}
if ($field->get('cdata')) {
$value = $this->dom->createCDATASection($value);
$element = $this->dom->createElement($name);
$element->appendChild($value);
} elseif ($field->get('attribute')) {
if (!$field->get('attribute_name')) {
throw new \InvalidArgumentException("'attribute' parameter required an 'attribute_name' parameter.");
}
$element = $this->dom->createElement($name);
$element->setAttribute($field->get('attribute_name'), $value);
} else {
if ($format = $field->get('date_format')) {
if (!$value instanceof \DateTime) {
throw new \InvalidArgumentException(sprintf('Field "%s" should be a DateTime instance.', $name));
}
$value = $value->format($format);
}
$element = $this->dom->createElement($name, htmlspecialchars($value));
}
$this->addAttributes($element, $field, $item);
return $element;
}