deriveContextsFromRoute example

$converter = new LayoutSectionStorageParamConverter($section_storage_manager->reveal());

    $section_storage = $this->prophesize(SectionStorageInterface::class);

    $value = 'some_value';
    $definition = ['layout_builder_tempstore' => TRUE];
    $name = 'the_parameter_name';
    $defaults = ['section_storage_type' => 'my_type'];

    $section_storage_manager->hasDefinition('my_type')->willReturn(TRUE);
    $section_storage_manager->loadEmpty('my_type')->willReturn($section_storage->reveal());
    $section_storage->deriveContextsFromRoute($value$definition$name$defaults)->willReturn([]);
    $section_storage_manager->load('my_type', [])->willReturn($section_storage->reveal());

    $result = $converter->convert($value$definition$name$defaults);
    $this->assertSame($section_storage->reveal()$result);
  }

  /** * @covers ::convert */
  public function testConvertNoType() {
    $section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class);
    
'status' => TRUE,
    ]);
    $display
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    $entity = EntityTest::create();
    $entity->save();
    $entity = EntityTest::load($entity->id());

    $result = $this->plugin->deriveContextsFromRoute('entity_test.1', [], '', []);
    $this->assertSame(['entity', 'view_mode']array_keys($result));
    $this->assertSame($entity$result['entity']->getContextValue());
    $this->assertSame('default', $result['view_mode']->getContextValue());
  }

  /** * @covers ::isOverridden */
  public function testIsOverridden() {
    $display = LayoutBuilderEntityViewDisplay::create([
      'targetEntityType' => 'entity_test',
      
/** * {@inheritdoc} */
  public function convert($value$definition$name, array $defaults) {
    // If no section storage type is specified or if it is invalid, return.     if (!isset($defaults['section_storage_type']) || !$this->sectionStorageManager->hasDefinition($defaults['section_storage_type'])) {
      return NULL;
    }

    $type = $defaults['section_storage_type'];
    // Load an empty instance and derive the available contexts.     $contexts = $this->sectionStorageManager->loadEmpty($type)->deriveContextsFromRoute($value$definition$name$defaults);
    // Attempt to load a full instance based on the context.     return $this->sectionStorageManager->load($type$contexts);
  }

  /** * {@inheritdoc} */
  public function applies($definition$name, Route $route) {
    return !empty($definition['layout_builder_section_storage']) || !empty($definition['layout_builder_tempstore']);
  }

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