You are here

function promote_disable_form_node_form_alter in Promote Disable 8

Implements hook_form_BASE_FORM_ID_alter().

File

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

Code

function promote_disable_form_node_form_alter(&$form, FormStateInterface $form_state) {
  $node = $form_state
    ->getFormObject()
    ->getEntity();
  $node_type = $node
    ->getType();
  $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)) {

    // Remove the option.
    unset($form['promote']);
  }

  // Our saved sticky 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)) {

    // Remove the option.
    unset($form['sticky']);
  }
}