User can't see field

Created on 14 March 2024, 9 months ago

Problem/Motivation

User can't see published at field event if have access to add/edit this date.
Problem is in $form['published_at']['#group'] = 'revision_information';

function publication_date_form_node_form_alter(&$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->bundle() . ' published on date');
    $form['published_at']['#group'] = 'revision_information';
  }
}

There are cases when user doesn't have access to revision_information group, and if we try add published at date that that group, user can't see that.

Steps to reproduce

Create user with minimal permission to edit node + permission at field, without any revision permission.
Try to change publish date.

Proposed resolution

Move field to other group? Maybe Authoring information?
Or check if access is false and change on true?

🐛 Bug report
Status

Active

Component

Code

Created by

🇵🇱Poland Pawelgorski87

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024