You are here

protected function ViewsSelection::stripAdminAndAnchorTagsFromResults in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php \Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection::stripAdminAndAnchorTagsFromResults()
  2. 10 core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php \Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection::stripAdminAndAnchorTagsFromResults()

Strips all admin and anchor tags from a result list.

These results are usually displayed in an autocomplete field, which is surrounded by anchor tags. Most tags are allowed inside anchor tags, except for other anchor tags.

Parameters

array $results: The result list.

Return value

array The provided result list with anchor tags removed.

1 call to ViewsSelection::stripAdminAndAnchorTagsFromResults()
ViewsSelection::getReferenceableEntities in core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
Gets the list of referenceable entities.

File

core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php, line 289

Class

ViewsSelection
Plugin implementation of the 'selection' entity_reference.

Namespace

Drupal\views\Plugin\EntityReferenceSelection

Code

protected function stripAdminAndAnchorTagsFromResults(array $results) {
  $allowed_tags = Xss::getAdminTagList();
  if (($key = array_search('a', $allowed_tags)) !== FALSE) {
    unset($allowed_tags[$key]);
  }
  $stripped_results = [];
  foreach ($results as $id => $row) {
    $entity = $row['#row']->_entity;
    $stripped_results[$entity
      ->bundle()][$id] = ViewsRenderPipelineMarkup::create(Xss::filter($this->renderer
      ->renderPlain($row), $allowed_tags));
  }
  return $stripped_results;
}