pluginId = $plugin_id; $this->pluginDefinition = $plugin_definition; $this->routeProvider = $route_provider; $this->configFactory = $config_factory; $this->typedConfigManager = $typed_config; $this->localeConfigManager = $locale_config_manager; $this->configMapperManager = $config_mapper_manager; $this->stringTranslation = $string_translation; $this->languageManager = $language_manager; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { // Note that we ignore the plugin $configuration because mappers have // nothing to configure in themselves. return new static ( $plugin_id, $plugin_definition, $container->get('config.factory'), $container->get('config.typed'), $container->get('locale.config_manager'), $container->get('plugin.manager.config_translation.mapper'), $container->get('router.route_provider'), $container->get('string_translation'), $container->get('language_manager') ); } /** * {@inheritdoc} */ public function setRouteCollection(RouteCollection $collection) { $this->routeCollection = $collection; } /** * {@inheritdoc} */ public function getTitle() { // A title from a *.config_translation.yml. Should be translated for // display in the current page language. return $this->t($this->pluginDefinition['title']); } /** * {@inheritdoc} */ public function getBaseRouteName() { return $this->pluginDefinition['base_route_name']; } /** * {@inheritdoc} */ public function getBaseRouteParameters() { return []; } /** * {@inheritdoc} */ public function getBaseRoute() { if ($this->routeCollection) { return $this->routeCollection->get($this->getBaseRouteName()); } else { return $this->routeProvider->getRouteByName($this->getBaseRouteName()); } } /** * Allows to process all config translation routes. * * @param \Symfony\Component\Routing\Route $route * The route object to process. */ protected function processRoute(Route $route) { } /** * {@inheritdoc} */ public function getBasePath() { return Url::fromRoute($this->getBaseRouteName(), $this->getBaseRouteParameters())->getInternalPath(); } /** * {@inheritdoc} */ public function getOverviewRouteName() { return 'config_translation.item.overview.' . $this->getBaseRouteName(); } /** * {@inheritdoc} */ public function getOverviewRouteParameters() { return $this->getBaseRouteParameters(); } /** * {@inheritdoc} */ public function getOverviewRoute() { $route = new Route( $this->getBaseRoute()->getPath() . '/translate', [ '_controller' => '\Drupal\config_translation\Controller\ConfigTranslationController::itemPage', 'plugin_id' => $this->getPluginId(), ], ['_config_translation_overview_access' => 'TRUE'] ); $this->processRoute($route); return $route; } /** * {@inheritdoc} */ public function getOverviewPath() { return Url::fromRoute($this->getOverviewRouteName(), $this->getOverviewRouteParameters())->getInternalPath(); } /** * {@inheritdoc} */ public function getAddRouteName() { return 'config_translation.item.add.' . $this->getBaseRouteName(); } /** * {@inheritdoc} */ public function getAddRouteParameters() { // If sub-classes provide route parameters in getBaseRouteParameters(), they // probably also want to provide those for the add, edit, and delete forms. $parameters = $this->getBaseRouteParameters(); $parameters['langcode'] = $this->langcode; return $parameters; } /** * {@inheritdoc} */ public function getAddRoute() { $route = new Route( $this->getBaseRoute()->getPath() . '/translate/{langcode}/add', [ '_form' => '\Drupal\config_translation\Form\ConfigTranslationAddForm', 'plugin_id' => $this->getPluginId(), ], ['_config_translation_form_access' => 'TRUE'] ); $this->processRoute($route); return $route; } /** * {@inheritdoc} */ public function getEditRouteName() { return 'config_translation.item.edit.' . $this->getBaseRouteName(); } /** * {@inheritdoc} */ public function getEditRouteParameters() { return $this->getAddRouteParameters(); } /** * {@inheritdoc} */ public function getEditRoute() { $route = new Route( $this->getBaseRoute()->getPath() . '/translate/{langcode}/edit', [ '_form' => '\Drupal\config_translation\Form\ConfigTranslationEditForm', 'plugin_id' => $this->getPluginId(), ], ['_config_translation_form_access' => 'TRUE'] ); $this->processRoute($route); return $route; } /** * {@inheritdoc} */ public function getDeleteRouteName() { return 'config_translation.item.delete.' . $this->getBaseRouteName(); } /** * {@inheritdoc} */ public function getDeleteRouteParameters() { return $this->getAddRouteParameters(); } /** * {@inheritdoc} */ public function getDeleteRoute() { $route = new Route( $this->getBaseRoute()->getPath() . '/translate/{langcode}/delete', [ '_form' => '\Drupal\config_translation\Form\ConfigTranslationDeleteForm', 'plugin_id' => $this->getPluginId(), ], ['_config_translation_form_access' => 'TRUE'] ); $this->processRoute($route); return $route; } /** * {@inheritdoc} */ public function getConfigNames() { return $this->pluginDefinition['names']; } /** * {@inheritdoc} */ public function addConfigName($name) { $this->pluginDefinition['names'][] = $name; } /** * {@inheritdoc} */ public function getWeight() { return $this->pluginDefinition['weight']; } /** * {@inheritdoc} */ public function populateFromRouteMatch(RouteMatchInterface $route_match) { $this->langcode = $route_match->getParameter('langcode'); } /** * {@inheritdoc} */ public function getTypeLabel() { return $this->getTitle(); } /** * {@inheritdoc} */ public function getLangcode() { $langcodes = array_map([$this, 'getLangcodeFromConfig'], $this->getConfigNames()); if (count(array_unique($langcodes)) > 1) { throw new ConfigMapperLanguageException('A config mapper can only contain configuration for a single language.'); } return reset($langcodes); } /** * {@inheritdoc} */ public function getLangcodeFromConfig($config_name) { // Default to English if no language code was provided in the file. // Although it is a best practice to include a language code, if the // developer did not think about a multilingual use case, we fall back // on assuming the file is English. return $this->configFactory->get($config_name)->get('langcode') ?: 'en'; } /** * {@inheritdoc} */ public function setLangcode($langcode) { $this->langcode = $langcode; return $this; } /** * {@inheritdoc} */ public function getConfigData() { $config_data = []; foreach ($this->getConfigNames() as $name) { $config_data[$name] = $this->configFactory->getEditable($name)->get(); } return $config_data; } /** * {@inheritdoc} */ public function hasSchema() { foreach ($this->getConfigNames() as $name) { if (!$this->typedConfigManager->hasConfigSchema($name)) { return FALSE; } } return TRUE; } /** * {@inheritdoc} */ public function hasTranslatable() { foreach ($this->getConfigNames() as $name) { if ($this->configMapperManager->hasTranslatable($name)) { return TRUE; } } return FALSE; } /** * {@inheritdoc} */ public function hasTranslation(LanguageInterface $language) { foreach ($this->getConfigNames() as $name) { if ($this->localeConfigManager->hasTranslation($name, $language->getId())) { return TRUE; } } return FALSE; } /** * {@inheritdoc} */ public function getTypeName() { return $this->t('Settings'); } /** * {@inheritdoc} */ public function getOperations() { return [ 'translate' => [ 'title' => $this->t('Translate'), 'url' => Url::fromRoute($this->getOverviewRouteName(), $this->getOverviewRouteParameters()), ], ]; } /** * {@inheritdoc} */ public function getContextualLinkGroup() { return NULL; } }