Eko\FeedBundle\Formatter\Formatter::formatWithOptions PHP Method

formatWithOptions() protected method

Format an item field.
protected formatWithOptions ( Eko\FeedBundle\Field\Item\ItemFieldInterface $field, Eko\FeedBundle\Item\Writer\ItemInterface $item, string $value ) : DOMElement
$field Eko\FeedBundle\Field\Item\ItemFieldInterface An item field instance
$item Eko\FeedBundle\Item\Writer\ItemInterface An entity instance
$value string A field value
return DOMElement
    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;
    }