Sulu\Component\Content\Repository\Content::getPropertyWithDefault PHP Method

getPropertyWithDefault() public method

Returns value for given property or given default.
public getPropertyWithDefault ( string $name, mixed $default = null ) : mixed
$name string
$default mixed
return mixed
    public function getPropertyWithDefault($name, $default = null)
    {
        if (!array_key_exists($name, $this->data)) {
            return $default;
        }
        return $this->data[$name];
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Returns new link item.
  *
  * @param Content $content
  * @param string $locale
  * @param string $scheme
  *
  * @return LinkItem
  */
 protected function getLinkItem(Content $content, $locale, $scheme)
 {
     $published = !empty($content->getPropertyWithDefault('published'));
     $url = $this->webspaceManager->findUrlByResourceLocator($content->getUrl(), $this->environment, $locale, $content->getWebspaceKey(), null, $scheme);
     return new LinkItem($content->getId(), $content->getPropertyWithDefault('title'), $url, $published);
 }