You are here

class FooTable in FooTable 8.2

Same name in this branch
  1. 8.2 src/FooTable.php \Drupal\footable\FooTable
  2. 8.2 src/Element/FooTable.php \Drupal\footable\Element\FooTable
  3. 8.2 src/Plugin/views/style/FooTable.php \Drupal\footable\Plugin\views\style\FooTable

Provides a render element for a FooTable.

Plugin annotation

@FormElement("footable");

Hierarchy

Expanded class hierarchy of FooTable

3 string references to 'FooTable'
footable.info.yml in ./footable.info.yml
footable.info.yml
footable.links.menu.yml in ./footable.links.menu.yml
footable.links.menu.yml
footable.routing.yml in ./footable.routing.yml
footable.routing.yml

File

src/Element/FooTable.php, line 15

Namespace

Drupal\footable\Element
View source
class FooTable extends Table {

  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    $info = parent::getInfo();
    $class = get_class($this);
    $info['#process'][] = [
      $class,
      'processFooTable',
    ];
    $info['#pre_render'][] = [
      $class,
      'preRenderFooTable',
    ];
    $info['#theme'] = 'footable';
    foreach (static::getProperties() as $key => $property) {
      $info['#' . $key] = $property['default'] ?? NULL;
    }
    return $info;
  }

  /**
   * Processes a FooTable element.
   *
   * @param array $element
   *   An associative array containing the properties and children of the
   *   container.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   * @param array $complete_form
   *   The complete form structure.
   *
   * @return array
   *   The processed element.
   */
  public static function processFooTable(&$element, FormStateInterface $form_state, &$complete_form) {
    unset($element['#sticky'], $element['#responsive']);
    return $element;
  }

  /**
   *
   *
   * @param array $element
   *
   * @return array
   */
  public static function preRenderFooTable($element) {
    $element['#attributes']['class'][] = 'footable';

    /* @var \Drupal\footable\FooTableInterface $footable */
    $footable = Drupal::service('footable.footable');
    $element['#attached']['library'][] = $footable
      ->getLibrary();

    // Add FooTable properties.
    foreach (static::getProperties() as $key => $property) {
      $default = $property['default'] ?? NULL;
      $value = $element['#' . $key] ?? $default;
      if ($value !== $default) {
        if (is_bool($value)) {
          $value = $value ? 'true' : 'false';
        }
        $element['#attributes']['data-' . $property['key']] = $value;
      }
    }
    if (isset($element['#header']) && is_array($element['#header'])) {
      foreach ($element['#header'] as $key => &$header) {
        if (!is_array($header) && Element::child($key)) {
          $header = [
            'data' => $header,
          ];
        }
        if ($footable = $header['footable'] ?? NULL) {
          unset($header['footable']);
          if (isset($footable['sort'])) {
            $element['#attributes']['data-sorting'] = 'true';
            $header['data-sortable'] = 'true';
            $header['data-direction'] = $footable['sort'];
            $header['data-breakpoints'] = 'all';
          }
        }
      }
    }
    return $element;
  }

  /**
   * Retrieve a list of available FooTable properties.
   *
   * @return array
   *   An associative array keyed by property id, containing:
   *   - key: The FooTable attribute key.
   *   - default: The default value of the property.
   */
  protected static function getProperties() {
    return [
      'empty' => [
        'key' => 'empty',
        'default' => t('No Results'),
      ],
      'expand_all' => [
        'key' => 'expand-all',
        'default' => FALSE,
      ],
      'expand_first' => [
        'key' => 'expand-first',
        'default' => FALSE,
      ],
      'show_header' => [
        'key' => 'show-header',
        'default' => FALSE,
      ],
      'show_toggle' => [
        'key' => 'show-toggle',
        'default' => TRUE,
      ],
      'toggle_column' => [
        'key' => 'toggle-column',
        'default' => 'first',
      ],
      'use_parent_width' => [
        'key' => 'use-parent-width',
        'default' => FALSE,
      ],
      // Filtering.
      'filtering' => [
        'key' => 'filtering',
        'default' => FALSE,
      ],
      'filter_container' => [
        'key' => 'filter-form-container',
      ],
      'filter_delay' => [
        'key' => 'filter-delay',
        'default' => 1200,
      ],
      'filter_dropdown_title' => [
        'key' => 'filter-dropdown-title',
      ],
      'filter_exact_match' => [
        'key' => 'filter-exact-match',
        'default' => FALSE,
      ],
      'filter_focus' => [
        'key' => 'filter-focus',
        'default' => TRUE,
      ],
      'filter_ignore_case' => [
        'key' => 'filter-ignore-case',
        'default' => TRUE,
      ],
      'filter_min' => [
        'key' => 'filter-min',
        'default' => 1,
      ],
      'filter_placeholder' => [
        'key' => 'filter-placeholder',
        'default' => t('Search'),
      ],
      'filter_position' => [
        'key' => 'filter-position',
        'default' => 'right',
      ],
      'filter_space' => [
        'key' => 'filter-space',
        'default' => 'AND',
      ],
      // Sorting.
      'sorting' => [
        'key' => 'sorting',
        'default' => FALSE,
      ],
      // Paging.
      'paging' => [
        'key' => 'paging',
        'default' => FALSE,
      ],
      'paging_container' => [
        'key' => 'paging-container',
      ],
      'paging_count_format' => [
        'key' => 'paging-container',
        'default' => '{CP} of {TP}',
      ],
      'paging_current' => [
        'key' => 'paging-current',
        'default' => 1,
      ],
      'paging_limit' => [
        'key' => 'paging-limit',
        'default' => 5,
      ],
      'paging_position' => [
        'key' => 'paging-position',
        'default' => 'center',
      ],
      'paging_size' => [
        'key' => 'paging-size',
        'default' => 10,
      ],
      // State.
      'state' => [
        'key' => 'state',
        'default' => FALSE,
      ],
      'state_filtering' => [
        'key' => 'state-filtering',
        'default' => TRUE,
      ],
      'state_paging' => [
        'key' => 'state-paging',
        'default' => TRUE,
      ],
      'state_sorting' => [
        'key' => 'state-sorting',
        'default' => TRUE,
      ],
      'state_key' => [
        'key' => 'state-key',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FooTable::getInfo public function Returns the element properties for this element. Overrides Table::getInfo
FooTable::getProperties protected static function Retrieve a list of available FooTable properties.
FooTable::preRenderFooTable public static function
FooTable::processFooTable public static function Processes a FooTable element.
FormElement::processAutocomplete public static function Adds autocomplete functionality to elements.
FormElement::processPattern public static function #process callback for #pattern form element property.
FormElement::validatePattern public static function #element_validate callback for #pattern form element property.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
RenderElement::preRenderAjaxForm public static function Adds Ajax information about an element to communicate with JavaScript.
RenderElement::preRenderGroup public static function Adds members of this group as actual elements for rendering.
RenderElement::processAjaxForm public static function Form element processing handler for the #ajax form property. 1
RenderElement::processGroup public static function Arranges elements into groups.
RenderElement::setAttributes public static function Sets a form element's class attribute. Overrides ElementInterface::setAttributes
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
Table::preRenderTable public static function #pre_render callback to transform children of an element of #type 'table'.
Table::processTable public static function #process callback for #type 'table' to add tableselect support.
Table::validateTable public static function #element_validate callback for #type 'table'.
Table::valueCallback public static function Determines how user input is mapped to an element's #value property. Overrides FormElement::valueCallback 1