protected static function WebformTermReferenceTrait::getOptionsBreadcrumb in Webform 8.5
Same name and namespace in other branches
- 6.x src/Element/WebformTermReferenceTrait.php \Drupal\webform\Element\WebformTermReferenceTrait::getOptionsBreadcrumb()
Get options to term breadcrumb.
Parameters
array $element: The term reference element.
string $language: The language to be displayed.
Return value
array An associative array of term options formatted as a breadcrumbs.
1 call to WebformTermReferenceTrait::getOptionsBreadcrumb()
- WebformTermReferenceTrait::setOptions in src/
Element/ WebformTermReferenceTrait.php - Set referencable term entities as options for an element.
File
- src/
Element/ WebformTermReferenceTrait.php, line 52
Class
- WebformTermReferenceTrait
- Trait for term reference elements.
Namespace
Drupal\webform\ElementCode
protected static function getOptionsBreadcrumb(array $element, $language) {
$element += [
'#breadcrumb_delimiter' => ' › ',
];
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
$tree = static::loadTree($element['#vocabulary']);
$options = [];
$breadcrumb = [];
foreach ($tree as $item) {
// Set the item in the correct language for display.
$item = $entity_repository
->getTranslationFromContext($item);
if (!$item
->access('view')) {
continue;
}
// Check depth.
if (!empty($element['#depth']) && $item->depth >= $element['#depth']) {
continue;
}
$breadcrumb[$item->depth] = $item
->getName();
$breadcrumb = array_slice($breadcrumb, 0, $item->depth + 1);
$options[$item
->id()] = implode($element['#breadcrumb_delimiter'], $breadcrumb);
}
return $options;
}