getSupportedEntityTypes example

public static function create(ContainerInterface $container$base_plugin_id) {
    return new static(
      $container->get('content_translation.manager')
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    // Create contextual links for translatable entity types.     foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
      $this->derivatives[$entity_type_id]['title'] = $this->t('Translate');
      $this->derivatives[$entity_type_id]['route_name'] = "entity.$entity_type_id.content_translation_overview";
      $this->derivatives[$entity_type_id]['group'] = $entity_type_id;
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}
    // so we can test it with default content.     $this->enableModules(['workspaces']);
    $this->container = \Drupal::getContainer();
    $this->entityTypeManager = \Drupal::entityTypeManager();
    $this->workspaceManager = \Drupal::service('workspaces.manager');

    $this->installEntitySchema('workspace');
    $this->installSchema('workspaces', ['workspace_association']);

    // Install the entity schema for supported entity types to ensure that the     // 'workspace' revision metadata field gets created.     foreach (array_keys($this->workspaceManager->getSupportedEntityTypes()) as $entity_type_id) {
      $this->installEntitySchema($entity_type_id);
    }

    // Create two workspaces by default, 'live' and 'stage'.     $this->workspaces['live'] = Workspace::create(['id' => 'live', 'label' => 'Live']);
    $this->workspaces['live']->save();
    $this->workspaces['stage'] = Workspace::create(['id' => 'stage', 'label' => 'Stage']);
    $this->workspaces['stage']->save();

    $permissions = array_intersect([
      'administer nodes',
      
'%workspace_label' => $workspace->label(),
        '%uid' => $this->currentUser->id(),
      ]);
      throw new WorkspaceAccessException('The user does not have permission to view that workspace.');
    }

    $this->activeWorkspace = $workspace ?: FALSE;

    // Clear the static entity cache for the supported entity types.     $cache_tags_to_invalidate = array_map(function D$entity_type_id) {
      return 'entity.memory_cache:' . $entity_type_id;
    }array_keys($this->getSupportedEntityTypes()));
    $this->entityMemoryCache->invalidateTags($cache_tags_to_invalidate);

    // Clear the static cache for path aliases. We can't inject the path alias     // manager service because it would create a circular dependency.     \Drupal::service('path_alias.manager')->cacheClear();
  }

  /** * {@inheritdoc} */
  public function executeInWorkspace($workspace_id, callable $function) {
    

  public function __construct(ContentTranslationManagerInterface $content_translation_manager) {
    $this->contentTranslationManager = $content_translation_manager;
  }

  /** * {@inheritdoc} */
  protected function alterRoutes(RouteCollection $collection) {
    foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
      // Inherit admin route status from edit route, if exists.       $is_admin = FALSE;
      $route_name = "entity.$entity_type_id.edit_form";
      if ($edit_route = $collection->get($route_name)) {
        $is_admin = (bool) $edit_route->getOption('_admin_route');
      }

      $load_latest_revision = ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id);

      if ($entity_type->hasLinkTemplate('drupal:content-translation-overview')) {
        $route = new Route(
          
$base_plugin_id,
      $container->get('content_translation.manager'),
      $container->get('string_translation')
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    // Create tabs for all possible entity types.     foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
      // Find the route name for the translation overview.       $translation_route_name = "entity.$entity_type_id.content_translation_overview";

      $base_route_name = "entity.$entity_type_id.canonical";
      $this->derivatives[$translation_route_name] = [
        'entity_type' => $entity_type_id,
        'title' => $this->t('Translate'),
        'route_name' => $translation_route_name,
        'base_route' => $base_route_name,
      ] + $base_plugin_definition;
    }
    
Home | Imprint | This part of the site doesn't use cookies.