Issue #3043825 by tim.plunkett, johndevman, phenaproxima: Create an interface for LayoutBuilderSampleEntityGenerator
parent
f4f6026156
commit
a10a712f2e
|
@ -8,13 +8,8 @@ use Drupal\Core\TempStore\SharedTempStoreFactory;
|
|||
|
||||
/**
|
||||
* 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 @@ class LayoutBuilderSampleEntityGenerator {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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 @@ class LayoutBuilderSampleEntityGenerator {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ use Drupal\Core\Session\AccountInterface;
|
|||
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;
|
||||
|
|
|
@ -9,8 +9,8 @@ use Drupal\Core\Entity\EntityTypeInterface;
|
|||
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 @@ class DefaultsSectionStorageTest extends UnitTestCase {
|
|||
|
||||
$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',
|
||||
|
|
Loading…
Reference in New Issue