public function ReadOnlyFormSubscriber::onFormAlter in Configuration Read-only mode 8
File
- src/EventSubscriber/ReadOnlyFormSubscriber.php, line 45
Class
- ReadOnlyFormSubscriber
- Check if the given form should be read-only.
Namespace
Drupal\config_readonly\EventSubscriber
Code
public function onFormAlter(ReadOnlyFormEvent $event) {
$form_object = $event
->getFormState()
->getFormObject();
$mark_form_read_only = $form_object instanceof ConfigFormBase || $form_object instanceof ConfigEntityListBuilder;
if (!$mark_form_read_only) {
$mark_form_read_only = in_array($form_object
->getFormId(), $this->readOnlyFormIds);
}
if (!$mark_form_read_only && $form_object instanceof EntityFormInterface) {
$entity = $form_object
->getEntity();
$mark_form_read_only = $entity instanceof ConfigEntityInterface;
}
if ($mark_form_read_only && $form_object instanceof EntityFormInterface) {
$entity = $form_object
->getEntity();
$name = $entity
->getConfigDependencyName();
if ($this
->matchesWhitelistPattern($name)) {
$mark_form_read_only = FALSE;
}
}
if ($mark_form_read_only && $form_object instanceof ConfigFormBase) {
$editable_config = $this
->getEditableConfigNames($form_object);
if ($editable_config == array_filter($editable_config, [
$this,
'matchesWhitelistPattern',
])) {
$mark_form_read_only = FALSE;
}
}
if ($mark_form_read_only) {
$event
->markFormReadOnly();
}
}