You are here

function hide_preview_form_alter in Hide Preview Button 8

Alters the forms to hide the preview button if needed.

@inheritdoc

File

./hide_preview.module, line 16
Module entry point.

Code

function hide_preview_form_alter(&$form, $form_state, $form_id) {
  $config = Drupal::config('hide_preview.settings');
  $formNames = $config
    ->get('hide_preview.form_names');

  // Check if it is a regexp or a simple string.
  foreach ($formNames as $name) {
    if (@preg_match($name, $form_id, $matches) !== FALSE) {
      if (count($matches)) {
        $form['actions']['preview']['#access'] = FALSE;
      }
    }
    elseif (strpos($form_id, $name) !== FALSE) {
      $form['actions']['preview']['#access'] = FALSE;
    }
  }
}