Commit 6e3a805a authored by Tavi Toporjinschi's avatar Tavi Toporjinschi Committed by Lio Novelli
Browse files

Issue #3268602 by vasike, fago: DefaultContentEntityProcessor does not respect field access

parent 612f5131
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ function custom_elements_prepare_slots_as_vue_3(CustomElement $custom_element) {
 */
function custom_elements_entity_type_alter(array &$entity_types) {
  // Use the right class depending on layout builder being used.
  $class = class_exists(LayoutBuilderEntityViewDisplay::class) ? CustomElementsLayoutBuilderEntityViewDisplay::class : CustomElementsEntityViewDisplay::class;
  $class = \Drupal::moduleHandler()->moduleExists('layout_builder') ? CustomElementsLayoutBuilderEntityViewDisplay::class : CustomElementsEntityViewDisplay::class;
  /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
  $entity_types['entity_view_display']
    ->setClass($class);
+1 −0
Original line number Diff line number Diff line
@@ -51,4 +51,5 @@ class CustomElementsLayoutBuilderEntityViewDisplay extends LayoutBuilderEntityVi
      return $this->buildSections($entity);
    }
  }

}
+10 −8
Original line number Diff line number Diff line
<?php


namespace Drupal\custom_elements\Processor;

use Drupal\Core\Entity\ContentEntityInterface;
@@ -12,7 +11,6 @@ use Drupal\Core\Render\Element;
use Drupal\custom_elements\CustomElement;
use Drupal\custom_elements\CustomElementGeneratorTrait;
use Drupal\custom_elements\CustomElementsLayoutBuilderEntityViewDisplay;
use Drupal\views\Plugin\views\field\Custom;
use Symfony\Component\HttpFoundation\RequestStack;

/**
@@ -82,7 +80,7 @@ class DefaultContentEntityProcessor implements CustomElementProcessorInterface {
  /**
   * {@inheritdoc}
   */
    public function addtoElement($data, CustomElement $custom_element, $viewMode) {
  public function addtoElement($data, CustomElement $element, $viewMode) {
    assert($data instanceof ContentEntityInterface);
    $entity = $data;

@@ -92,12 +90,16 @@ class DefaultContentEntityProcessor implements CustomElementProcessorInterface {

    if ($display->getThirdPartySetting('layout_builder', 'enabled')) {
      // Skip processing of the fields and let the layout builder render it all.
      $this->addLayoutBuilderContent($entity, $custom_element, $display);
      $this->addLayoutBuilderContent($entity, $element, $display);
    }
    else {
      foreach ($display->getComponents() as $field_name => $options) {
        if (isset($entity->{$field_name})) {
          $this->getCustomElementGenerator()->process($entity->get($field_name), $custom_element, $viewMode);
        if ($entity->hasField($field_name)) {
          $access = $entity->get($field_name)->access('view', NULL, TRUE);
          $element->addCacheableDependency($access);
          if ($access->isAllowed()) {
            $this->getCustomElementGenerator()->process($entity->get($field_name), $element, $viewMode);
          }
        }
      }
    }
@@ -147,7 +149,7 @@ class DefaultContentEntityProcessor implements CustomElementProcessorInterface {
   * @param \Drupal\custom_elements\CustomElement $parent_element
   *   The parent custom element to which content will be added.
   *
   * @return CustomElement[]
   * @return \Drupal\custom_elements\CustomElement[]
   *   The list of generated custom elements.
   */
  protected function getElementsFromBlockContentRenderArray(array $build, CustomElement $parent_element) {
+0 −2
Original line number Diff line number Diff line
<?php


namespace Drupal\custom_elements\Processor;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
use Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface;
use Drupal\Core\Field\FieldItemInterface;
+0 −1
Original line number Diff line number Diff line
<?php


namespace Drupal\custom_elements\Processor;

use Drupal\Core\Field\FieldItemListInterface;
Loading