getAddPageRoute example


class AdminHtmlRouteProvider extends DefaultHtmlRouteProvider {

  /** * {@inheritdoc} */
  protected function getAddPageRoute(EntityTypeInterface $entity_type) {
    if ($route = parent::getAddPageRoute($entity_type)) {
      $route->setOption('_admin_route', TRUE);
      return $route;
    }
  }

  /** * {@inheritdoc} */
  protected function getAddFormRoute(EntityTypeInterface $entity_type) {
    if ($route = parent::getAddFormRoute($entity_type)) {
      $route->setOption('_admin_route', TRUE);
      

  }

  /** * {@inheritdoc} */
  public function getRoutes(EntityTypeInterface $entity_type) {
    $collection = new RouteCollection();

    $entity_type_id = $entity_type->id();

    if ($add_page_route = $this->getAddPageRoute($entity_type)) {
      $collection->add("entity.{$entity_type_id}.add_page", $add_page_route);
    }

    if ($add_form_route = $this->getAddFormRoute($entity_type)) {
      $collection->add("entity.{$entity_type_id}.add_form", $add_form_route);
    }

    if ($canonical_route = $this->getCanonicalRoute($entity_type)) {
      $collection->add("entity.{$entity_type_id}.canonical", $canonical_route);
    }

    
$this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
    $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class);

    $this->routeProvider = new TestDefaultHtmlRouteProvider($this->entityTypeManager->reveal()$this->entityFieldManager->reveal());
  }

  /** * @covers ::getAddPageRoute * @dataProvider providerTestGetAddPageRoute */
  public function testGetAddPageRoute(Route $expected = NULL, EntityTypeInterface $entity_type) {
    $route = $this->routeProvider->getAddPageRoute($entity_type);
    $this->assertEquals($expected$route);
  }

  public static function providerTestGetAddPageRoute() {
    $data = [];

    $entity_type1 = static::getEntityType();
    $entity_type1->hasLinkTemplate('add-page')->willReturn(FALSE);
    $data['no_add_page_link_template'] = [NULL, $entity_type1->reveal()];

    $entity_type2 = static::getEntityType();
    
Home | Imprint | This part of the site doesn't use cookies.