Problem/Motivation

The langcode field widget is not hidden when denying access via hook_entity_field_access().

Proposed resolution

Slightly modify hook_form_alter() implementation in language.modue since it happens after hook_entity_field_access().

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Original report by [username]

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ibustos created an issue. See original summary.

ibustos’s picture

Attached test evidencing the problem.

ibustos’s picture

ibustos’s picture

ibustos’s picture

Status: Active » Needs review

ibustos’s picture

Title: Language selector picker is immune to hook_entity_field_access in entity forms. » Language selector is immune to hook_entity_field_access in entity forms.
joachim’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Nice bug fix and great test coverage.

Committed and pushed f6674fa417 to 8.7.x and efefc9236c to 8.6.x. Thanks!

+++ b/core/modules/language/tests/language_entity_field_access_test/language_entity_field_access_test.module
@@ -0,0 +1,18 @@
+function language_entity_field_access_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
+  return AccessResult::forbidden();
+}

Quite extreme to deny access to everything but it works within the context of the test. I think we could file a follow-up to make field_test_boolean_access_denied_entity_field_access() more generic and rename its module and use it here.

  • alexpott committed f6674fa on 8.7.x
    Issue #3017812 by ibustos, joachim: Language selector is immune to...

  • alexpott committed efefc92 on 8.6.x
    Issue #3017812 by ibustos, joachim: Language selector is immune to...
a_mitch’s picture

This if statement in language.module was throwing warnings when i form i had didn't have #access set inside $form['langcode'].

    if (isset($form[$langcode_key]) && $form[$langcode_key]['#access'] !== FALSE) {
      $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
      $form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
    }

I have attached a small patch that checks if #access is not set or is false.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
quietone’s picture

Version: 9.3.x-dev » 8.6.x-dev
Status: Needs review » Fixed

This was committed to 8.6. It was re-opened due to a problem when #access is not defined on the form. Instead, lets made a follow up to explore that problem,

Follow up creates #3270660: Warning if #access not defined on form. Restoring meta data to the time this was committed.

Cheers.

quietone’s picture

Moved patch and credit to new issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.