You are here

function config_readonly_form_alter in Configuration Read-only mode 8

Same name and namespace in other branches
  1. 7 config_readonly.module \config_readonly_form_alter()

Implements hook_form_alter().

File

./config_readonly.module, line 15
Contains config_readonly.module.

Code

function config_readonly_form_alter(array &$form, FormStateInterface &$form_state) {
  if (!Settings::get('config_readonly')) {
    return;
  }
  $event = new ReadOnlyFormEvent($form_state);
  \Drupal::service('event_dispatcher')
    ->dispatch(ReadOnlyFormEvent::NAME, $event);
  if ($event
    ->isFormReadOnly()) {
    \Drupal::messenger()
      ->addWarning('This form will not be saved because the configuration active store is read-only.');
    $form['#validate'][] = '_config_readonly_validate_failure';
    if (isset($form['actions']['submit'])) {
      $form['actions']['submit']['#disabled'] = TRUE;
    }
  }
}