You are here

public function ViewsSimpleMathFieldSort::postExecute in Views Simple Math Field 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/sort/ViewsSimpleMathFieldSort.php \Drupal\views_simple_math_field\Plugin\views\sort\ViewsSimpleMathFieldSort::postExecute()

Run after the view is executed, before the result is cached.

This gives all the handlers some time to modify values. This is primarily used so that handlers that pull up secondary data can put it in the $values so that the raw data can be used externally.

Overrides HandlerBase::postExecute

File

src/Plugin/views/sort/ViewsSimpleMathFieldSort.php, line 32

Class

ViewsSimpleMathFieldSort
Handler which sort by the similarity.

Namespace

Drupal\views_simple_math_field\Plugin\views\sort

Code

public function postExecute(&$values) {
  $view = $this->view;
  $order = $this->options['order'];
  foreach ($this->view->result as $result) {
    $sm_field = $view->field[$this->options['simple']]
      ->getValue($result);
    $this->view->result[$result->index]->{$this->options['simple']} = $sm_field;
  }
  if ($order === 'ASC') {
    usort($this->view->result, function ($item1, $item2) {
      return $item1->{$this->options['simple']} <=> $item2->{$this->options['simple']};
    });
  }
  else {
    usort($this->view->result, function ($item1, $item2) {
      return $item2->{$this->options['simple']} <=> $item1->{$this->options['simple']};
    });
  }
}