Disable (Close) webform form dynamically We would like to be able to put our site into a "read-only" mode prior to doing major releases etc. I was hoping to achieve this for forms on the site by enabling or disabling my custom module, which I could easily do from drush during our release process. 

The module would use a hook to disable all forms and show the closed message instead. 

This is what I had so far:

&lt;?php

use Drupal\Core\Form\FormStateInterface;

/**
 * Implementation of hook_form_alter().
 *
 * Disables any webforms when this module is active. Include a custom config key
 * called `exempt_from_maintenance_mode` with any value to allow your form to
 * remain open during maintenance.
 *
 * E.g.
 *     exempt_from_maintenance_mode: 1
 *
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
function yvw_maintenance_form_alter(&amp;$form, FormStateInterface $form_state, $form_id)
{
    // Check for custom config key
    if (array_key_exists('#exempt_from_maintenance_mode', $form)) {
        return;
    }

    // Load the webform entity. This should prevent the module from disabling
    // all forms across the site.
    $webform_id = $form['#webform_id'];
    $webform = \Drupal::entityTypeManager()-&gt;getStorage('webform')-&gt;load($webform_id);

    // Only disable the webform if its currently enabled
    if ($webform-&gt;status() === true) {
        $webform-&gt;setStatus('closed');
        // Does not save. Maybe we need a different hook.
    }
}


The problem is I would need to call $webform->save(); which would permanently close the form. I was hoping there was a hook where I could modify the form configuration only at runtime, and not persist any of the changes to the database. But I haven't been able to find any hooks that look like they would do it. 

I had a look at Close a webform when total seats reach a maximum which is close to what I want, but it appears that would only run on submission, and also permanently closes the form.
Webforms are config entities and you can use hook_webform_load() to close the webform before it is rendered and then altered. Instead of closing and resaving the webform, you can call $webform-&gt;setPropertyOverride('status', FALSE); which will safely close the webform and prevent it from being permanently closed.