Example #1
0
 /**
  * Format field
  *
  * @param Field         $field A field instance
  * @param ItemInterface $item  An entity instance
  * 
  * @return string
  */
 protected function format(Field $field, ItemInterface $item)
 {
     $name = $field->getName();
     $method = $field->getMethod();
     $value = $item->{$method}();
     if ($field->get('cdata')) {
         $value = $this->dom->createCDATASection($value);
         $element = $this->dom->createElement($name);
         $element->appendChild($value);
     } else {
         if ($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'), $item->getFeedItemLink());
         } else {
             if ($format = $field->get('date_format')) {
                 $value = $value->format($format);
             }
             $element = $this->dom->createElement($name, $value);
         }
     }
     return $element;
 }