You are here

public static function WebformTermReferenceTrait::setOptions in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformTermReferenceTrait.php \Drupal\webform\Element\WebformTermReferenceTrait::setOptions()

Set referencable term entities as options for an element.

Parameters

array $element: An element.

2 calls to WebformTermReferenceTrait::setOptions()
WebformTermCheckboxes::processCheckboxes in src/Element/WebformTermCheckboxes.php
Processes a checkboxes form element.
WebformTermSelect::processSelect in src/Element/WebformTermSelect.php
Processes a select list form element.

File

src/Element/WebformTermReferenceTrait.php, line 16

Class

WebformTermReferenceTrait
Trait for term reference elements.

Namespace

Drupal\webform\Element

Code

public static function setOptions(array &$element) {
  $language = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  if (!empty($element['#options'])) {
    return;
  }
  if (!\Drupal::moduleHandler()
    ->moduleExists('taxonomy') || empty($element['#vocabulary'])) {
    $element['#options'] = [];
    return;
  }
  if (!empty($element['#breadcrumb'])) {
    $element['#options'] = static::getOptionsBreadcrumb($element, $language);
  }
  else {
    $element['#options'] = static::getOptionsTree($element, $language);
  }

  // Add the vocabulary to the cache tags.
  // Issue #2920913: The taxonomy_term_list cache should be invalidated
  // on a vocabulary-by-vocabulary basis.
  // @see https://www.drupal.org/project/drupal/issues/2920913
  $element['#cache']['tags'][] = 'taxonomy_term_list';
}