You are here

config_override_warn.module in Configuration Override Warn 8

Shows message on config forms when any values are possibly being overridden.

File

config_override_warn.module
View source
<?php

/**
 * @file
 * Shows message on config forms when any values are possibly being overridden.
 */
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_theme().
 */
function config_override_warn_theme($existing, $type, $theme, $path) {
  return [
    'config_override_warn_overrides' => [
      'variables' => [
        'overrides' => [],
      ],
    ],
  ];
}

/**
 * Implements hook_form_alter().
 */
function config_override_warn_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if ($overrides = \Drupal::service('config_override_warn.form_overrides')
    ->getFormOverrides($form_state
    ->getFormObject())) {
    $override_output = [
      '#theme' => 'config_override_warn_overrides',
      '#overrides' => $overrides,
    ];
    $warning = \Drupal::service('renderer')
      ->renderPlain($override_output);
    \Drupal::service('messenger')
      ->addWarning($warning);
  }
}