function ViewsPhp::phpClickSort in Views PHP 8
Helper function; usort() callback for click sort support.
File
- src/
Plugin/ views/ field/ ViewsPhp.php, line 226 - Contains \Drupal\views_php\Plugin\views\field\ViewsPhp.
Class
- ViewsPhp
- A handler to provide a field that is constructed by the administrator using PHP.
Namespace
Drupal\views_php\Plugin\views\fieldCode
function phpClickSort($row1, $row2) {
$factor = strtoupper($this->php_click_sort_order) == 'ASC' ? 1 : -1;
$function = $this->php_click_sort_function;
if ($this->options['use_php_click_sortable'] == self::CLICK_SORT_PHP) {
foreach (array(
'row1' => 'normalized_row1',
'row2' => 'normalized_row2',
) as $name => $normalized_name) {
${$normalized_name} = new ViewsPhpNormalizedRow();
foreach ($this->view->display_handler
->getHandlers('field') as $field => $handler) {
${$normalized_name}->{$field} = isset(${$name}->{$handler->field_alias}) ? ${$name}->{$handler->field_alias} : NULL;
}
}
ob_start();
$result = (int) $function($this->view, $this, $this->php_static_variable, $normalized_row1, $normalized_row2);
ob_end_clean();
}
else {
$result = $function($row1->{$this->field_alias}, $row2->{$this->field_alias});
}
return $factor * $result;
}