how to setup entity access correctly? How to setup entity access correctly?

i have entity:

/**
 * @ContentEntityType(
 *   id = "test_entity",
 *   bla... let me know if you need detail of this
 *     "route_provider" = { "admin" = "Drupal\test_entity\Entity\TestEntityRouteProvider" },
 *   bla... let me know if you need detail of this
 */


and class TestEntityRouteProvider extends AdminHtmlRouteProvider implements EntityRouteProviderInterface with getRoutes as follow:

$parameters = ['target_type' =&gt; 'test_entity_type', 'target_id' =&gt; ['type' =&gt; 'entity:{test_entity}']];

$route = (new Route('/admin/testing/my-entity/{test_entity}'))
         -&gt;addDefaults([
           '_controller' =&gt; '\Drupal\test_entity\Controller\TestEntityViewController::view',
           '_title_callback' =&gt; '\Drupal\test_entity\Controller\TestEntityViewController::title',
         ])
         -&gt;setOption('parameters', $parameters)
         -&gt;setRequirement('_entity_access', 'test_entity.view');

$route_collection-&gt;add('entity.test_entity.canonical', $route);


i read comments in: EntityAccessCheck:Access, it said:

  /**
   * ... dynamic entity type:
   * example.route:
   *   path: foo/{entity_type}/{example}
   *   requirements:
   *     _entity_access: example.delete
   *   options:
   *     parameters:
   *       example:
   *         type: entity:{entity_type}


question: is my $parameter in class TestEntityRouteProvider correct? i'm not sure if i follow the instruction in comment correctly.

and with my code above, $entity value in EntityAccessCheck:Access is "test_entity-15" as string 

*for reference: "test_entity-15" is referring to my test entity ID the same as in my url: /admin/testing/my-entity/test_entity-15

if ($parameters-&gt;has($entity_type)) {
  $entity = $parameters-&gt;get($entity_type); // &lt;-- value: "test_entity-15"
  if ($entity instanceof EntityInterface) { // will false in here
    return $entity-&gt;access($operation, $account, TRUE); // and didn't reach here
  }
}


and will giving me response:


  403: You are not authorized to access this page.


what am I missing here? let me know if you need my particular part of my code.

Thank You,
You say "i have entity and class TestEntityRouteProvider extends AdminHtmlRouteProvider implements EntityRouteProviderInterface. Normally you don't rewrite all of the route generating code when extending an entity route provider, you only modify some of the routes, rarely the whole set of routes in getRoutes(). But always execute the parent method first. See this example from a core entity type:

&lt;?php

namespace Drupal\aggregator;

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;

/**
 * Provides HTML routes for the feed entity type.
 */
class FeedHtmlRouteProvider extends AdminHtmlRouteProvider {

  /**
   * {@inheritdoc}
   */
  protected function getCanonicalRoute(EntityTypeInterface $entity_type) {
    $route = parent::getCanonicalRoute($entity_type);
    $route-&gt;setDefault('_title_controller', '\Drupal\aggregator\Controller\AggregatorController::feedTitle');

    return $route;
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditFormRoute(EntityTypeInterface $entity_type) {
    $route = parent::getEditFormRoute($entity_type);

    $route-&gt;setDefault('_title', 'Configure');

    return $route;
  }

}


Or if you don't need to modify anything you simply use the standard class for the administration of entity types

  *     "route_provider" = {
  *       "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider",


in the entity type annotations. Is it working then?