From e7a410097428a8c67b61a9c4433321154d1c0c7d Mon Sep 17 00:00:00 2001 From: xjm <xjm@65776.no-reply.drupal.org> Date: Wed, 27 Mar 2019 19:00:37 -0500 Subject: [PATCH] Issue #3043825 by tim.plunkett, johndevman, phenaproxima: Create an interface for LayoutBuilderSampleEntityGenerator --- .../LayoutBuilderSampleEntityGenerator.php | 26 ++------------ .../Entity/SampleEntityGeneratorInterface.php | 35 +++++++++++++++++++ .../SectionStorage/DefaultsSectionStorage.php | 6 ++-- .../src/Unit/DefaultsSectionStorageTest.php | 6 ++-- 4 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 core/modules/layout_builder/src/Entity/SampleEntityGeneratorInterface.php diff --git a/core/modules/layout_builder/src/Entity/LayoutBuilderSampleEntityGenerator.php b/core/modules/layout_builder/src/Entity/LayoutBuilderSampleEntityGenerator.php index 9f606070e3fd..9897c4719c23 100644 --- a/core/modules/layout_builder/src/Entity/LayoutBuilderSampleEntityGenerator.php +++ b/core/modules/layout_builder/src/Entity/LayoutBuilderSampleEntityGenerator.php @@ -8,13 +8,8 @@ /** * Generates a sample entity for use by the Layout Builder. - * - * @internal - * Layout Builder is currently experimental and should only be leveraged by - * experimental modules and development releases of contributed modules. - * See https://www.drupal.org/core/experimental for more information. */ -class LayoutBuilderSampleEntityGenerator { +class LayoutBuilderSampleEntityGenerator implements SampleEntityGeneratorInterface { /** * The shared tempstore factory. @@ -44,15 +39,7 @@ public function __construct(SharedTempStoreFactory $temp_store_factory, EntityTy } /** - * Gets a sample entity for a given entity type and bundle. - * - * @param string $entity_type_id - * The entity type ID. - * @param string $bundle_id - * The bundle ID. - * - * @return \Drupal\Core\Entity\EntityInterface - * An entity. + * {@inheritdoc} */ public function get($entity_type_id, $bundle_id) { $tempstore = $this->tempStoreFactory->get('layout_builder.sample_entity'); @@ -73,14 +60,7 @@ public function get($entity_type_id, $bundle_id) { } /** - * Deletes a sample entity for a given entity type and bundle. - * - * @param string $entity_type_id - * The entity type ID. - * @param string $bundle_id - * The bundle ID. - * - * @return $this + * {@inheritdoc} */ public function delete($entity_type_id, $bundle_id) { $tempstore = $this->tempStoreFactory->get('layout_builder.sample_entity'); diff --git a/core/modules/layout_builder/src/Entity/SampleEntityGeneratorInterface.php b/core/modules/layout_builder/src/Entity/SampleEntityGeneratorInterface.php new file mode 100644 index 000000000000..3df87ba23bec --- /dev/null +++ b/core/modules/layout_builder/src/Entity/SampleEntityGeneratorInterface.php @@ -0,0 +1,35 @@ +<?php + +namespace Drupal\layout_builder\Entity; + +/** + * Generates a sample entity. + */ +interface SampleEntityGeneratorInterface { + + /** + * Gets a sample entity for a given entity type and bundle. + * + * @param string $entity_type_id + * The entity type ID. + * @param string $bundle_id + * The bundle ID. + * + * @return \Drupal\Core\Entity\EntityInterface + * An entity. + */ + public function get($entity_type_id, $bundle_id); + + /** + * Deletes a sample entity for a given entity type and bundle. + * + * @param string $entity_type_id + * The entity type ID. + * @param string $bundle_id + * The bundle ID. + * + * @return $this + */ + public function delete($entity_type_id, $bundle_id); + +} diff --git a/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php b/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php index 38acebf3cfbb..98e6e34df2c0 100644 --- a/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php +++ b/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php @@ -15,7 +15,7 @@ use Drupal\Core\Url; use Drupal\field_ui\FieldUI; use Drupal\layout_builder\DefaultsSectionStorageInterface; -use Drupal\layout_builder\Entity\LayoutBuilderSampleEntityGenerator; +use Drupal\layout_builder\Entity\SampleEntityGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\RouteCollection; @@ -60,14 +60,14 @@ class DefaultsSectionStorage extends SectionStorageBase implements ContainerFact /** * The sample entity generator. * - * @var \Drupal\layout_builder\Entity\LayoutBuilderSampleEntityGenerator + * @var \Drupal\layout_builder\Entity\SampleEntityGeneratorInterface */ protected $sampleEntityGenerator; /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, LayoutBuilderSampleEntityGenerator $sample_entity_generator) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, SampleEntityGeneratorInterface $sample_entity_generator) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entity_type_manager; diff --git a/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php b/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php index 8add377b259b..f36b8fbc94b1 100644 --- a/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php @@ -9,8 +9,8 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Plugin\Context\ContextInterface; -use Drupal\layout_builder\Entity\LayoutBuilderSampleEntityGenerator; use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface; +use Drupal\layout_builder\Entity\SampleEntityGeneratorInterface; use Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage; use Drupal\layout_builder\SectionStorage\SectionStorageDefinition; use Drupal\Tests\UnitTestCase; @@ -41,7 +41,7 @@ class DefaultsSectionStorageTest extends UnitTestCase { /** * The sample entity generator. * - * @var \Drupal\layout_builder\Entity\LayoutBuilderSampleEntityGenerator + * @var \Drupal\layout_builder\Entity\SampleEntityGeneratorInterface */ protected $sampleEntityGenerator; @@ -53,7 +53,7 @@ protected function setUp() { $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class); $entity_type_bundle_info = $this->prophesize(EntityTypeBundleInfoInterface::class); - $this->sampleEntityGenerator = $this->prophesize(LayoutBuilderSampleEntityGenerator::class); + $this->sampleEntityGenerator = $this->prophesize(SampleEntityGeneratorInterface::class); $definition = new SectionStorageDefinition([ 'id' => 'defaults', -- GitLab