/** * {@inheritdoc} */ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { if ($match || $limit) { return parent::getReferenceableEntities($match, $match_operator, $limit); } $options = array(); $bundles = $this->entityManager->getBundleInfo('taxonomy_term'); $handler_settings = $this->configuration['handler_settings']; $bundle_names = !empty($handler_settings['target_bundles']) ? $handler_settings['target_bundles'] : array_keys($bundles); foreach ($bundle_names as $bundle) { if ($vocabulary = Vocabulary::load($bundle)) { if ($terms = $this->entityManager->getStorage('taxonomy_term')->loadTree($vocabulary->id(), 0, NULL, TRUE)) { foreach ($terms as $term) { $options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . Html::escape($term->getName()); } } } } return $options; }
/** * {@inheritdoc} */ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { // No input, return everything from the entity query. if ($match === NULL || $match === '') { return parent::getReferenceableEntities($match, $match_operator, $limit); } // Start with the selection results returned by the entity query. Don't use // any limit because we have to apply a limit after filtering the items. $options = parent::getReferenceableEntities($match, $match_operator); // Always use a case-insensitive, escaped match. Entity labels returned by // SelectionInterface::getReferenceableEntities() are already escaped, so // the incoming $match needs to be escaped as well, making the comparison // possible. // @see \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface::getReferenceableEntities() if (is_string($match)) { $match = Html::escape(Unicode::strtolower($match)); } elseif (is_array($match)) { array_walk($match, function (&$item) { $item = Html::escape(Unicode::strtolower($item)); }); } $filtered = []; $count = 0; // Filter target entities by the output of their label() method. foreach ($options as $bundle => &$items) { foreach ($items as $entity_id => $label) { if ($this->matchLabel($match, $match_operator, $label)) { $filtered[$bundle][$entity_id] = $label; $count++; if ($limit && $count >= $limit) { break 2; } } } } return $filtered; }