protected function formatMediaItemField(MediaItemField $field, ItemInterface $item)
    {
        $elements = [];

        $method = $field->getMethod();
        $values = $item->{$method}();

        if (null === $values) {
            return $elements;
        }

        if (!is_array($values) || (is_array($values) && isset($values['value']))) {
            $values = [$values];
        }

        foreach ($values as $value) {
            if (!isset($value['type']) || !isset($value['length']) || !isset($value['value'])) {
                throw new \InvalidArgumentException('Item media method must returns an array with following keys: type, length & value.');
            }

            $elementName = $field->getName();
            $elementName = $elementName[$this->getName()];

            $element = $this->dom->createElement($elementName);

            $this->addAttributes($element, $field, $item);

            switch ($this->getName()) {
                case 'rss':
                    $element->setAttribute('url', $value['value']);
                    break;

                case 'atom':
                    $element->setAttribute('rel', 'enclosure');
                    $element->setAttribute('href', $value['value']);
                    break;
            }

            $element->setAttribute('type', $value['type']);
            $element->setAttribute('length', $value['length']);

            $elements[] = $element;
        }

        return $elements;
    }