getRouteProviderClasses example

->setStringTranslation($this->stringTranslation)
      ->setModuleHandler($this->moduleHandler)
      ->setEntityTypeManager($this)
      ->setOperation($operation);
  }

  /** * {@inheritdoc} */
  public function getRouteProviders($entity_type_id) {
    if (!isset($this->handlers['route_provider'][$entity_type_id])) {
      $route_provider_classes = $this->getDefinition($entity_type_id, TRUE)->getRouteProviderClasses();

      foreach ($route_provider_classes as $type => $class) {
        $this->handlers['route_provider'][$entity_type_id][$type] = $this->createHandlerInstance($class$this->getDefinition($entity_type_id));
      }
    }

    return $this->handlers['route_provider'][$entity_type_id] ?? [];
  }

  /** * {@inheritdoc} */
$entity->getHandlerClass('storage')->willReturn('');
    $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]);
    $this->expectException(InvalidPluginDefinitionException::class);
    $this->entityTypeManager->getHandler('test_entity_type', 'storage');
  }

  /** * @covers ::getRouteProviders */
  public function testGetRouteProviders() {
    $apple = $this->prophesize(EntityTypeInterface::class);
    $apple->getRouteProviderClasses()->willReturn(['default' => TestRouteProvider::class]);

    $this->setUpEntityTypeDefinitions([
      'apple' => $apple,
    ]);

    $apple_route_provider = $this->entityTypeManager->getRouteProviders('apple');
    $this->assertInstanceOf(TestRouteProvider::class$apple_route_provider['default']);
    $this->assertInstanceOf(ModuleHandlerInterface::class$apple_route_provider['default']->moduleHandler);
    $this->assertInstanceOf(TranslationInterface::class$apple_route_provider['default']->stringTranslation);
  }

  

  protected function addModerationToEntityType(ContentEntityTypeInterface $type) {
    if (!$type->hasHandlerClass('moderation')) {
      $handler_class = !empty($this->moderationHandlers[$type->id()]) ? $this->moderationHandlers[$type->id()] : ModerationHandler::class;
      $type->setHandlerClass('moderation', $handler_class);
    }

    if (!$type->hasLinkTemplate('latest-version') && $type->hasLinkTemplate('canonical')) {
      $type->setLinkTemplate('latest-version', $type->getLinkTemplate('canonical') . '/latest');
    }

    $providers = $type->getRouteProviderClasses() ?: [];
    if (empty($providers['moderation'])) {
      $providers['moderation'] = EntityModerationRouteProvider::class;
      $type->setHandlerClass('route_provider', $providers);
    }

    return $type;
  }

  /** * Gets the "extra fields" for a bundle. * * @return array * A nested array of 'pseudo-field' elements. Each list is nested within the * following keys: entity type, bundle name, context (either 'form' or * 'display'). The keys are the name of the elements as appearing in the * renderable array (either the entity form or the displayed entity). The * value is an associative array: * - label: The human readable name of the element. Make sure you sanitize * this appropriately. * - description: A short description of the element contents. * - weight: The default weight of the element. * - visible: (optional) The default visibility of the element. Defaults to * TRUE. * - edit: (optional) String containing markup (normally a link) used as the * element's 'edit' operation in the administration interface. Only for * 'form' context. * - delete: (optional) String containing markup (normally a link) used as * the element's 'delete' operation in the administration interface. Only * for 'form' context. * * @see hook_entity_extra_field_info() */
Home | Imprint | This part of the site doesn't use cookies.