You are here

class DataTablesModifier in Modifiers Pack 8

Provides a Modifier to advanced interaction controls to HTML tables.

Plugin annotation


@Modifier(
  id = "datatables_modifier",
  label = @Translation("DataTables Modifier"),
  description = @Translation("Provides a Modifier to advanced interaction controls to HTML tables."),
)

Hierarchy

  • class \Drupal\modifiers_datatables\Plugin\modifiers\DataTablesModifier extends \Drupal\modifiers\ModifierPluginBase

Expanded class hierarchy of DataTablesModifier

1 string reference to 'DataTablesModifier'
DataTablesModifier::modification in modules/modifiers_datatables/src/Plugin/modifiers/DataTablesModifier.php

File

modules/modifiers_datatables/src/Plugin/modifiers/DataTablesModifier.php, line 17

Namespace

Drupal\modifiers_datatables\Plugin\modifiers
View source
class DataTablesModifier extends ModifierPluginBase {

  /**
   * {@inheritdoc}
   */
  public static function modification($selector, array $config) {
    if (!empty($config['dt_paging'])) {
      $args['paging'] = (bool) $config['dt_paging'];
    }
    if (!empty($config['dt_searching'])) {
      $args['searching'] = (bool) $config['dt_searching'];
    }
    if (!empty($config['dt_ordering'])) {
      $args['ordering'] = (bool) $config['dt_ordering'];
    }
    if (!empty($config['dt_scroll_y'])) {
      $args['scroll_y'] = (int) $config['dt_scroll_y'];
    }
    if (!empty($config['dt_scroll_collapse'])) {
      $args['scroll_collapse'] = (bool) $config['dt_scroll_collapse'];
    }
    if (!empty($config['dt_scroll_x'])) {
      $args['scroll_x'] = (bool) $config['dt_scroll_x'];
    }
    if (!empty($config['dt_length_menu'])) {
      $args['length_menu'] = [];
      foreach ($config['dt_length_menu'] as $value) {
        $args['length_menu'][0][] = $value;
        $args['length_menu'][1][] = $value == -1 ? 'All' : $value;
      }
      $args['page_length'] = (int) $args['length_menu'][0][0];
    }
    if (!empty($args)) {
      $css = [];
      $media = parent::getMediaQuery($config);
      if (!empty($config['dt_nowrap'])) {
        $css[$media][$selector . ' th'][] = 'white-space:nowrap';
        $css[$media][$selector . ' td'][] = 'white-space:nowrap';
      }
      $libraries = [
        'modifiers_datatables/apply',
      ];
      $settings = [
        'namespace' => 'DataTablesModifier',
        'callback' => 'apply',
        'selector' => $selector,
        'media' => $media,
        'args' => $args,
      ];
      return new Modification($css, $libraries, $settings);
    }
    return NULL;
  }

}

Members