Chris@0: setType($plugin_definition['entity_type']); Chris@0: Chris@0: $this->entityManager = $entity_manager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { Chris@0: // Note that we ignore the plugin $configuration because mappers have Chris@0: // nothing to configure in themselves. Chris@0: return new static ( Chris@0: $plugin_id, Chris@0: $plugin_definition, Chris@0: $container->get('config.factory'), Chris@0: $container->get('config.typed'), Chris@0: $container->get('locale.config_manager'), Chris@0: $container->get('plugin.manager.config_translation.mapper'), Chris@0: $container->get('router.route_provider'), Chris@0: $container->get('string_translation'), Chris@0: $container->get('entity.manager'), Chris@17: $container->get('language_manager'), Chris@17: $container->get('event_dispatcher') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function populateFromRouteMatch(RouteMatchInterface $route_match) { Chris@0: $entity = $route_match->getParameter($this->entityType); Chris@0: $this->setEntity($entity); Chris@17: parent::populateFromRouteMatch($route_match); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the entity instance for this mapper. Chris@0: * Chris@0: * @return \Drupal\Core\Config\Entity\ConfigEntityInterface Chris@0: * The configuration entity. Chris@0: */ Chris@0: public function getEntity() { Chris@0: return $this->entity; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the entity instance for this mapper. Chris@0: * Chris@0: * This method can only be invoked when the concrete entity is known, that is Chris@0: * in a request for an entity translation path. After this method is called, Chris@0: * the mapper is fully populated with the proper display title and Chris@0: * configuration names to use to check permissions or display a translation Chris@0: * screen. Chris@0: * Chris@0: * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity Chris@0: * The configuration entity to set. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE, if the entity was set successfully; FALSE otherwise. Chris@0: */ Chris@0: public function setEntity(ConfigEntityInterface $entity) { Chris@0: if (isset($this->entity)) { Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: $this->entity = $entity; Chris@0: Chris@0: // Add the list of configuration IDs belonging to this entity. We add on a Chris@0: // possibly existing list of names. This allows modules to alter the entity Chris@0: // page with more names if form altering added more configuration to an Chris@0: // entity. This is not a Drupal 8 best practice (ideally the configuration Chris@0: // would have pluggable components), but this may happen as well. Chris@0: /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type_info */ Chris@0: $entity_type_info = $this->entityManager->getDefinition($this->entityType); Chris@0: $this->addConfigName($entity_type_info->getConfigPrefix() . '.' . $entity->id()); Chris@0: Chris@0: return TRUE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getTitle() { Chris@0: return $this->entity->label() . ' ' . $this->pluginDefinition['title']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getBaseRouteParameters() { Chris@0: return [$this->entityType => $this->entity->id()]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set entity type for this mapper. Chris@0: * Chris@0: * This should be set in initialization. A mapper that knows its type but Chris@0: * not yet its names is still useful for router item and tab generation. The Chris@0: * concrete entity only turns out later with actual controller invocations, Chris@0: * when the setEntity() method is invoked before the rest of the methods are Chris@0: * used. Chris@0: * Chris@0: * @param string $entity_type Chris@0: * The entity type to set. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the entity type was set correctly; FALSE otherwise. Chris@0: */ Chris@0: public function setType($entity_type) { Chris@0: if (isset($this->entityType)) { Chris@0: return FALSE; Chris@0: } Chris@0: $this->entityType = $entity_type; Chris@0: return TRUE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the entity type from this mapper. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getType() { Chris@0: return $this->entityType; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getTypeName() { Chris@0: $entity_type_info = $this->entityManager->getDefinition($this->entityType); Chris@0: return $entity_type_info->getLabel(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getTypeLabel() { Chris@0: $entityType = $this->entityManager->getDefinition($this->entityType); Chris@0: return $entityType->getLabel(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getOperations() { Chris@0: return [ Chris@0: 'list' => [ Chris@0: 'title' => $this->t('List'), Chris@0: 'url' => Url::fromRoute('config_translation.entity_list', [ Chris@0: 'mapper_id' => $this->getPluginId(), Chris@0: ]), Chris@0: ], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getContextualLinkGroup() { Chris@0: // @todo Contextual groups do not map to entity types in a predictable Chris@0: // way. See https://www.drupal.org/node/2134841 to make them predictable. Chris@0: switch ($this->entityType) { Chris@0: case 'menu': Chris@0: case 'block': Chris@0: return $this->entityType; Chris@0: case 'view': Chris@0: return 'entity.view.edit_form'; Chris@0: default: Chris@0: return NULL; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getOverviewRouteName() { Chris@0: return 'entity.' . $this->entityType . '.config_translation_overview'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function processRoute(Route $route) { Chris@0: // Add entity upcasting information. Chris@0: $parameters = $route->getOption('parameters') ?: []; Chris@0: $parameters += [ Chris@0: $this->entityType => [ Chris@0: 'type' => 'entity:' . $this->entityType, Chris@17: ], Chris@0: ]; Chris@0: $route->setOption('parameters', $parameters); Chris@0: } Chris@0: Chris@0: }