Neos\ContentRepository\Domain\Model\AbstractNodeData::getProperty PHP Method

getProperty() public method

If the node has a content object attached, the property will be fetched there if it is gettable.
public getProperty ( string $propertyName ) : mixed
$propertyName string Name of the property
return mixed value of the property
    public function getProperty($propertyName)
    {
        if (!is_object($this->contentObjectProxy)) {
            $value = isset($this->properties[$propertyName]) ? $this->properties[$propertyName] : null;
            if (!empty($value)) {
                if ($this->getNodeType()->getPropertyType($propertyName) === 'references') {
                    if (!is_array($value)) {
                        $value = array();
                    }
                }
            }
            return $value;
        } elseif (ObjectAccess::isPropertyGettable($this->contentObjectProxy->getObject(), $propertyName)) {
            return ObjectAccess::getProperty($this->contentObjectProxy->getObject(), $propertyName);
        }
        throw new NodeException(sprintf('Property "%s" does not exist in content object of type %s.', $propertyName, get_class($this->contentObjectProxy->getObject())), 1291286995);
    }

Usage Example

 /**
  * Render a node label
  *
  * @param AbstractNodeData $nodeData
  * @param boolean $crop This argument is deprecated as of Neos 1.2 and will be removed. Don't rely on this behavior and crop labels in the view.
  * @return string
  */
 public function getLabel(AbstractNodeData $nodeData, $crop = true)
 {
     if ($nodeData->hasProperty('title') === true && $nodeData->getProperty('title') !== '') {
         $label = strip_tags($nodeData->getProperty('title'));
     } elseif ($nodeData->hasProperty('text') === true && $nodeData->getProperty('text') !== '') {
         $label = strip_tags($nodeData->getProperty('text'));
     } else {
         $label = ($nodeData->getNodeType()->getLabel() ?: $nodeData->getNodeType()->getName()) . ' (' . $nodeData->getName() . ')';
     }
     if ($crop === false) {
         return $label;
     }
     $croppedLabel = trim(Functions::substr($label, 0, 30));
     return $croppedLabel . (strlen($croppedLabel) < strlen($label) ? ' …' : '');
 }