SectionStorageDefinition example

/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    entity_test_create_bundle('bundle_with_extra_fields');
    $this->installEntitySchema('entity_test');
    $this->installEntitySchema('user');
    $this->installConfig(['layout_builder_defaults_test']);

    $definition = (new SectionStorageDefinition())
      ->addContextDefinition('display', EntityContextDefinition::fromEntityTypeId('entity_view_display'))
      ->addContextDefinition('view_mode', new ContextDefinition('string'));
    $this->plugin = DefaultsSectionStorage::create($this->container, [], 'defaults', $definition);
  }

  /** * Tests installing defaults via config install. */
  public function testConfigInstall() {
    /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display */
    $display = LayoutBuilderEntityViewDisplay::load('entity_test.bundle_with_extra_fields.default');
    

    $section_storage_second = $this->prophesize(SectionStorageInterface::class);
    $section_storage_second->buildRoutes(Argument::type(RouteCollection::class))->shouldBeCalled()->will(function D$args) {
      /** @var \Symfony\Component\Routing\RouteCollection $collection */
      $collection = $args[0];
      $collection->add('test_route_shared', new Route('/test/path/shared2'));
      $collection->add('test_route2', new Route('/test/path2'));
    });

    $this->sectionStorageManager->loadEmpty('first')->willReturn($section_storage_first->reveal());
    $this->sectionStorageManager->loadEmpty('second')->willReturn($section_storage_second->reveal());
    $definitions['first'] = new SectionStorageDefinition();
    $definitions['second'] = new SectionStorageDefinition();
    $this->sectionStorageManager->getDefinitions()->willReturn($definitions);

    $collection = new RouteCollection();
    $event = new RouteBuildEvent($collection);
    $this->routeBuilder->onAlterRoutes($event);
    $this->assertEquals($expected$collection->all());
    $this->assertSame(array_keys($expected)array_keys($collection->all()));
  }

}
/** * {@inheritdoc} */
  protected function getSectionList(array $section_data) {
    $config = $this->container->get('config.factory')->getEditable('layout_builder_test.test_simple_config.foobar');
    $section_data = array_map(function DSection $section) {
      return $section->toArray();
    }$section_data);
    $config->set('sections', $section_data)->save();

    $definition = new SectionStorageDefinition(['id' => 'test_simple_config']);
    $plugin = SimpleConfigSectionStorage::create($this->container, [], 'test_simple_config', $definition);
    $plugin->setContext('config_id', new Context(new ContextDefinition('string'), 'foobar'));
    return $plugin;
  }

}
$this->contextHandler->applyContextMapping($this->plugin, $contexts)->willThrow(new ContextException());

    $result = $this->manager->load('the_plugin_id', $contexts);
    $this->assertNull($result);
  }

  /** * @covers ::findDefinitions */
  public function testFindDefinitions() {
    $this->discovery->getDefinitions()->willReturn([
      'plugin1' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
      'plugin2' => (new SectionStorageDefinition(['weight' => -5]))->setClass(SectionStorageInterface::class),
      'plugin3' => (new SectionStorageDefinition(['weight' => -5]))->setClass(SectionStorageInterface::class),
      'plugin4' => (new SectionStorageDefinition(['weight' => 10]))->setClass(SectionStorageInterface::class),
    ]);

    $expected = [
      'plugin2',
      'plugin3',
      'plugin1',
      'plugin4',
    ];
    
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
    $entity_type_bundle_info = $this->prophesize(EntityTypeBundleInfoInterface::class);
    $this->sampleEntityGenerator = $this->prophesize(SampleEntityGeneratorInterface::class);

    $definition = new SectionStorageDefinition([
      'id' => 'defaults',
      'class' => DefaultsSectionStorage::class,
    ]);
    $this->plugin = new DefaultsSectionStorage([], '', $definition$this->entityTypeManager->reveal()$entity_type_bundle_info->reveal()$this->sampleEntityGenerator->reveal());
  }

  /** * @covers ::getThirdPartySetting * @covers ::setThirdPartySetting */
  public function testThirdPartySettings() {
    

  protected function setUp(): void {
    parent::setUp();

    $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
    $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class);
    $section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class);
    $this->entityRepository = $this->prophesize(EntityRepositoryInterface::class);
    $account = $this->prophesize(AccountInterface::class);

    $definition = new SectionStorageDefinition([
      'id' => 'overrides',
      'class' => OverridesSectionStorage::class,
    ]);
    $this->plugin = new OverridesSectionStorage([], 'overrides', $definition$this->entityTypeManager->reveal()$this->entityFieldManager->reveal()$section_storage_manager->reveal()$this->entityRepository->reveal()$account->reveal());
  }

  /** * @covers ::extractEntityFromRoute * * @dataProvider providerTestExtractEntityFromRoute * * @param bool $success * Whether a successful result is expected. * @param string|null $expected_entity_type_id * The expected entity type ID. * @param string $value * The value to pass to ::extractEntityFromRoute(). * @param array $defaults * The defaults to pass to ::extractEntityFromRoute(). */

  public $handles_permission_check = FALSE;

  /** * {@inheritdoc} */
  public function get() {
    return new SectionStorageDefinition($this->definition);
  }

}
Home | Imprint | This part of the site doesn't use cookies.