public function WebformTermReferenceTrait::preview in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/WebformTermReferenceTrait.php \Drupal\webform\Plugin\WebformElement\WebformTermReferenceTrait::preview()
Overrides WebformEntityReferenceTrait::preview
File
- src/
Plugin/ WebformElement/ WebformTermReferenceTrait.php, line 26
Class
- WebformTermReferenceTrait
- Provides an 'term_reference' trait.
Namespace
Drupal\webform\Plugin\WebformElementCode
public function preview() {
if ($vocabularies = Vocabulary::loadMultiple()) {
$vocabulary = reset($vocabularies);
$vocabulary_id = $vocabulary
->id();
}
else {
$vocabulary_id = 'tags';
}
// Make sure the vocabulary does not have more than 250 terms.
// This will prevent a fatal memory error when
// previewing term related elements.
/** @var \Drupal\taxonomy\TermStorageInterface $taxonomy_storage */
$taxonomy_storage = $this->entityTypeManager
->getStorage('taxonomy_term');
$tree = $taxonomy_storage
->loadTree($vocabulary_id);
if (count($tree) > 250) {
$vocabulary_id = NULL;
}
return parent::preview() + [
'#vocabulary' => $vocabulary_id,
];
}