You are here

function promote_disable_form_alter in Promote Disable 8

Same name and namespace in other branches
  1. 7 promote_disable.module \promote_disable_form_alter()

Implements hook_form_alter().

File

./promote_disable.module, line 16
Primarily Drupal hooks and helper functions.

Code

function promote_disable_form_alter(&$form, FormStateInterface &$form_state, $form_id) {

  // Node type form.
  if ($form_id == 'node_type_edit_form') {

    // The current form's node type.
    $node_type = $form['type']['#default_value'];

    // Our saved front page node types.
    $node_types = \Drupal::configFactory()
      ->getEditable('promote_disable.settings')
      ->get('promote_disable_node_types');

    // Is this node type one we've set?
    if (in_array($node_type, $node_types)) {

      // Unset the form element.
      unset($form['workflow']['options']['#options']['promote']);
    }

    // Our saved sticky page node types.
    $node_types = \Drupal::configFactory()
      ->getEditable('promote_disable.settings')
      ->get('promote_disable_sticky_node_types');

    // Is this node type one we've set?
    if (in_array($node_type, $node_types)) {

      // Unset the form element.
      unset($form['workflow']['options']['#options']['sticky']);
    }
  }
}