AjaxHistory.php in Views AJAX History 8
File
src/Plugin/views/display_extender/AjaxHistory.php
View source
<?php
namespace Drupal\views_ajax_history\Plugin\views\display_extender;
use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase;
use Drupal\Core\Form\FormStateInterface;
class AjaxHistory extends DisplayExtenderPluginBase {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
if ($form_state
->get('section') == 'use_ajax') {
$form['enable_history'] = [
'#title' => $this
->t('AJAX history'),
'#type' => 'checkbox',
'#description' => $this
->t('Enable Views AJAX history.'),
'#default_value' => isset($this->options['enable_history']) ? $this->options['enable_history'] : 0,
'#states' => [
'visible' => [
':input[name="use_ajax"]' => [
'checked' => TRUE,
],
],
],
];
}
}
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
if ($form_state
->hasValue('use_ajax') && $form_state
->getValue('use_ajax') != TRUE) {
$form_state
->setValue('enable_history', FALSE);
}
}
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
if ($form_state
->get('section') == 'use_ajax') {
$this->options['enable_history'] = $form_state
->getValue('enable_history');
}
}
}