setTargetType example



  /** * {@inheritdoc} */
  protected function prepareEntity() {
    $definition = $this->entityTypeManager->getDefinition($this->targetEntityTypeId);
    if (!$definition->get('field_ui_base_route') || !$definition->hasViewBuilderClass()) {
      throw new NotFoundHttpException();
    }

    $this->entity->setTargetType($this->targetEntityTypeId);
  }

}
class EntityFormModeAddForm extends EntityDisplayModeAddForm {

  /** * {@inheritdoc} */
  protected function prepareEntity() {
    $definition = $this->entityTypeManager->getDefinition($this->targetEntityTypeId);
    if (!$definition->get('field_ui_base_route') || !$definition->hasFormClasses()) {
      throw new NotFoundHttpException();
    }

    $this->entity->setTargetType($this->targetEntityTypeId);
  }

}
// Some test values.     $bad_target = 'uninitialized';
    $target = 'test_target_type';

    // Gain access to the protected property.     $property = new \ReflectionProperty($mock, 'targetEntityType');
    // Set the property to a known state.     $property->setValue($mock$bad_target);

    // Set the target type.     $mock->setTargetType($target);

    // Test the outcome.     $this->assertNotEquals($bad_target$property->getValue($mock));
    $this->assertEquals($target$property->getValue($mock));
  }

  /** * @covers ::getTargetType */
  public function testGetTargetType() {
    // Generate mock.
Home | Imprint | This part of the site doesn't use cookies.