Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / layout_builder / src / EventSubscriber / BlockComponentRenderArray.php
index 181ed8229b6cc523f54c4b1b02451658986bb0da..c2e3bfb188899606daad512542260c377b03d872 100644 (file)
@@ -2,9 +2,11 @@
 
 namespace Drupal\layout_builder\EventSubscriber;
 
+use Drupal\block_content\Access\RefinableDependentAccessInterface;
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Block\BlockPluginInterface;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\layout_builder\Access\LayoutPreviewAccessAllowed;
 use Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent;
 use Drupal\layout_builder\LayoutBuilderEvents;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -56,6 +58,24 @@ class BlockComponentRenderArray implements EventSubscriberInterface {
       return;
     }
 
+    // Set block access dependency even if we are not checking access on
+    // this level. The block itself may render another
+    // RefinableDependentAccessInterface object and need to pass on this value.
+    if ($block instanceof RefinableDependentAccessInterface) {
+      $contexts = $event->getContexts();
+      if (isset($contexts['layout_builder.entity'])) {
+        if ($entity = $contexts['layout_builder.entity']->getContextValue()) {
+          if ($event->inPreview()) {
+            // If previewing in Layout Builder allow access.
+            $block->setAccessDependency(new LayoutPreviewAccessAllowed());
+          }
+          else {
+            $block->setAccessDependency($entity);
+          }
+        }
+      }
+    }
+
     // Only check access if the component is not being previewed.
     if ($event->inPreview()) {
       $access = AccessResult::allowed()->setCacheMaxAge(0);