getCanonicalRoute example

/** * @covers ::getCanonicalRoute * @dataProvider providerTestGetCanonicalRoute */
  public function testGetCanonicalRoute(Route $expected = NULL, EntityTypeInterface $entity_type, FieldStorageDefinitionInterface $field_storage_definition = NULL) {
    if ($field_storage_definition) {
      $this->entityFieldManager->getFieldStorageDefinitions($entity_type->id())
        ->willReturn([$entity_type->getKey('id') => $field_storage_definition]);
    }

    $route = $this->routeProvider->getCanonicalRoute($entity_type);
    $this->assertEquals($expected$route);
  }

  public static function providerTestGetCanonicalRoute() {
    $prophet = new Prophet();
    $data = [];

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

    
$container->get('entity_type.manager'),
      $container->get('entity_field.manager'),
      $container->get('config.factory')
    );
  }

  /** * {@inheritdoc} */
  protected function getCanonicalRoute(EntityTypeInterface $entity_type) {
    if ($this->config->get('standalone_url')) {
      return parent::getCanonicalRoute($entity_type);
    }
    else {
      return parent::getEditFormRoute($entity_type);
    }
  }

}
$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);
    }

    if ($edit_route = $this->getEditFormRoute($entity_type)) {
      $collection->add("entity.{$entity_type_id}.edit_form", $edit_route);
    }

    if ($delete_route = $this->getDeleteFormRoute($entity_type)) {
      $collection->add("entity.{$entity_type_id}.delete_form", $delete_route);
    }

    
Home | Imprint | This part of the site doesn't use cookies.