eleven-8.x-1.0-beta5/elevenformsuggestions/elevenformsuggestions.module

elevenformsuggestions/elevenformsuggestions.module
<?php

/**
 * @file
 * Provides hooks for elevenformsuggestions module.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;

function elevenformsuggestions_theme_suggestions_input(array $variables) {

  $suggestions = [];

  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'input___form_id__'. $variables['element']['#form_id'];
    $suggestions[] = 'input__'. $variables['element']['#type'] . '___form_id__'  . $variables['element']['#form_id'];
  }
  return $suggestions;

  kint($suggestions);

}

/**
 * Implements hook_preprocess_form_element().
 */
function elevenformsuggestions_preprocess_form_element(array &$variables) {

  if (!isset($variables['label'])) {
    return;
  }

  if (isset($variables['element']['#form_id'])) {
    $variables['label']['#form_id'] = $variables['element']['#form_id'];
  }
  if (isset($variables['element']['#type'])) {
    $variables['label']['#form_element_type'] = $variables['element']['#type'];
  }

}

/**
 * Implements hook_theme_suggestions_form_element().
 */
function elevenformsuggestions_theme_suggestions_form_element(array $variables) {
  $suggestions = ['form_element__type__' . $variables['element']['#type']];
  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'form_element__form_id__' . $variables['element']['#form_id'];
    $suggestions[] = 'form_element__' . $variables['element']['#type'] . '___form_id__' . $variables['element']['#form_id'];
  }

  return $suggestions;
}

/**
 * Implements hook_theme_suggestions_form_element_label().
 */
function elevenformsuggestions_theme_suggestions_form_element_label(array $variables) {
  $suggestions = [];
  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'form_element_label__form-id__' . $variables['element']['#form_id'];
  }
  if (isset($variables['element']['#form_element_type']) && isset($variables['element']['#form_id'])) {
    $suggestions[] = 'form_element_label__' . $variables['element']['#form_element_type'] . '___form_id__'. $variables['element']['#form_id'];
  }

  return $suggestions;
}

function elevenformsuggestions_theme_suggestions_form(array $variables) {
  $suggestions = [];

  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'form___form-id__' . $variables['element']['#form_id'];
  }

  return $suggestions;
}

/**
 * Implements hook_theme_suggestions_details().
 */
function elevenformsuggestions_theme_suggestions_details(array $variables) {
  $suggestions = [];

  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'details___form-id__' . $variables['element']['#form_id'];
  }

  return $suggestions;
}

/**
 * Implements hook_theme_suggestions_select().
 */
function elevenformsuggestions_theme_suggestions_select(array $variables) {
  $suggestions = [];

  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'select___form-id__' . $variables['element']['#form_id'];
  }

  return $suggestions;
}

/**
 * Implements hook_theme_suggestions_select().
 */
function elevenformsuggestions_theme_suggestions_fieldset(array $variables) {
  $suggestions = [];

  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'fieldset___form-id__' . $variables['element']['#form_id'];
  }

  return $suggestions;
}

function elevenformsuggestions_theme_suggestions_checkboxes(array $variables) {
  $suggestions = [];

  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'checkboxes___form-id__' . $variables['element']['#form_id'];
  }

  return $suggestions;
}

function elevenformsuggestions_theme_suggestions_radios(array $variables) {
  $suggestions = [];

  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'radios___form-id__' . $variables['element']['#form_id'];
  }

  return $suggestions;
}

function elevenformsuggestions_theme_suggestions_textarea(array $variables) {
  $suggestions = [];

  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'textarea___form-id__' . $variables['element']['#form_id'];
  }

  return $suggestions;
}

function elevenformsuggestions_theme_suggestions_vertical_tabs(array $variables) {
  $suggestions = [];

  if (isset($variables['element']['#form_id'])) {
    $suggestions[] = 'vertical_tabs___form-id__' . $variables['element']['#form_id'];
  }

  return $suggestions;
}

/**
 * Implements hook_form_alter().
 */
function elevenformsuggestions_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  elevenformsuggestions_attach_form_id($form, $form_id);
}

/**
 * Attaches form id to all form elements.
 *
 * @param $form
 *   The form or form element which children should have form id attached.
 * @param $form_id
 *   The form id attached to form elements.
 *
 * @return array
 */
function elevenformsuggestions_attach_form_id(&$form, $form_id) {
  foreach (Element::children($form) as $child) {
    if (!isset($form[$child]['#form_id'])) {
      $form[$child]['#form_id'] = $form_id;
    }
    elevenformsuggestions_attach_form_id($form[$child], $form_id);
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc