diff --git a/core/modules/layout_builder/src/Plugin/DataType/SectionData.php b/core/modules/layout_builder/src/Plugin/DataType/SectionData.php index be05cb61f6..f5858cedac 100644 --- a/core/modules/layout_builder/src/Plugin/DataType/SectionData.php +++ b/core/modules/layout_builder/src/Plugin/DataType/SectionData.php @@ -27,7 +27,7 @@ class SectionData extends TypedData { * {@inheritdoc} */ public function setValue($value, $notify = TRUE) { - if (!$value instanceof Section) { + if ($value && !$value instanceof Section) { throw new \InvalidArgumentException('Value is not a valid section'); } parent::setValue($value, $notify); diff --git a/core/modules/layout_builder/src/SectionComponent.php b/core/modules/layout_builder/src/SectionComponent.php index 71d76b7108..10c333f41c 100644 --- a/core/modules/layout_builder/src/SectionComponent.php +++ b/core/modules/layout_builder/src/SectionComponent.php @@ -4,8 +4,7 @@ use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Block\BlockPluginInterface; -use Drupal\Core\Cache\RefinableCacheableDependencyInterface; -use Drupal\Core\Cache\RefinableCacheableDependencyTrait; +use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Plugin\ContextAwarePluginInterface; /** @@ -19,9 +18,7 @@ * experimental modules and development releases of contributed modules. * See https://www.drupal.org/core/experimental for more information. */ -class SectionComponent implements RefinableCacheableDependencyInterface { - - use RefinableCacheableDependencyTrait; +class SectionComponent { /** * The UUID of the component. @@ -81,21 +78,23 @@ public function __construct($uuid, $region, array $configuration = [], $weight = } /** - * Builds and returns the renderable array for this component. + * Returns the renderable array for this component. * * @return array * A renderable array representing the content of the component. */ - public function build() { + public function toRenderArray() { $output = []; $plugin = $this->getPlugin(); + // @todo Figure out the best way to unify fields and blocks and components + // in https://www.drupal.org/node/2922033 if ($plugin instanceof BlockPluginInterface) { $access = $plugin->access($this->currentUser(), TRUE); - $this->addCacheableDependency($access); + $cacheability = CacheableMetadata::createFromObject($access); if ($access->isAllowed()) { - $this->addCacheableDependency($plugin); + $cacheability->addCacheableDependency($plugin); $output = [ '#theme' => 'block', '#configuration' => $plugin->getConfiguration(), @@ -106,6 +105,7 @@ public function build() { 'content' => $plugin->build(), ]; } + $cacheability->applyTo($output); } return $output; }