public function toDOMElement()

in src/Facebook/InstantArticles/Elements/Header.php [385:442]


    public function toDOMElement($document = null)
    {
        if (!$document) {
            $document = new \DOMDocument();
        }

        $element = $document->createElement('header');

        Element::appendChild($element, $this->cover, $document);
        Element::appendChild($element, $this->title, $document);
        Element::appendChild($element, $this->subtitle, $document);
        Element::appendChild($element, $this->published, $document);
        Element::appendChild($element, $this->modified, $document);

        if ($this->authors) {
            foreach ($this->authors as $author) {
                Element::appendChild($element, $author, $document);
            }
        }

        if ($this->kicker && $this->kicker->isValid()) {
            $kicker_element = $this->kicker->toDOMElement($document);
            $kicker_element->setAttribute('class', 'op-kicker');
            $element->appendChild($kicker_element);
        }

        if (count($this->ads) === 1) {
            $this->ads[0]->disableDefaultForReuse();
            Element::appendChild($element, $this->ads[0], $document);
        } elseif (count($this->ads) >= 2) {
            $ads_container = $document->createElement('section');
            $ads_container->setAttribute('class', 'op-ad-template');

            $default_is_set = false;
            $has_valid_ad = false;
            foreach ($this->ads as $ad) {
                if ($default_is_set) {
                    $ad->disableDefaultForReuse();
                }

                if ($ad->getIsDefaultForReuse()) {
                    $default_is_set = true;
                }

                if ($ad->isValid()) {
                    $ads_container->appendChild($ad->toDOMElement($document));
                    $has_valid_ad = true;
                }
            }
            if ($has_valid_ad) {
                $element->appendChild($ads_container);
            }
        }

        Element::appendChild($element, $this->sponsor, $document);

        return $element;
    }