You are here

hide_preview.module in Hide Preview Button 8

Module entry point.

This file calls the hook_form_alter to manipulate the form preview button.

File

hide_preview.module
View source
<?php

/**
 * @file
 * Module entry point.
 *
 * This file calls the hook_form_alter
 * to manipulate the form preview button.
 */

/**
 * Alters the forms to hide the preview button if needed.
 *
 * @inheritdoc
 */
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;
    }
  }
}

Functions

Namesort descending Description
hide_preview_form_alter Alters the forms to hide the preview button if needed.