protected function MenuLinkField::getProperty in Menu Link (Field) 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Menu/MenuLinkField.php \Drupal\menu_link\Plugin\Menu\MenuLinkField::getProperty()
Gets a specific property.
In case the underlying entity is translatable, we watch the translated value.
Parameters
string $property: Gets a specific property from the field, like title or weight.
Return value
mixed The Property.
3 calls to MenuLinkField::getProperty()
- MenuLinkField::getDescription in src/Plugin/ Menu/ MenuLinkField.php 
- Returns the description of the menu link.
- MenuLinkField::getTitle in src/Plugin/ Menu/ MenuLinkField.php 
- Returns the localized title to be shown for this link.
- MenuLinkField::getWeight in src/Plugin/ Menu/ MenuLinkField.php 
- Returns the weight of the menu link.
File
- src/Plugin/ Menu/ MenuLinkField.php, line 112 
Class
- MenuLinkField
- Provides a menu link plugin for field-based menu links.
Namespace
Drupal\menu_link\Plugin\MenuCode
protected function getProperty($property) {
  // We only need to get the property from the actual entity if it may be a
  // translation based on the current language context. This can only happen
  // if the site is configured to be multilingual.
  if (!empty($this->pluginDefinition['metadata']['translatable']) && $this->languageManager
    ->isMultilingual()) {
    /** @var \Drupal\Core\TypedData\TranslatableInterface|\Drupal\Core\Entity\EntityInterface $entity */
    $entity = $this
      ->getEntity();
    $field_name = $this
      ->getFieldName();
    if ($property_value = $entity
      ->get($field_name)->{$property}) {
      return $property_value;
    }
    return $entity
      ->label();
  }
  return $this->pluginDefinition[$property];
}