You are here

field_states_ui.module in Field States UI 8.2

Same filename and directory in other branches
  1. 8 field_states_ui.module

Main module file for Field States UI.

File

field_states_ui.module
View source
<?php

/**
 * @file
 * Main module file for Field States UI.
 */
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\WidgetInterface;
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_field_widget_third_party_settings_form().
 */
function field_states_ui_field_widget_third_party_settings_form(WidgetInterface $plugin, FieldDefinitionInterface $field_definition, $form_mode, $form, FormStateInterface $form_state) {
  return \Drupal::service('plugin.manager.field_states_ui.fieldstate')
    ->settingsForm($plugin, $field_definition, $form_mode, $form, $form_state);
}

/**
 * Implements hook_field_widget_settings_summary_alter().
 */
function field_states_ui_field_widget_settings_summary_alter(&$summary, $context) {
  $field_states = $context['widget']
    ->getThirdPartySettings('field_states_ui');
  if (!empty($field_states['field_states'])) {
    $summary[] = t('Field States applied.');
  }
}

/**
 * Implements hook_field_widget_multivalue_form_alter().
 */
function field_states_ui_field_widget_multivalue_form_alter(&$elements, FormStateInterface $form_state, $context) {

  // Don't show on default value forms.
  if ($context['default']) {
    return;
  }
  \Drupal::service('plugin.manager.field_states_ui.fieldstate')
    ->apply($elements, $form_state, $context);
}

/**
 * Implements hook_theme().
 */
function field_states_ui_theme() {
  return [
    'field_states_ui_summary' => [
      'variables' => [
        'data' => [],
      ],
    ],
  ];
}