ViewsBootstrapCards.php in Views Bootstrap 8.4
File
src/Plugin/views/style/ViewsBootstrapCards.php
View source
<?php
namespace Drupal\views_bootstrap\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\style\StylePluginBase;
class ViewsBootstrapCards extends StylePluginBase {
protected $usesFields = TRUE;
protected $usesRowPlugin = TRUE;
protected function defineOptions() {
$options = parent::defineOptions();
$options['card_title_field'] = [
'default' => NULL,
];
$options['card_content_field'] = [
'default' => NULL,
];
$options['card_image_field'] = [
'default' => NULL,
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
if (isset($form['grouping'])) {
unset($form['grouping']);
$form['card_title_field'] = [
'#type' => 'select',
'#title' => $this
->t('Card title field'),
'#options' => $this->displayHandler
->getFieldLabels(TRUE),
'#required' => TRUE,
'#default_value' => $this->options['card_title_field'],
'#description' => $this
->t('Select the field that will be used for the card title.'),
];
$form['card_content_field'] = [
'#type' => 'select',
'#title' => $this
->t('Card content field'),
'#options' => $this->displayHandler
->getFieldLabels(TRUE),
'#required' => TRUE,
'#default_value' => $this->options['card_content_field'],
'#description' => $this
->t('Select the field that will be used for the card content.'),
];
$form['card_image_field'] = [
'#type' => 'select',
'#title' => $this
->t('Card image field'),
'#options' => $this->displayHandler
->getFieldLabels(TRUE),
'#required' => TRUE,
'#default_value' => $this->options['card_image_field'],
'#description' => $this
->t('Select the field that will be used for the card image.'),
];
}
}
}