You are here

entityreference_dragdrop.module in Entity Reference Drag & Drop 8

Same filename and directory in other branches
  1. 7 entityreference_dragdrop.module
  2. 2.x entityreference_dragdrop.module

File

entityreference_dragdrop.module
View source
<?php

use Drupal\Core\Template\Attribute;

/**
 * Implements hook_theme().
 */
function entityreference_dragdrop_theme($existing, $type, $theme, $path) {
  return [
    'entityreference_dragdrop_options_list' => [
      'variables' => [
        'items' => [],
        'title' => '',
        'wrapper_attributes' => [],
        'attributes' => [],
        'display_filter' => 0,
      ],
    ],
  ];
}

/**
 * Prepares variables for entityreference_dragdrop options list template.
 *
 * @param array $variables
 */
function template_preprocess_entityreference_dragdrop_options_list(&$variables) {
  $variables['wrapper_attributes'] = new Attribute($variables['wrapper_attributes']);
  foreach ($variables['items'] as &$item) {
    $attributes = [];

    // If the item value is an array, then it is a render array.
    if (is_array($item)) {

      // List items support attributes via the '#wrapper_attributes' property.
      if (isset($item['#wrapper_attributes'])) {
        $attributes = $item['#wrapper_attributes'];
      }
    }

    // Set the item's value and attributes for the template.
    $item = [
      'value' => $item,
      'attributes' => new Attribute($attributes),
    ];
  }
  $variables['filter'] = !$variables['display_filter'] ? [] : [
    '#type' => 'textfield',
    '#attributes' => [
      'class' => [
        'entityreference-dragdrop-filter',
      ],
    ],
  ];
}

Functions

Namesort descending Description
entityreference_dragdrop_theme Implements hook_theme().
template_preprocess_entityreference_dragdrop_options_list Prepares variables for entityreference_dragdrop options list template.