View source
<?php
namespace Drupal\views_megarow\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\style\Table;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
class ViewsMegarowTable extends Table {
protected function defineOptions() {
$options = parent::defineOptions();
$options['title'] = array(
'default' => 'Megarow',
);
$options['scroll'] = array(
'default' => TRUE,
);
$options['autoclose'] = array(
'default' => TRUE,
);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['views_megarow'] = array(
'#type' => 'details',
'#title' => t('Views Megarow settings'),
'#open' => TRUE,
);
$form['views_megarow']['title'] = array(
'#type' => 'textfield',
'#title' => t('Megarow title'),
'#description' => t('Value to display as the title of the row when opened.'),
'#default_value' => $this->options['views_megarow']['title'],
);
$form['views_megarow']['scroll'] = array(
'#type' => 'checkbox',
'#title' => t('Enable scroll'),
'#description' => t('When a row is opened, scroll to have the opened row at the top of the page.'),
'#default_value' => $this->options['views_megarow']['scroll'],
);
$form['views_megarow']['autoclose'] = array(
'#type' => 'checkbox',
'#title' => t('Automatically close the row'),
'#description' => t('When a row is opened and a form submitted, automatically close the row.'),
'#default_value' => $this->options['views_megarow']['autoclose'],
);
}
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
$formats = $form_state
->getValue(array(
'style_options',
'views_megarow',
));
$form_state
->setValue(array(
'style_options',
'views_megarow',
), array_filter($formats));
}
}