You are here

public function EREFNodeTitles::init in Entity Reference Exposed Filters 8

Overrides \Drupal\views\Plugin\views\HandlerBase::init().

Provide some extra help to get the operator/value easier to use.

This likely has to be overridden by filters which are more complex than simple operator/value.

Overrides ManyToOne::init

File

src/Plugin/views/filter/EREFNodeTitles.php, line 141

Class

EREFNodeTitles
Filters by given list of related content title options.

Namespace

Drupal\entity_reference_exposed_filters\Plugin\views\filter

Code

public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
  parent::init($view, $display, $options);
  $this->getRelationships = $this->view
    ->getHandlers('relationship');
  if ($this->getRelationships === NULL) {
    $this->getRelationships = [];
  }

  // Check for existence of relationship and
  // Remove non-standard and non-node relationships
  // TODO Can I get the relationship type from the handler?
  $invalid_relationships = [
    'cid',
    'comment_cid',
    'last_comment_uid',
    'uid',
    'vid',
    'nid',
  ];
  foreach ($this->getRelationships as $key => $relationship) {

    // $is_node = strpos($relationship['table'], 'ode__');.
    $is_target = strpos($relationship['id'], 'target_id');
    if ($relationship['plugin_id'] != 'standard' || in_array($key, $invalid_relationships) || $is_target !== FALSE) {
      unset($this->getRelationships[$key]);
    }
  }

  // Set the sort options.
  $this->sortByOptions = [
    'nid',
    'title',
  ];
  $this->sortOrderOptions = [
    'DESC',
    'ASC',
  ];
  $this->sortBundleOrder = [
    'DESC',
    'ASC',
  ];
  $this->getUnpublishedOptions = [
    'Unpublished',
    'Published',
    'All',
  ];
  $this->getFilterNoResultsOptions = [
    'Yes',
    "No",
  ];
}