View source
<?php
namespace Drupal\views_bootstrap\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\style\StylePluginBase;
class ViewsBootstrapPanel extends StylePluginBase {
protected $usesFields = TRUE;
protected $usesRowPlugin = TRUE;
protected function defineOptions() {
$options = parent::defineOptions();
$options['panel_title_field'] = [
'default' => NULL,
];
$options['panel_label_field'] = [
'default' => NULL,
];
$options['panel_footer_field'] = [
'default' => NULL,
];
$options['contextual_class'] = [
'default' => 'panel-default',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['help'] = [
'#markup' => $this
->t('The Bootstrap panels displays content in a box with optional header and footer elements (<a href=":docs">see documentation</a>).', [
':docs' => 'https://www.drupal.org/docs/contributed-modules/views-bootstrap-for-bootstrap-3/panels',
]),
'#weight' => -99,
];
$form['contextual_class'] = [
'#type' => 'radios',
'#title' => $this
->t('Contextual class'),
'#options' => [
'panel-default' => $this
->t('Default'),
'panel-primary' => $this
->t('Primary'),
'panel-success' => $this
->t('Success'),
'panel-info' => $this
->t('Info'),
'panel-warning' => $this
->t('Warning'),
'panel-danger' => $this
->t('Danger'),
],
'#default_value' => $this->options['contextual_class'],
'#description' => $this
->t('<a href=":docs">see Bootstrap documentation</a>', [
':docs' => 'https://getbootstrap.com/docs/3.4/components/#panels-alternatives',
]),
];
$form['panel_title_field'] = [
'#type' => 'select',
'#title' => $this
->t('Panel title field'),
'#options' => [
'' => $this
->t('- None -'),
] + $this->displayHandler
->getFieldLabels(TRUE),
'#default_value' => $this->options['panel_title_field'],
'#description' => $this
->t('Select the field that will be used as the panel heading titles.'),
];
$form['panel_label_field'] = [
'#type' => 'select',
'#title' => $this
->t('Label field'),
'#options' => [
'' => $this
->t('- None -'),
] + $this->displayHandler
->getFieldLabels(TRUE),
'#required' => FALSE,
'#default_value' => $this->options['label_field'],
'#description' => $this
->t('Select the field that will be used as the label.'),
];
$form['panel_footer_field'] = [
'#type' => 'select',
'#title' => $this
->t('Panel footer field'),
'#options' => [
'' => $this
->t('- None -'),
] + $this->displayHandler
->getFieldLabels(TRUE),
'#default_value' => $this->options['panel_title_field'],
'#description' => $this
->t('Select the field that will be used as the panel footer.'),
];
}
}