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;
* {@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');
}
/**
/**
* {@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);
}
/**
*/
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;
}
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();
+ }
+
}