diff --git a/config_translation.module b/config_translation.module index ded2307..cdc08ca 100644 --- a/config_translation.module +++ b/config_translation.module @@ -24,36 +24,6 @@ function config_translation_help($path) { } /** - * Implements hook_menu(). - */ -function config_translation_menu() { - // Generate translation tabs for keys where a specific path can be - // determined. This makes it possible to use translation features in-context - // of the administration experience. - $config_groups = config_translation_get_groups(); - foreach ($config_groups as $group) { - $path = $group->getBasePath(); - if ($group->needsEditTab()) { - // For pages that do not have a default tab, we need a default local task - // on this level, so that the translate tab will show up. - $items[$path . '/edit'] = array( - 'title' => 'Edit', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -100, - ); - } - $items[$path . '/translate'] = array( - 'title' => 'Translate', - 'route_name' => $group->getRouteName(), - 'type' => $group->getMenuItemType(), - 'weight' => 100, - ); - } - - return $items; -} - -/** * Implements hook_permission(). */ function config_translation_permission() { diff --git a/lib/Drupal/config_translation/Plugin/Derivative/EditLocalTask.php b/lib/Drupal/config_translation/Plugin/Derivative/EditLocalTask.php new file mode 100644 index 0000000..e1d0e9a --- /dev/null +++ b/lib/Drupal/config_translation/Plugin/Derivative/EditLocalTask.php @@ -0,0 +1,60 @@ +routeProvider = \Drupal::service('router.route_provider'); + } + + /** + * {@inheritdoc} + */ + public function getDerivativeDefinitions(array $base_plugin_definition) { + $this->derivatives = array(); + + $config_groups = config_translation_get_groups(); + foreach ($config_groups as $group) { + if ($group->needsEditTab() && $type = $group->getType()) { + // Get the route the task is attached to. + // @todo Note this just works for routes, so the patch has to wait + // until all parents are converted to routes? + $path = $group->getBasePath(); + $pattern = str_replace('%', '{}', $path); + foreach ($this->routeProvider->getRoutesByPattern('/' . $pattern) as $name => $route) { + $this->derivatives[$type] = array( + 'title' => 'Edit', + 'route_name' => $name, + 'weight' => -100, + 'tab_root_id' => 'config_translation_edit:' . $type, + ); + break; + } + } + } + return $this->derivatives; + } + +} diff --git a/lib/Drupal/config_translation/Plugin/Derivative/TranslateLocalTask.php b/lib/Drupal/config_translation/Plugin/Derivative/TranslateLocalTask.php new file mode 100644 index 0000000..c75bde6 --- /dev/null +++ b/lib/Drupal/config_translation/Plugin/Derivative/TranslateLocalTask.php @@ -0,0 +1,61 @@ +routeProvider = \Drupal::service('router.route_provider'); + } + + /** + * {@inheritdoc} + */ + public function getDerivativeDefinitions(array $base_plugin_definition) { + $this->derivatives = array(); + + $config_groups = config_translation_get_groups(); + foreach ($config_groups as $group) { + if ($group->getMenuItemType() == MENU_LOCAL_TASK) { + $this->derivatives[$group->getType()] = array( + 'title' => 'Translate', + 'route_name' => $group->getRouteName(), + 'weight' => 100, + 'class' => 'Drupal\config_translation\Plugin\Menu\LocalTask\TranslateLocalTask', + ); + // The edit tab is probably the default task, of which the ID is known. + // @see \Drupal\config_translation\Plugin\Derivative\EditLocalTask + if ($group->needsEditTab()) { + $this->derivatives[$group->getType()]['tab_root_id'] = 'config_translation_translate:' . $group->getType(); + } + else { + // @Fixme Get the local task plugin from the parent from the group + // definition. + $this->derivatives[$group->getType()]['tab_root_id'] = ''; + } + } + } + return $this->derivatives; + } +} diff --git a/lib/Drupal/config_translation/Plugin/Menu/LocalTask/EditLocalTask.php b/lib/Drupal/config_translation/Plugin/Menu/LocalTask/EditLocalTask.php new file mode 100644 index 0000000..d92f87e --- /dev/null +++ b/lib/Drupal/config_translation/Plugin/Menu/LocalTask/EditLocalTask.php @@ -0,0 +1,23 @@ +