You are here

ViewsMegarowTable.php in Views Megarow 8

File

src/Plugin/views/style/ViewsMegarowTable.php
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;

/**
 * The style plugin for serialized output formats.
 *
 * @ingroup views_style_plugins
 *
 * @ViewsStyle(
 *   id = "views_megarow_table",
 *   title = @Translation("Views Megarow Table"),
 *   help = @Translation("Let's you display content between two rows."),
 *   display_types = {"normal"},
 *   theme = "views_view_table",
 * )
 */
class ViewsMegarowTable extends Table {

  /**
   * {@inheritdoc}
   */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['title'] = array(
      'default' => 'Megarow',
    );
    $options['scroll'] = array(
      'default' => TRUE,
    );
    $options['autoclose'] = array(
      'default' => TRUE,
    );
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  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'],
    );
  }

  /**
   * {@inheritdoc}
   */
  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));
  }

}

Classes

Namesort descending Description
ViewsMegarowTable The style plugin for serialized output formats.