Sulu\Bundle\PreviewBundle\Preview\RdfaExtractor::getPropertyValue PHP Method

getPropertyValue() public method

Returns html and attributes value of rdfa property.
public getPropertyValue ( string $property ) : boolean
$property string Could be a property sequence like (block[1].title[0])
return boolean
    public function getPropertyValue($property)
    {
        $nodes = $this->crawler;
        $before = '';
        $path = new PropertyPath($property);
        if (1 < $path->getLength()) {
            foreach ($path as $item) {
                // is not integer
                if (!ctype_digit(strval($item))) {
                    $before = $item;
                    $nodes = $nodes->filter('*[property="' . $item . '"]');
                } else {
                    $nodes = $nodes->filter('*[rel="' . $before . '"]')->eq($item);
                }
            }
        } else {
            // FIXME it is a bit complex but there is no :not operator in crawler
            // should be *[property="block"]:not(*[property] *)
            $nodes = $nodes->filter('*[property="' . $property . '"]')->reduce(function (Crawler $node) {
                // get parents
                $parents = $node->parents();
                $count = 0;
                // check if one parent is property exclude it
                $parents->each(function ($node) use(&$count) {
                    if (null !== $node->attr('property') && $node->attr('typeof') === 'collection') {
                        ++$count;
                    }
                });
                return $count === 0;
            });
        }
        // if rdfa property not found return false
        if ($nodes->count() > 0) {
            // create an array of changes
            return $nodes->each(function (Crawler $crawlerNode) {
                $node = $crawlerNode->getNode(0);
                $attributes = [];
                foreach ($node->attributes as $name => $value) {
                    $attributes[$name] = $value->nodeValue;
                }
                $attributes['html'] = $crawlerNode->html();
                return $attributes;
            });
        }
        return false;
    }