You are here

public function EntityReferenceFilterViewResult::getConfiguredViewsOptions in Views Reference Filter 8

Returns options for the selected filter.

Return value

array Options list.

1 call to EntityReferenceFilterViewResult::getConfiguredViewsOptions()
EntityReferenceFilterViewResult::getValueOptions in src/Plugin/views/filter/EntityReferenceFilterViewResult.php
Child classes should be used to override this function and set the 'value options', unless 'options callback' is defined as a valid function or static public method to generate these values.

File

src/Plugin/views/filter/EntityReferenceFilterViewResult.php, line 202

Class

EntityReferenceFilterViewResult
Filter by entity id using items got from the another view..

Namespace

Drupal\entityreference_filter\Plugin\views\filter

Code

public function getConfiguredViewsOptions() {
  $options = [];
  if (empty($this->options['reference_display'])) {
    return [];
  }
  [
    $view_name,
    $display_id,
  ] = explode(':', $this->options['reference_display']);
  $view = Views::getView($view_name);
  if (!$view || !$view
    ->access($display_id)) {
    $this->loggerChannel
      ->warning('The view %view_name is no longer eligible for the filter.', [
      '%view_name' => $view_name,
    ]);
    return $options;
  }
  if ($view instanceof ViewExecutable) {
    $args = $this
      ->getFilterArgs();
    $view
      ->setDisplay($display_id);
    $view
      ->setItemsPerPage(0);

    // Set `entity_reference_options` for the new EntityReference view display implementation.
    $entity_reference_options = [
      'limit' => NULL,
    ];
    $view->displayHandlers
      ->get($display_id)
      ->setOption('entity_reference_options', $entity_reference_options);
    $results = $view
      ->executeDisplay($display_id, $args);
    foreach ($results as $renderable) {
      $entity = $renderable["#row"]->_entity;
      $render = $this
        ->getRenderer();
      $option = $render
        ->renderPlain($renderable);
      $options[$entity
        ->id()] = strip_tags($option);
    }
  }
  return $options;
}