You are here

function publication_date_form_node_form_alter in Publication Date 8

Same name and namespace in other branches
  1. 8.2 publication_date.module \publication_date_form_node_form_alter()
  2. 7.2 publication_date.module \publication_date_form_node_form_alter()
  3. 7 publication_date.module \publication_date_form_node_form_alter()

Implements hook_form_BASE_ID_alter().

Display the publication date on the node edit form. @note: This won't work where you have Display Suite/REL enabled.

File

./publication_date.module, line 88
Add a field to nodes containing the publication date.

Code

function publication_date_form_node_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $account = \Drupal::currentUser();
  $node = $form_state
    ->getFormObject()
    ->getEntity();
  if (isset($form['published_at'])) {

    // Check if the user has permission to edit the publication date.
    $form['published_at']['#access'] = $account
      ->hasPermission('set any published on date') || $account
      ->hasPermission('set ' . $node->type . ' published on date');
    $form['published_at']['#group'] = 'revision_information';
  }
}