eZ\Publish\Core\FieldType\RichText\Type::getRelatedObjectIds PHP Method

getRelatedObjectIds() protected method

protected getRelatedObjectIds ( Value $fieldValue, $relationType )
$fieldValue Value
    protected function getRelatedObjectIds(Value $fieldValue, $relationType)
    {
        if ($relationType === Relation::EMBED) {
            $tagNames = ['ezembedinline', 'ezembed'];
        } else {
            $tagNames = ['link', 'ezlink'];
        }
        $contentIds = array();
        $locationIds = array();
        $xpath = new \DOMXPath($fieldValue->xml);
        $xpath->registerNamespace('docbook', 'http://docbook.org/ns/docbook');
        foreach ($tagNames as $tagName) {
            $xpathExpression = "//docbook:{$tagName}[starts-with( @xlink:href, 'ezcontent://' ) or starts-with( @xlink:href, 'ezlocation://' )]";
            /** @var \DOMElement $element */
            foreach ($xpath->query($xpathExpression) as $element) {
                preg_match('~^(.+)://([^#]*)?(#.*|\\s*)?$~', $element->getAttribute('xlink:href'), $matches);
                list(, $scheme, $id) = $matches;
                if (empty($id)) {
                    continue;
                }
                if ($scheme === 'ezcontent') {
                    $contentIds[] = $id;
                } elseif ($scheme === 'ezlocation') {
                    $locationIds[] = $id;
                }
            }
        }
        return array('locationIds' => array_unique($locationIds), 'contentIds' => array_unique($contentIds));
    }