You are here

function publishcontent_form_node_form_alter in Publish Content 8

Same name and namespace in other branches
  1. 7 publishcontent.module \publishcontent_form_node_form_alter()

Implements hook_form_BASE_FORM_ID_alter().

File

./publishcontent.module, line 14
Contains publishcontent.module.

Code

function publishcontent_form_node_form_alter(&$form, FormStateInterface $form_state) {
  $config = \Drupal::config('publishcontent.settings');
  $form['status']['widget']['value']['#title'] = $config
    ->get('publish_text_value');
  if (!array_key_exists('#default_value', $form['status']['widget']['value'])) {
    $form['status']['widget']['value']['#default_value'] = 0;
  }
  $form['status']['widget']['value']['#default_value'] ? $form['meta']['published']['#markup'] = $config
    ->get('publish_text_value') : ($form['meta']['published']['#markup'] = $config
    ->get('unpublish_text_value'));
  if (empty($config) || empty($config
    ->get('ui_checkbox'))) {
    $form['status']['#disabled'] = TRUE;
    return;
  }
  if (!empty($form['status']) && empty($form['status']['#access'])) {
    $user = Drupal::currentUser();
    $node = $form_state
      ->getFormObject()
      ->getEntity();
    $publishContentAccess = new PublishContentAccess();
    $form['status']['#access'] = TRUE;
    if (!$publishContentAccess
      ->access($user, $node)
      ->isAllowed()) {
      $form['status']['#disabled'] = TRUE;
      $form['status']['widget']['value']['#description'] = t('You can not change the @published status.', [
        '@published' => $config
          ->get('publish_text_value'),
      ]);
    }
  }
}