protected static function WebformTermCheckboxes::getOptionsTree in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Element/WebformTermCheckboxes.php \Drupal\webform\Element\WebformTermCheckboxes::getOptionsTree()
Get options to term tree.
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 tree.
Overrides WebformTermReferenceTrait::getOptionsTree
File
- src/
Element/ WebformTermCheckboxes.php, line 68
Class
- WebformTermCheckboxes
- Provides a webform element for term checkboxes.
Namespace
Drupal\webform\ElementCode
protected static function getOptionsTree(array $element, $language) {
$element += [
'#tree_delimiter' => '-',
];
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
$tree = static::loadTree($element['#vocabulary']);
$options = [];
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;
}
$options[$item
->id()] = $item
->getName();
}
return $options;
}