ViewsJsonSort.php in Views Json Source 8
File
src/Plugin/views/sort/ViewsJsonSort.php
View source
<?php
namespace Drupal\views_json_source\Plugin\views\sort;
use Drupal\views\Plugin\views\sort\SortPluginBase;
use Drupal\Core\Form\FormStateInterface;
class ViewsJsonSort extends SortPluginBase {
public function defineOptions() {
$options = parent::defineOptions();
$options['key'] = [
'default' => '',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['key'] = [
'#title' => $this
->t('Key Chooser'),
'#description' => $this
->t('choose a key'),
'#type' => 'textfield',
'#default_value' => $this->options['key'],
'#required' => TRUE,
];
}
public function query() {
$this->query
->addOrderBy(NULL, $this->options['key'], $this->options['order']);
}
}