You are here

function config_readonly_form_alter in Configuration Read-only mode 7

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

Implements hook_form_alter().

File

./config_readonly.module, line 11

Code

function config_readonly_form_alter(array &$form, array &$form_state) {

  // If settings.php doesn't say to lock config changes, then don't do anything.
  if (!settings()
    ->get('config_readonly')) {
    return;
  }

  // Check if the form is a ConfigFormBase or a ConfigEntityListController.
  $form_object = $form_state['build_info']['callback_object'];
  $is_config_form = $form_object instanceof ConfigFormBase || $form_object instanceof ConfigEntityListController;

  // Check if the form is an EntityFormControllerInterface and if the entity is
  // a config entity.
  if (!$is_config_form && isset($form_state['controller']) && $form_state['controller'] instanceof EntityFormControllerInterface) {
    $is_config_form = $form_state['controller']
      ->getEntity() instanceof ConfigEntityInterface;
  }

  // Display a message informing the user that this form cannot be saved.
  if ($is_config_form) {
    drupal_set_message('This form will not be saved because the configuration active store is read-only.', 'warning');
    $form['#validate'][] = '_config_readonly_validate_failure';
  }
}