getViewBuilderClass example



  /** * Tests that viewing an entity without template does not specify #theme. */
  public function testNoTemplate() {
    // Ensure that an entity type without explicit view builder uses the     // default.     $entity_type_manager = \Drupal::entityTypeManager();
    $entity_type = $entity_type_manager->getDefinition('entity_test_base_field_display');
    $this->assertTrue($entity_type->hasViewBuilderClass());
    $this->assertEquals(EntityViewBuilder::class$entity_type->getViewBuilderClass());

    // Ensure that an entity without matching template does not have a #theme     // key.     $entity = $this->createTestEntity('entity_test');
    $build = $entity_type_manager->getViewBuilder('entity_test')->view($entity);
    $this->assertEquals($entity$build['#entity_test']);
    $this->assertArrayNotHasKey('#theme', $build);
  }

  /** * Tests an entity type with an external canonical rel. */
/** * Tests the getViewBuilderClass() method. */
  public function testGetViewBuilderClass() {
    $controller = $this->getTestHandlerClass();
    $entity_type = $this->setUpEntityType([
      'handlers' => [
        'view_builder' => $controller,
      ],
    ]);
    $this->assertSame($controller$entity_type->getViewBuilderClass());
  }

  /** * @covers ::__construct */
  public function testIdExceedsMaxLength() {
    $id = $this->randomMachineName(33);
    $message = 'Attempt to create an entity type with an ID longer than 32 characters: ' . $id;
    $this->expectException('Drupal\Core\Entity\Exception\EntityTypeIdLengthException');
    $this->expectExceptionMessage($message);
    $this->setUpEntityType(['id' => $id]);
  }
Home | Imprint | This part of the site doesn't use cookies.