config_readonly.module in Configuration Read-only mode 7
File
config_readonly.module
View source
<?php
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Entity\EntityFormControllerInterface;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Config\Entity\ConfigEntityListController;
function config_readonly_form_alter(array &$form, array &$form_state) {
if (!settings()
->get('config_readonly')) {
return;
}
$form_object = $form_state['build_info']['callback_object'];
$is_config_form = $form_object instanceof ConfigFormBase || $form_object instanceof ConfigEntityListController;
if (!$is_config_form && isset($form_state['controller']) && $form_state['controller'] instanceof EntityFormControllerInterface) {
$is_config_form = $form_state['controller']
->getEntity() instanceof ConfigEntityInterface;
}
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';
}
}
function _config_readonly_validate_failure(array $form, array &$form_state) {
\Drupal::formBuilder()
->setErrorByName(NULL, $form_state, t('This configuration form cannot be saved because the configuration active store is read-only.'));
}