getEntityFromRouteMatch example


  protected function getFormObject(RouteMatchInterface $route_match$form_arg) {
    // If no operation is provided, use 'default'.     $form_arg .= '.default';
    [$entity_type_id$operation] = explode('.', $form_arg);

    $form_object = $this->entityTypeManager->getFormObject($entity_type_id$operation);

    // Allow the entity form to determine the entity object from a given route     // match.     $entity = $form_object->getEntityFromRouteMatch($route_match$entity_type_id);
    $form_object->setEntity($entity);

    return $form_object;
  }

}

  public function testGetEntityFromRouteMatchEditDelete() {
    $entity = $this->prophesize(EntityInterface::class)->reveal();
    $id = $this->entityType->id();
    $route_match = new RouteMatch(
      'test_route',
      new Route('/entity-test/manage/{' . $id . '}/edit'),
      [$id => $entity],
      [$id => 1]
    );
    $actual = $this->entityForm->getEntityFromRouteMatch($route_match$id);
    $this->assertEquals($entity$actual);
  }

  /** * Tests EntityForm::getEntityFromRouteMatch() for add forms without a bundle. * * @covers ::getEntityFromRouteMatch */
  public function testGetEntityFromRouteMatchAdd() {
    $entity = $this->prophesize(EntityInterface::class)->reveal();
    $this->setUpStorage()->create([])->willReturn($entity);
    
Home | Imprint | This part of the site doesn't use cookies.