getSectionStorageForEntity example


  public function testGetSectionStorageForEntity($entity_type_id$values$expected_context_keys) {
    $section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class);
    $section_storage_manager->load('')->willReturn(NULL);
    $section_storage_manager->findByContext(Argument::cetera())->will(function D$arguments) {
      return $arguments[0];
    });
    $this->container->set('plugin.manager.layout_builder.section_storage', $section_storage_manager->reveal());
    $entity = $this->container->get('entity_type.manager')->getStorage($entity_type_id)->create($values);
    $entity->save();
    $class = new TestLayoutEntityHelperTrait();
    $result = $class->getSectionStorageForEntity($entity);
    $this->assertEquals($expected_context_keysarray_keys($result));
    if ($entity instanceof EntityViewDisplayInterface) {
      $this->assertEquals(EntityContext::fromEntity($entity)$result['display']);
    }
    elseif ($entity instanceof FieldableEntityInterface) {
      $this->assertEquals(EntityContext::fromEntity($entity)$result['entity']);
      $this->assertInstanceOf(Context::class$result['view_mode']);
      $this->assertEquals('full', $result['view_mode']->getContextData()->getValue());

      $expected_display = EntityViewDisplay::collectRenderDisplay($entity, 'full');
      $this->assertInstanceOf(EntityContext::class$result['display']);
      
/** * Determines if an entity can have a layout. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to check. * * @return bool * TRUE if the entity can have a layout otherwise FALSE. */
  protected function isLayoutCompatibleEntity(EntityInterface $entity) {
    return $this->getSectionStorageForEntity($entity) !== NULL;
  }

  /** * Gets revision IDs for layout sections. * * @param \Drupal\layout_builder\Section[] $sections * The layout sections. * * @return int[] * The revision IDs. */
  
Home | Imprint | This part of the site doesn't use cookies.