Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / layout_builder / src / Plugin / SectionStorage / OverridesSectionStorage.php
index ef154f1b2b2e122f282b4d10cb6acc142b20f2a7..3a92ee63fab7fe21fbfd5f50243c25650f7da1ad 100644 (file)
@@ -2,15 +2,15 @@
 
 namespace Drupal\layout_builder\Plugin\SectionStorage;
 
+use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Entity\EntityFieldManagerInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\FieldableEntityInterface;
 use Drupal\Core\Field\FieldItemListInterface;
 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
-use Drupal\Core\Plugin\Context\Context;
-use Drupal\Core\Plugin\Context\ContextDefinition;
-use Drupal\Core\StringTranslation\TranslatableMarkup;
+use Drupal\Core\Plugin\Context\EntityContext;
+use Drupal\Core\Session\AccountInterface;
 use Drupal\Core\Url;
 use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
 use Drupal\layout_builder\OverridesSectionStorageInterface;
@@ -187,7 +187,9 @@ class OverridesSectionStorage extends SectionStorageBase implements ContainerFac
    * {@inheritdoc}
    */
   public function getDefaultSectionStorage() {
-    return LayoutBuilderEntityViewDisplay::collectRenderDisplay($this->getEntity(), 'default');
+    // @todo Expand to work for all view modes in
+    //   https://www.drupal.org/node/2907413.
+    return LayoutBuilderEntityViewDisplay::collectRenderDisplay($this->getEntity(), 'full');
   }
 
   /**
@@ -200,10 +202,10 @@ class OverridesSectionStorage extends SectionStorageBase implements ContainerFac
   /**
    * {@inheritdoc}
    */
-  public function getLayoutBuilderUrl() {
+  public function getLayoutBuilderUrl($rel = 'view') {
     $entity = $this->getEntity();
     $route_parameters[$entity->getEntityTypeId()] = $entity->id();
-    return Url::fromRoute("layout_builder.{$this->getStorageType()}.{$this->getEntity()->getEntityTypeId()}.view", $route_parameters);
+    return Url::fromRoute("layout_builder.{$this->getStorageType()}.{$this->getEntity()->getEntityTypeId()}.$rel", $route_parameters);
   }
 
   /**
@@ -211,9 +213,7 @@ class OverridesSectionStorage extends SectionStorageBase implements ContainerFac
    */
   public function getContexts() {
     $entity = $this->getEntity();
-    // @todo Use EntityContextDefinition after resolving
-    //   https://www.drupal.org/node/2932462.
-    $contexts['layout_builder.entity'] = new Context(new ContextDefinition("entity:{$entity->getEntityTypeId()}", new TranslatableMarkup('@entity being viewed', ['@entity' => $entity->getEntityType()->getLabel()])), $entity);
+    $contexts['layout_builder.entity'] = EntityContext::fromEntity($entity);
     return $contexts;
   }
 
@@ -231,4 +231,13 @@ class OverridesSectionStorage extends SectionStorageBase implements ContainerFac
     return $this->getEntity()->save();
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
+    $default_section_storage = $this->getDefaultSectionStorage();
+    $result = AccessResult::allowedIf($default_section_storage->isLayoutBuilderEnabled())->addCacheableDependency($default_section_storage);
+    return $return_as_object ? $result : $result->isAllowed();
+  }
+
 }