diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php index b79f5e5..426b479 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php @@ -38,8 +38,8 @@ * revision_table = "custom_block_revision", * route_base_path = "admin/structure/block/custom-blocks/manage/{bundle}", * links = { - * "canonical" = "/block/{id}", - * "edit-form" = "/block/{id}" + * "canonical" = "/block/{custom_block}", + * "edit-form" = "/block/{custom_block}" * }, * fieldable = TRUE, * translatable = TRUE, diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 221c3cc..25f1e00 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -88,14 +88,9 @@ function content_translation_entity_info_alter(array &$entity_info) { // shared accross different entities. $info['controllers'] += array('translation' => 'Drupal\content_translation\ContentTranslationController'); - // Provide a standard canonical link if none is defined. - if (!isset($info['links']['canonical'])) { - $info['links']['canonical'] = "/$entity_type/{{$entity_type}}"; - } - // Provide default links for the translation paths. $info['links'] += array( - 'translation-overview' => $info['links']['canonical'] . '/translations', + 'drupal:content-translation-overview' => $info['links']['canonical'] . '/translations', ); if (!isset($info['translation']['content_translation'])) { @@ -497,9 +492,9 @@ function content_translation_set_config($entity_type, $bundle, $setting, $value) */ function content_translation_enabled($entity_type, $bundle = NULL) { $enabled = FALSE; - $info = entity_get_info($entity_type); + $entity_info = entity_get_info($entity_type); - if (!empty($info['translatable'])) { + if (content_translation_supported($entity_type)) { $bundles = !empty($bundle) ? array($bundle) : array_keys(entity_get_bundles($entity_type)); foreach ($bundles as $bundle) { if (content_translation_get_config($entity_type, $bundle, 'enabled')) { @@ -513,32 +508,17 @@ function content_translation_enabled($entity_type, $bundle = NULL) { } /** - * Returns all the translatable entity types. + * Checks whether an entity type supports translation. * - * @return array - * An array of entity types keyed by entity type. + * @param string $entity_type + * The entity type. + * + * @return bool + * TRUE if an entity type is supported, FALSE otherwise. */ -function content_translation_types_translatable() { - $entity_types = &drupal_static(__FUNCTION__, array()); - - foreach (entity_get_info() as $entity_type => $info) { - if (content_translation_enabled($entity_type)) { - // Lazy load router items. - if (!isset($items)) { - $items = menu_get_router(); - } - // Check whether the required paths are defined. We need to strip out the - // menu loader and replace it with a plain "%" as router items have no - // menu loader in them. - $path = _content_translation_link_to_router_path($entity_type, $info['links']['canonical']); - $path = _content_translation_menu_strip_loaders($path); - if (!empty($items[$path]) && !empty($items[$path . '/translations'])) { - $entity_types[$entity_type] = $entity_type; - } - } - } - - return $entity_types; +function content_translation_supported($entity_type) { + $info = entity_get_info($entity_type); + return !empty($info['translatable']) && !empty($info['links']['canonical']); } /** diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc index 8fcda2f..b6473ae 100644 --- a/core/modules/content_translation/content_translation.pages.inc +++ b/core/modules/content_translation/content_translation.pages.inc @@ -26,7 +26,7 @@ function content_translation_overview(EntityInterface $entity) { $field_ui = \Drupal::moduleHandler()->moduleExists('field_ui') && user_access('administer ' . $entity->entityType() . ' fields'); $rel = array(); - foreach (array('canonical', 'edit-form', 'translation-overview') as $name) { + foreach (array('canonical', 'edit-form', 'drupal:content-translation-overview') as $name) { $rel[$name] = $entity->uri($name); } @@ -53,13 +53,13 @@ function content_translation_overview(EntityInterface $entity) { $language_name = $language->name; $langcode = $language->id; - $add_path = $rel['translation-overview']['path'] . '/add/' . $original . '/' . $langcode; - $translate_path = $rel['translation-overview']['path'] . '/edit/' . $langcode; + $add_path = $rel['drupal:content-translation-overview']['path'] . '/add/' . $original . '/' . $langcode; + $translate_path = $rel['drupal:content-translation-overview']['path'] . '/edit/' . $langcode; $add_links = _content_translation_get_switch_links($add_path); $edit_links = _content_translation_get_switch_links($rel['edit-form']['path']); $translate_links = _content_translation_get_switch_links($translate_path); - $delete_links = _content_translation_get_switch_links($rel['translation-overview']['path'] . '/delete/' . $langcode); + $delete_links = _content_translation_get_switch_links($rel['drupal:content-translation-overview']['path'] . '/delete/' . $langcode); $operations = array( 'data' => array( @@ -251,7 +251,7 @@ function content_translation_prepare_translation(EntityInterface $entity, Langua */ function content_translation_delete_confirm(array $form, array $form_state, EntityInterface $entity, Language $language) { $controller = content_translation_controller($entity->entityType()); - $uri = $entity->uri('translation-overview'); + $uri = $entity->uri('drupal:content-translation-overview'); return confirm_form( $form, @@ -282,6 +282,6 @@ function content_translation_delete_confirm_submit(array $form, array &$form_sta \Drupal::service('path.crud')->delete($conditions); } - $uri = $entity->uri('translation-overview'); + $uri = $entity->uri('drupal:content-translation-overview'); $form_state['redirect'] = $uri['path']; } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php index 959c536..a639f30 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php @@ -426,7 +426,7 @@ public function entityFormSourceChange($form, &$form_state) { $entity = $form_controller->getEntity(); $source = $form_state['values']['source_langcode']['source']; - $uri = $entity->uri('translation-overview'); + $uri = $entity->uri('drupal:content-translation-overview'); $path = $uri['path'] . '/add/' . $source . '/' . $form_controller->getFormLangcode($form_state); $form_state['redirect'] = $path; $languages = language_list(); @@ -454,7 +454,7 @@ function entityFormDelete($form, &$form_state) { function entityFormDeleteTranslation($form, &$form_state) { $form_controller = content_translation_form_controller($form_state); $entity = $form_controller->getEntity(); - $uri = $entity->uri('translation-overview'); + $uri = $entity->uri('drupal:content-translation-overview'); $form_langcode = $form_controller->getFormLangcode($form_state); $form_state['redirect'] = $uri['path'] . '/delete/' . $form_langcode; } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationLocalTasks.php b/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationLocalTasks.php index 21c352a..f7da9a7 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationLocalTasks.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationLocalTasks.php @@ -72,7 +72,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) { public function getDerivativeDefinitions(array $base_plugin_definition) { // Create tabs for all possible entity types. foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) { - if ($entity_info['translatable'] && isset($entity_info['translation'])) { + if (!empty($entity_info['translatable'])) { // Find the route name for the translation overview. $translation_route_name = "content_translation.translation_overview_$entity_type"; $translation_tab = $translation_route_name; @@ -92,8 +92,8 @@ public function getDerivativeDefinitions(array $base_plugin_definition) { */ public function alterLocalTasks(array &$local_tasks) { foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) { - if ($entity_info['translatable'] && isset($entity_info['translation'])) { - $path = '/' . preg_replace('/%(.*)/', '{$1}', $entity_info['menu_base_path']); + if (!empty($entity_info['translatable']) && !empty($entity_info['links']['canonical'])) { + $path = $entity_info['links']['canonical']; if ($routes = $this->routeProvider->getRoutesByPattern($path)->all()) { // Find the route name for the entity page. $entity_route_name = key($routes); diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php b/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php index 06bf207..368dc27 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php @@ -39,11 +39,9 @@ public function __construct(EntityManagerInterface $entityManager) { */ protected function routes(RouteCollection $collection) { foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) { - if ($entity_info['translatable'] && isset($entity_info['translation'])) { - // Symfony is using reflections to determine order of parameters for - // Route methods. ContentTranslationController is for all entities so we - // have to replace {$entity_type} and {id} with {entity}. - $path = str_replace(array('{id}', "{{$entity_type}}"), '{entity}', $entity_info['links']['translation-overview']); + if (!empty($entity_info['translatable']) && !empty($entity_info['links']['drupal:content-translation-overview'])) { + $path = $entity_info['links']['drupal:content-translation-overview']; + $route = new Route( $path, array( diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php index 69eeb22..212d427 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php @@ -68,7 +68,7 @@ protected function assertBasicTranslation() { $langcode = 'it'; $values[$langcode] = $this->getNewEntityValues($langcode); - $uri = $entity->uri('translation-overview'); + $uri = $entity->uri('drupal:content-translation-overview'); $path = $langcode . '/' . $uri['path'] . '/add/' . $default_langcode . '/' . $langcode; $this->drupalPostForm($path, $this->getEditValues($values, $langcode), $this->getFormSubmitAction($entity)); if ($this->testLanguageSelector) { @@ -107,8 +107,8 @@ protected function assertBasicTranslation() { */ protected function doTestTranslationOverview() { $entity = entity_load($this->entityType, $this->entityId, TRUE); - $path = $this->controller->getBasePath($entity) . '/translations'; - $this->drupalGet($path); + $uri = $entity->uri('drupal:content-translation-overview'); + $this->drupalGet($uri['path']); foreach ($this->langcodes as $langcode) { if ($entity->hasTranslation($langcode)) { diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationWorkflowsTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationWorkflowsTest.php index 028d87c..0b3da77 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationWorkflowsTest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationWorkflowsTest.php @@ -67,7 +67,7 @@ protected function setupEntity() { // Create a translation. $this->drupalLogin($this->translator); - $uri = $this->entity->uri('translation-overview'); + $uri = $this->entity->uri('drupal:content-translation-overview'); $add_translation_path = $uri['path'] . "/add/$default_langcode/{$this->langcodes[2]}"; $this->drupalPostForm($add_translation_path, array(), t('Save')); $this->rebuildContainer(); @@ -91,7 +91,7 @@ function testWorkflows() { // Check that translation permissions governate the associated operations. $ops = array('create' => t('Add'), 'update' => t('Edit'), 'delete' => t('Delete')); - $uri = $this->entity->uri('translation-overview'); + $uri = $this->entity->uri('drupal:content-translation-overview'); $translations_path = $uri['path']; foreach ($ops as $current_op => $label) { $user = $this->drupalCreateUser(array($this->getTranslatePermission(), "$current_op content translations")); @@ -133,7 +133,7 @@ protected function assertWorkflows(UserInterface $user, $expected_status) { // Check whether the user is allowed to access the translation overview. $langcode = $this->langcodes[1]; - $uri = $this->entity->uri('translation-overview'); + $uri = $this->entity->uri('drupal:content-translation-overview'); $translations_path = $uri['path']; $options = array('language' => $languages[$langcode]); $this->drupalGet($translations_path, $options); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUriTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUriTest.php index ca3d040..381d8b0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUriTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUriTest.php @@ -30,10 +30,10 @@ public function setUp() { */ function testDefaultUri() { // Create a test entity. - $entity = entity_create('entity_test_no_uri', array('name' => 'test', 'user_id' => 1)); + $entity = entity_create('entity_test_no_label', array('name' => 'test', 'user_id' => 1)); $entity->save(); $uri = $entity->uri(); - $expected_path = 'entity/entity_test_no_uri/' . $entity->id(); + $expected_path = 'entity/entity_test_no_label/' . $entity->id(); $this->assertEqual(url($uri['path'], $uri['options']), url($expected_path), 'Entity without URI callback returns expected URI.'); } diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index c8f868e..2348856 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -62,9 +62,6 @@ function entity_test_entity_types($filter = NULL) { */ function entity_test_entity_info_alter(&$info) { foreach (entity_test_entity_types() as $entity_type) { - // Ensure these test entity types use their base path as their edit path. - $info[$entity_type]['menu_edit_path'] = $info[$entity_type]['menu_base_path']; - // Optionally specify a translation handler for testing translations. if (\Drupal::state()->get('entity_test.translation')) { $info[$entity_type]['translation'][$entity_type] = TRUE; diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestCache.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestCache.php index 1e1c114..48d345e 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestCache.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestCache.php @@ -32,10 +32,6 @@ * "id" = "id", * "uuid" = "uuid", * "bundle" = "type" - * }, - * links = { - * "canonical" = "/entity-test/manage/{id}", - * "edit-form" = "/entity-test/manage/{id}" * } * ) */ diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php index b7a1fde..85cad2e 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php @@ -37,7 +37,7 @@ * }, * route_base_path = "entity_test_mul/structure/{bundle}", * links = { - * "canonical" = "/entity_test_mul/{entity_test_mul}", + * "canonical" = "/entity_test_mul/manage/{entity_test_mul}", * "edit-form" = "/entity_test_mul/manage/{entity_test_mul}" * } * ) diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php index a09c871..25887a5 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php @@ -38,8 +38,8 @@ * "bundle" = "type" * }, * links = { - * "canonical" = "/entity_test_mulrev/manage/{id}", - * "edit-form" = "/entity_test_mulrev/manage/{id}" + * "canonical" = "/entity_test_mulrev/manage/{entity_test_mulrev}", + * "edit-form" = "/entity_test_mulrev/manage/{entity_test_mulrev}" * } * ) */ diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestNoUri.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestNoUri.php deleted file mode 100644 index 910ef12..0000000 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestNoUri.php +++ /dev/null @@ -1,40 +0,0 @@ -