Chris@0: [ Chris@0: 'field' => 'name', Chris@0: 'direction' => 'asc', Chris@0: ] Chris@0: ] + parent::defaultConfiguration(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function buildConfigurationForm(array $form, FormStateInterface $form_state) { Chris@0: $form = parent::buildConfigurationForm($form, $form_state); Chris@0: Chris@0: $form['target_bundles']['#title'] = $this->t('Available Vocabularies'); Chris@0: Chris@0: // Sorting is not possible for taxonomy terms because we use Chris@0: // \Drupal\taxonomy\TermStorageInterface::loadTree() to retrieve matches. Chris@0: $form['sort']['#access'] = FALSE; Chris@0: Chris@0: return $form; Chris@0: Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { Chris@0: if ($match || $limit) { Chris@0: return parent::getReferenceableEntities($match, $match_operator, $limit); Chris@0: } Chris@0: Chris@0: $options = []; Chris@0: Chris@0: $bundles = $this->entityManager->getBundleInfo('taxonomy_term'); Chris@0: $bundle_names = $this->getConfiguration()['target_bundles'] ?: array_keys($bundles); Chris@0: Chris@0: foreach ($bundle_names as $bundle) { Chris@0: if ($vocabulary = Vocabulary::load($bundle)) { Chris@0: if ($terms = $this->entityManager->getStorage('taxonomy_term')->loadTree($vocabulary->id(), 0, NULL, TRUE)) { Chris@0: foreach ($terms as $term) { Chris@0: $options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . Html::escape($this->entityManager->getTranslationFromContext($term)->label()); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: return $options; Chris@0: } Chris@0: Chris@0: }