form_inspector-8.x-1.x-dev/form_inspector.module

form_inspector.module
<?php

use Drupal\Core\Entity\EntityFormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\form_inspector\Entity\FormInspectorEntityFormDisplay;

/**
 * Implements hook_help().
 */
function form_inspector_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.form_inspector':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The Form Inspector module provides ancestors information of each form element adding an HTML comment with the keyword ANCESTORS in the prefix, it is very useful to track nested paragraphs. Besides, the module adds contextual links to edit fields from the form.');
      return $output;
  }
}

/**
 * Implements hook_entity_type_alter().
 */
function form_inspector_entity_type_alter(array &$entity_types) {
  $entity_types['entity_form_display']->setClass(FormInspectorEntityFormDisplay::class);
}

/**
 * Implements hook_field_widget_single_element_form_alter().
 */
function form_inspector_field_widget_single_element_form_alter(array &$element, FormStateInterface $form_state, array $context) {
  \Drupal::service('form_inspector.manager')
    ->fieldWidgetFormAlter($element, $form_state, $context);
}

/**
 * Implements hook_field_widget_complete_form_alter().
 */
function form_inspector_field_widget_complete_form_alter(&$field_widget_complete_form, FormStateInterface $form_state, $context) {
  $elements = &$field_widget_complete_form['widget'];
  \Drupal::service('form_inspector.manager')
    ->fieldWidgetFormAlter($elements, $form_state, $context, FALSE, FALSE);
}

/**
 * Implements hook_form_alter().
 */
function form_inspector_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if ($form_state->getFormObject() instanceof EntityFormInterface) {
    $form['#attached']['library'][] = 'contextual/drupal.contextual-links';
  }
}

/**
 * Implements hook_theme_registry_alter().
 */
function form_inspector_theme_registry_alter(&$theme_registry) {
  if (isset($theme_registry['form_element'])) {
    $theme_registry['form_element']['path'] = \Drupal::service('extension.list.module')->getPath('form_inspector') . '/templates';
  }
}

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

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