Problem

From looking at the code, I think DefaultContentEntityProcessor does not respect field access .

Steps to reproduce

      foreach ($display->getComponents() as $field_name => $options) {
        if (isset($entity->{$field_name})) {
          $this->getCustomElementGenerator()->process($entity->get($field_name), $custom_element, $viewMode);
        }
      }

getComponents() does not have a field-access filter, nor is it filtered here. It's usuallly done at EntityViewDisplay::buildMultiple()

Proposed resolution

Check field access like

      foreach ($display->getComponents() as $field_name => $options) {
        if (isset($entity->{$field_name}) && field access) {
          $this->getCustomElementGenerator()->process($entity->get($field_name), $custom_element, $viewMode);
        }
      }

besides that we need to make sure to reflect this in caching metadata as done by EntityViewDisplay:

 // Apply the field access cacheability metadata to the render array.
          $this->renderer
            ->addCacheableDependency($build_list[$id][$name], $field_access);

Best, let's also add a follow-up for adding a unit test that ensures that not accessible fields are not displayed.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

fago created an issue. See original summary.

fago’s picture

Issue summary: View changes

vasike made their first commit to this issue’s fork.

vasike’s picture

Status: Active » Needs review

please check the MR open

Unit testing should chased here ... or new issue?

fago’s picture

Status: Needs review » Needs work

thx, I think this looks pretty good already. We really need to setup the drupal testbot here now.

I added two comments to the MR, please see the above to comments for that. In particular the access-check cache metadata issue, see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Access%21... - the API should support that somehow.

vasike’s picture

Status: Needs work » Needs review
fago’s picture

seems good to me now. let's do some more testing and then let's merge when all fine. I created #3273275: Make custom_elements_thunder follow field-access for the remaining thunder sub-module.

fago’s picture

Status: Needs review » Reviewed & tested by the community

useernamee made their first commit to this issue’s fork.

  • useernamee committed 6e3a805 on 8.x-2.x authored by vasike
    Issue #3268602 by vasike, fago: DefaultContentEntityProcessor does not...
useernamee’s picture

Status: Reviewed & tested by the community » Fixed

pr merged. will be included in the next release

Status: Fixed » Closed (fixed)

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