diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php index 9e94728..e321bb2 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php @@ -17,7 +17,7 @@ class PathLanguageTest extends PathTestBase { * * @var array */ - public static $modules = array('path', 'locale', 'translation'); + public static $modules = array('path', 'locale', 'content_translation'); public static function getInfo() { return array( @@ -30,8 +30,20 @@ public static function getInfo() { function setUp() { parent::setUp(); + $permissions = array( + 'edit any page content', + 'create page content', + 'administer url aliases', + 'create url aliases', + 'administer languages', + 'access administration pages', + 'administer content types', + 'create content translations', + 'administer content translation', + 'translate any entity' + ); // Create and login user. - $this->web_user = $this->drupalCreateUser(array('edit any page content', 'create page content', 'administer url aliases', 'create url aliases', 'administer languages', 'translate all content', 'access administration pages', 'administer content types')); + $this->web_user = $this->drupalCreateUser($permissions); $this->drupalLogin($this->web_user); // Enable French language. @@ -43,6 +55,11 @@ function setUp() { // Enable URL language detection and selection. $edit = array('language_interface[enabled][language-url]' => 1); $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); + + // Enable translation for page node. + $edit = array('entity_types[node]' => 1, 'settings[node][page][translatable]' => 1, 'settings[node][page][fields][body]' => 1, 'settings[node][page][settings][language][language_show]' => 1); + $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save')); + } /** @@ -57,12 +74,11 @@ function testAliasTranslation() { $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.'); variable_set('node_type_language_translation_enabled_page', TRUE); - $english_node = $this->drupalCreateNode(array('type' => 'page')); + $english_node = $this->drupalCreateNode(array('type' => 'page', 'langcode' => 'en')); $english_alias = $this->randomName(); // Edit the node to set language and path. $edit = array(); - $edit['langcode'] = 'en'; $edit['path[alias]'] = $english_alias; $this->drupalPostForm('node/' . $english_node->id() . '/edit', $edit, t('Save')); @@ -71,8 +87,9 @@ function testAliasTranslation() { $this->assertText($english_node->label(), 'Alias works.'); // Translate the node into French. - $this->drupalGet('node/' . $english_node->id() . '/translate'); - $this->clickLink(t('Add translation')); + $this->drupalGet('node/' . $english_node->id() . '/translations'); + $this->clickLink(t('Add')); + $edit = array(); $edit['title'] = $this->randomName(); $edit['body[0][value]'] = $this->randomName(); @@ -89,7 +106,8 @@ function testAliasTranslation() { $languages = language_list(); // Ensure the node was created. - $french_node = $this->drupalGetNodeByTitle($edit["title"]); + $french_node = $english_node->getTranslation('fr'); + $this->assertTrue(($french_node), 'Node found in database.'); // Confirm that the alias works. @@ -97,7 +115,7 @@ function testAliasTranslation() { $this->assertText($french_node->label(), 'Alias for French translation works.'); // Confirm that the alias is returned by url(). - $url = $this->container->get('url_generator')->generateFromPath('node/' . $french_node->id(), array('language' => $languages[$french_node->language()->id])); + $url = $this->container->get('url_generator')->generateFromPath('node/' . $french_node->id(), array('language' => $languages['fr'])); $this->assertTrue(strpos($url, $edit['path[alias]']), 'URL contains the path alias.'); @@ -148,17 +166,17 @@ function testAliasTranslation() { // The alias manager has an internal path lookup cache. Check to see that // it has the appropriate contents at this point. $this->container->get('path.alias_manager')->cacheClear(); - $french_node_path = $this->container->get('path.alias_manager')->getSystemPath($french_alias, $french_node->language()->id); + $french_node_path = $this->container->get('path.alias_manager')->getSystemPath($french_alias, 'fr'); $this->assertEqual($french_node_path, 'node/' . $french_node->id(), 'Normal path works.'); // Second call should return the same path. - $french_node_path = $this->container->get('path.alias_manager')->getSystemPath($french_alias, $french_node->language()->id); + $french_node_path = $this->container->get('path.alias_manager')->getSystemPath($french_alias, 'fr'); $this->assertEqual($french_node_path, 'node/' . $french_node->id(), 'Normal path is the same.'); // Confirm that the alias works. - $french_node_alias = $this->container->get('path.alias_manager')->getPathAlias('node/' . $french_node->id(), $french_node->language()->id); + $french_node_alias = $this->container->get('path.alias_manager')->getPathAlias('node/' . $french_node->id(), 'fr'); $this->assertEqual($french_node_alias, $french_alias, 'Alias works.'); // Second call should return the same alias. - $french_node_alias = $this->container->get('path.alias_manager')->getPathAlias('node/' . $french_node->id(), $french_node->language()->id); + $french_node_alias = $this->container->get('path.alias_manager')->getPathAlias('node/' . $french_node->id(), 'fr'); $this->assertEqual($french_node_alias, $french_alias, 'Alias is the same.'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php index 2fba93f6..df27013 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -82,18 +82,10 @@ public function testLanguageUpgrade() { // Test that the 'language' property was properly renamed to 'langcode'. $language_none_nid = 50; $spanish_nid = 51; - $translation_source_nid = 52; - $translation_nid = 53; // Check directly for the node langcode. $this->assertEqual(node_load($language_none_nid)->language()->id, Language::LANGCODE_NOT_SPECIFIED, "'language' property was renamed to 'langcode' for Language::LANGCODE_NOT_SPECIFIED node."); $this->assertEqual(node_load($spanish_nid)->language()->id, 'ca', "'language' property was renamed to 'langcode' for Catalan node."); - // Check that the translation table works correctly. - $this->drupalGet("node/$translation_source_nid/translate"); - $this->assertResponse(200, 'The translated node has a proper translation table.'); - $this->assertRaw('
' . t('The Content Translation module allows content to be translated into different languages. Working with the Locale module (which manages enabled languages and provides translation for the site interface), the Content Translation module is key to creating and maintaining translated site content. For more information, see the online handbook entry for Content Translation module.', array('@locale' => url('admin/help/locale'), '@translation' => 'http://drupal.org/documentation/modules/translation/')) . '
'; - $output .= '' . t('Translations of a piece of content are managed with translation sets. Each translation set has one source post and any number of translations in any of the enabled languages. All translations are tracked to be up to date or outdated based on whether the source post was modified significantly.', array('!languages' => url('admin/config/regional/language'))) . '
'; - return $output; - } -} - -/** - * Implements hook_menu(). - */ -function translation_menu() { - $items = array(); - $items['node/%node/translate'] = array( - 'title' => 'Translate', - 'route_name' => 'translation.node_overview', - 'type' => MENU_LOCAL_TASK, - 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, - 'weight' => 2, - ); - return $items; -} - -/** - * Access callback: Checks that the user has permission to 'translate - * all content' or to 'translate own content' and has created the node - * being translated. - * - * Only displays the translation tab for nodes that are not language-neutral - * of types that have translation enabled. - * - * @param $node - * A node entity. - * - * @return - * TRUE if the translation tab should be displayed, FALSE otherwise. - * - * @see translation_menu() - */ -function _translation_tab_access(NodeInterface $node) { - if ($node->language()->id != Language::LANGCODE_NOT_SPECIFIED && translation_supported_type($node->getType()) && node_access('view', $node)) { - return translation_user_can_translate_node($node); - } - return FALSE; -} - -/** - * Implements hook_admin_paths(). - */ -function translation_admin_paths() { - if (\Drupal::config('node.settings')->get('use_admin_theme')) { - $paths = array( - 'node/*/translate' => TRUE, - ); - return $paths; - } -} - -/** - * Implements hook_permission(). - */ -function translation_permission() { - return array( - 'translate all content' => array( - 'title' => t('Translate all content'), - ), - 'translate own content' => array( - 'title' => t('Translate own content'), - ), - ); -} - -/** - * Implements hook_node_create_access(). - */ -function translation_node_create_access($account) { - $query = \Drupal::request()->query; - $translation = $query->get('translation'); - $target = $query->get('target'); - $request_has_translation_arg = !empty($translation) && !empty($target) && is_numeric($translation); - if ($request_has_translation_arg) { - $source_node = node_load($translation); - if (empty($source_node) || !translation_user_can_translate_node($source_node, $account)){ - return NODE_ACCESS_DENY; - } - } - - return NODE_ACCESS_IGNORE; -} - -/** - * Check if the user has permissions to translate a node. - * - * @param $node - * Node being checked. - * @param $account - * User object to check translation permissions. - * - * @return - * TRUE if the user can translate a node, FALSE otherwise. - */ -function translation_user_can_translate_node($node, $account = NULL) { - // If no user object is supplied, the access check is for the current user. - if (empty($account)) { - $account = \Drupal::currentUser(); - } - return node_access('view', $node, $account) && (user_access('translate all content', $account) || ($node->getAuthorId() == $account->id() && user_access('translate own content', $account))); -} - -/** - * Implements hook_form_FORM_ID_alter() for node_type_form(). - */ -function translation_form_node_type_form_alter(&$form, &$form_state) { - // Hide form element if default language is a constant. - // TODO: When form #states allows OR values change this to use form #states. - $form['#attached']['library'][] = array('translation', 'drupal.translation'); - // Add translation option to content type form. - $form['language']['node_type_language_translation_enabled'] = array( - '#type' => 'checkbox', - '#title' => t('Enable translation'), - '#default_value' => variable_get('node_type_language_translation_enabled_' . $form_state['controller']->getEntity()->id(), FALSE), - '#element_validate' => array('translation_node_type_language_translation_enabled_validate'), - '#prefix' => "", - ); -} - -/** - * Checks if translation can be enabled. - * - * If language is set to one of the special languages - * and language selector is not hidden, translation cannot be enabled. - */ -function translation_node_type_language_translation_enabled_validate($element, &$form_state, $form) { - if (language_is_locked($form_state['values']['language_configuration']['langcode']) && !$form_state['values']['language_configuration']['language_show'] && $form_state['values']['node_type_language_translation_enabled']) { - foreach (language_list(Language::STATE_LOCKED) as $language) { - $locked_languages[] = $language->name; - } - form_set_error('node_type_language_translation_enabled', t('Translation is not supported if language is always one of: @locked_languages', array('@locked_languages' => implode(", ", $locked_languages)))); - } -} - -/** - * Implements hook_form_BASE_FORM_ID_alter() for node_form(). - * - * Alters language fields on node edit forms when a translation is about to be - * created. - * - * @see node_form() - */ -function translation_form_node_form_alter(&$form, &$form_state) { - $node = $form_state['controller']->getEntity(); - if (translation_supported_type($node->getType())) { - if (!empty($node->translation_source)) { - // We are creating a translation. Lock language field. - $form['langcode']['#disabled'] = TRUE; - } - elseif (!$node->isNew() && $node->tnid->value) { - // Disable languages for existing translations, so it is not possible - // to switch this node to some language which is already in the - // translation set. Also remove the language neutral option. - unset($form['langcode']['#options'][Language::LANGCODE_NOT_SPECIFIED]); - foreach (translation_node_get_translations($node->tnid->value) as $langcode => $translation) { - if ($translation->nid != $node->id()) { - unset($form['langcode']['#options'][$langcode]); - } - } - // Add translation values and workflow options. - $form['translation'] = array( - '#type' => 'details', - '#title' => t('Translation settings'), - '#access' => translation_user_can_translate_node($node), - '#collapsed' => !$node->translate->value, - '#tree' => TRUE, - '#weight' => 30, - ); - if ($node->tnid->value == $node->id()) { - // This is the source node of the translation. - $form['translation']['retranslate'] = array( - '#type' => 'checkbox', - '#title' => t('Flag translations as outdated'), - '#default_value' => 0, - '#description' => t('If you made a significant change, which means translations should be updated, you can flag all translations of this post as outdated. This will not change any other property of those posts, like whether they are published or not.'), - ); - $form['translation']['status'] = array('#type' => 'value', '#value' => 0); - } - else { - $form['translation']['status'] = array( - '#type' => 'checkbox', - '#title' => t('This translation needs to be updated'), - '#default_value' => $node->translate->value, - '#description' => t('When this option is checked, this translation needs to be updated because the source post has changed. Uncheck when the translation is up to date again.'), - ); - } - $form['#entity_builders'][] = 'translation_node_builder'; - } - } -} - -/** - * Entity form builder to add translation metadata to the node. - * - * @todo: Remove this in favor of an entity field. - */ -function translation_node_builder($entity_type, $entity, &$form, &$form_state) { - if (isset($form_state['values']['translation'])) { - $entity->translation = $form_state['values']['translation']; - } -} - -/** - * Implements hook_node_view(). - * - * Displays translation links with language names if this node is part of a - * translation set. If no language provider is enabled, "fall back" to simple - * links built through the result of translation_node_get_translations(). - */ -function translation_node_view(EntityInterface $node, EntityDisplay $display, $view_mode) { - // If the site has no translations or is not multilingual we have no content - // translation links to display. - if ($node->tnid->value && language_multilingual() && $translations = translation_node_get_translations($node->tnid->value)) { - $languages = language_list(Language::STATE_ALL); - - // There might be a language provider enabled defining custom language - // switch links which need to be taken into account while generating the - // content translation links. As custom language switch links are available - // only for configurable language types and interface language is the only - // configurable language type in core, we use it as default. Contributed - // modules can change this behavior by setting the system variable below. - $type = \Drupal::config('translation.settings')->get('language_type'); - $custom_links = language_negotiation_get_switch_links($type, 'node/' . $node->id()); - $links = array(); - - foreach ($translations as $langcode => $translation) { - // Do not show links to the same node or to unpublished translations. - if ($translation->status && isset($languages[$langcode]) && $langcode != $node->language()->id) { - $key = "translation_$langcode"; - - if (isset($custom_links->links[$langcode])) { - $links[$key] = $custom_links->links[$langcode]; - } - else { - $links[$key] = array( - 'href' => "node/{$translation->nid}", - 'title' => language_name($langcode), - 'language' => $languages[$langcode], - ); - } - - // Custom switch links are more generic than content translation links, - // hence we override existing attributes with the ones below. - $links[$key] += array('attributes' => array()); - $attributes = array( - 'title' => $translation->title, - 'class' => array('translation-link'), - ); - $links[$key]['attributes'] = $attributes + $links[$key]['attributes']; - } - } - - $node->content['links']['translation'] = array( - '#theme' => 'links__node__translation', - '#links' => $links, - '#attributes' => array('class' => array('links', 'inline')), - ); - } -} - -/** - * Implements hook_node_prepare_form(). - */ -function translation_node_prepare_form(NodeInterface $node, $form_display, $operation, array &$form_state) { - $query = \Drupal::request()->query; - $translation = $query->get('translation'); - $target = $query->get('target'); - // Only act if we are dealing with a content type supporting translations. - if (translation_supported_type($node->getType()) && - // And it's a new node. - $node->isNew() && - // And the request variables are set properly. - !empty($translation) && - !empty($target) && - is_numeric($translation)) { - - $source_node = node_load($translation); - - $language_list = language_list(); - $langcode = $target; - if (!isset($language_list[$langcode]) || ($source_node->language()->id == $langcode)) { - // If not supported language, or same language as source node, break. - return; - } - - // Ensure we don't have an existing translation in this language. - if (!empty($source_node->tnid->value)) { - $translations = translation_node_get_translations($source_node->tnid->value); - if (isset($translations[$langcode])) { - drupal_set_message(t('A translation of %title in %language already exists, a new %type will be created instead of a translation.', array('%title' => $source_node->label(), '%language' => $language_list[$langcode]->name, '%type' => $node->getType())), 'error'); - return; - } - } - - // Populate fields based on source node. - $node->langcode = $langcode; - $node->translation_source = $source_node; - $node->title = $source_node->getTitle(); - } -} - -/** - * Implements hook_node_insert(). - */ -function translation_node_insert(EntityInterface $node) { - // Only act if we are dealing with a content type supporting translations. - if (translation_supported_type($node->getType())) { - if (!empty($node->translation_source)) { - if ($node->translation_source->tnid->value) { - // Add node to existing translation set. - $tnid = $node->translation_source->tnid->value; - } - else { - // Create new translation set, using nid from the source node. - $tnid = $node->translation_source->id(); - db_update('node') - ->fields(array( - 'tnid' => $tnid, - 'translate' => 0, - )) - ->condition('nid', $node->translation_source->id()) - ->execute(); - } - db_update('node') - ->fields(array( - 'tnid' => $tnid, - 'translate' => 0, - )) - ->condition('nid', $node->id()) - ->execute(); - // Save tnid to avoid loss in case of resave. - $node->tnid = $tnid; - } - } -} - -/** - * Implements hook_node_update(). - */ -function translation_node_update(NodeInterface $node) { - // Only act if we are dealing with a content type supporting translations. - if (translation_supported_type($node->getType())) { - if (isset($node->translation) && $node->translation && $node->tnid->value) { - // Update translation information. - db_update('node') - ->fields(array( - 'tnid' => $node->tnid->value, - 'translate' => $node->translation['status'], - )) - ->condition('nid', $node->id()) - ->execute(); - if (!empty($node->translation['retranslate'])) { - // This is the source node, asking to mark all translations outdated. - db_update('node') - ->fields(array('translate' => 1)) - ->condition('nid', $node->id(), '<>') - ->condition('tnid', $node->tnid->value) - ->execute(); - } - } - } -} - -/** - * Implements hook_node_validate(). - * - * Ensures that duplicate translations can't be created for the same source. - */ -function translation_node_validate(NodeInterface $node, $form, &$form_state) { - // Only act on translatable nodes with a tnid or translation_source. - $form_node = $form_state['controller']->getEntity(); - if (translation_supported_type($node->getType()) && ($node->tnid->value || ($form_node->translation_source && $form_node->translation_source->id()))) { - $tnid = $node->tnid->value ?: $form_node->translation_source->id(); - $translations = translation_node_get_translations($tnid); - if (isset($translations[$node->language()->id]) && $translations[$node->language()->id]->nid != $node->id()) { - form_set_error('langcode', t('There is already a translation in this language.')); - } - } -} - -/** - * Implements hook_node_predelete(). - */ -function translation_node_predelete(NodeInterface $node) { - // Only act if we are dealing with a content type supporting translations. - if (translation_supported_type($node->getType())) { - translation_remove_from_set($node); - } -} - -/** - * Removes a node from its translation set and updates accordingly. - * - * @param $node - * A node entity. - */ -function translation_remove_from_set(NodeInterface $node) { - if ($node->tnid->value) { - $query = db_update('node') - ->fields(array( - 'tnid' => 0, - 'translate' => 0, - )); - if (db_query('SELECT COUNT(*) FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid->value))->fetchField() == 1) { - // There is only one node left in the set: remove the set altogether. - $query - ->condition('tnid', $node->tnid->value) - ->execute(); - } - else { - $query - ->condition('nid', $node->id()) - ->execute(); - - // If the node being removed was the source of the translation set, - // we pick a new source - preferably one that is up to date. - if ($node->tnid->value == $node->id()) { - $new_tnid = db_query('SELECT nid FROM {node} WHERE tnid = :tnid ORDER BY translate ASC, nid ASC', array(':tnid' => $node->tnid->value))->fetchField(); - db_update('node') - ->fields(array('tnid' => $new_tnid)) - ->condition('tnid', $node->tnid->value) - ->execute(); - } - } - } -} - -/** - * Gets all nodes in a given translation set. - * - * @param $tnid - * The translation source nid of the translation set, the identifier of the - * node used to derive all translations in the set. - * - * @return - * Array of partial node objects (nid, title, langcode) representing all - * nodes in the translation set, in effect all translations of node $tnid, - * including node $tnid itself. Because these are partial nodes, you need to - * node_load() the full node, if you need more properties. The array is - * indexed by language code. - */ -function translation_node_get_translations($tnid) { - if (is_numeric($tnid) && $tnid) { - $translations = &drupal_static(__FUNCTION__, array()); - - if (!isset($translations[$tnid])) { - $translations[$tnid] = array(); - $query = db_select('node_field_data', 'n'); - $query->innerJoin('node', 'nb', 'nb.nid = n.nid AND nb.langcode = n.langcode'); - $query->fields('n', array('nid', 'uid', 'status', 'title', 'langcode')) - ->fields('nb', array('type')) - ->condition('nb.tnid', $tnid) - ->addTag('node_access'); - $result = $query->execute(); - - foreach ($result as $node) { - $translations[$tnid][$node->langcode] = $node; - } - } - return $translations[$tnid]; - } -} - -/** - * Returns whether the given content type has support for translations. - * - * @return - * TRUE if translation is supported, and FALSE if not. - */ -function translation_supported_type($type) { - return variable_get('node_type_language_translation_enabled_' . $type, FALSE); -} - -/** - * Returns the paths of all translations of a node, based on its Drupal path. - * - * @param $path - * A Drupal path, for example node/432. - * - * @return - * An array of paths of translations of the node accessible to the current - * user, keyed with language codes. - */ -function translation_path_get_translations($path) { - $paths = array(); - // Check for a node related path, and for its translations. - if ((preg_match("!^node/(\d+)(/.+|)$!", $path, $matches)) && ($node = node_load((int) $matches[1])) && $node->tnid->value) { - foreach (translation_node_get_translations($node->tnid->value) as $language => $translation_node) { - $paths[$language] = 'node/' . $translation_node->id() . $matches[2]; - } - } - return $paths; -} - -/** - * Implements hook_language_switch_links_alter(). - * - * Replaces links with pointers to translated versions of the content. - */ -function translation_language_switch_links_alter(array &$links, $type, $path) { - $language_type = \Drupal::config('translation.settings')->get('language_type'); - if ($type == $language_type && preg_match("!^node/(\d+)(/.+|)!", $path, $matches)) { - $node = node_load((int) $matches[1]); - - if (empty($node->tnid->value)) { - // If the node cannot be found nothing needs to be done. If it does not - // have translations it might be a language neutral node, in which case we - // must leave the language switch links unaltered. This is true also for - // nodes not having translation support enabled. - if (empty($node) || $node->language()->id == Language::LANGCODE_NOT_SPECIFIED || !translation_supported_type($node->getType())) { - return; - } - $translations = array($node->language()->id => $node); - } - else { - $translations = translation_node_get_translations($node->tnid->value); - } - - foreach ($links as $langcode => $link) { - if (isset($translations[$langcode]) && $translations[$langcode]->status) { - // Translation in a different node. - $nid = $translations[$langcode] instanceof EntityInterface ? $translations[$langcode]->id() : $translations[$langcode]->nid; - $links[$langcode]['href'] = 'node/' . $nid . $matches[2]; - } - else { - // No translation in this language, or no permission to view. - unset($links[$langcode]['href']); - $links[$langcode]['attributes']['class'][] = 'locale-untranslated'; - } - } - } -} - -/** - * Implements hook_library_info(). - */ -function translation_library_info() { - $libraries['drupal.translation'] = array( - 'title' => 'Translation', - 'version' => \Drupal::VERSION, - 'js' => array( - drupal_get_path('module', 'translation') . '/translation.js' => array(), - ), - 'dependencies' => array( - array('system', 'jquery'), - array('system', 'drupal'), - ), - ); - - return $libraries; -} diff --git a/core/modules/translation/translation.pages.inc b/core/modules/translation/translation.pages.inc deleted file mode 100644 index a1f6360..0000000 --- a/core/modules/translation/translation.pages.inc +++ /dev/null @@ -1,105 +0,0 @@ -tnid->value) { - // Already part of a set, grab that set. - $tnid = $node->tnid->value; - $translations = translation_node_get_translations($node->tnid->value); - } - else { - // We have no translation source nid, this could be a new set, emulate that. - $tnid = $node->id(); - $translations = array($node->language()->id => $node); - } - - $type = \Drupal::config('translation.settings')->get('language_type'); - $header = array(t('Language'), t('Title'), t('Status'), t('Operations')); - - foreach (language_list() as $langcode => $language) { - $options = array(); - $language_name = $language->name; - if (isset($translations[$langcode])) { - // Existing translation in the translation set: display status. - // We load the full node to check whether the user can edit it. - $nid = $translations[$langcode] instanceof EntityInterface ? $translations[$langcode]->id() : $translations[$langcode]->nid; - $translation_node = node_load($nid); - $path = 'node/' . $translation_node->id(); - $links = language_negotiation_get_switch_links($type, $path); - $title = empty($links->links[$langcode]['href']) ? l($translation_node->label(), $path) : l($translation_node->label(), $links->links[$langcode]['href'], $links->links[$langcode]); - if (node_access('update', $translation_node)) { - $path = 'node/' . $translation_node->id() . '/edit'; - $links = language_negotiation_get_switch_links($type, $path); - if (!empty($links->links[$langcode]['href'])) { - $options['edit'] = array( - 'title' => t('edit'), - ) + $links->links[$langcode]; - } - } - $status = $translation_node->isPublished() ? t('Published') : t('Not published'); - $status .= $translation_node->translate->value ? ' - ' . t('outdated') . '' : ''; - if ($translation_node->id() == $tnid) { - $language_name = t('@language_name (source)', array('@language_name' => $language_name)); - } - } - else { - // No such translation in the set yet: help user to create it. - $title = t('n/a'); - if (node_access('create', $node)) { - $path = 'node/add/' . $node->getType(); - $links = language_negotiation_get_switch_links($type, $path); - $query = array('query' => array('translation' => $node->id(), 'target' => $langcode)); - if (!empty($links->links[$langcode]['href'])) { - $options['add'] = array( - 'title' => t('Add translation'), - ) + $links->links[$langcode]; - $options['add'] = NestedArray::mergeDeep($options['add'], $query); - } - } - $status = t('Not translated'); - } - $row = array(); - $row[] = $language_name; - $row[] = $title; - $row[] = $status; - $row[] = array( - 'data' => array( - '#type' => 'operations', - '#links' => $options, - ), - ); - $rows[] = $row; - } - - $build['#title'] = t('Translations of %title', array('%title' => $node->label())); - - $build['translation_node_overview'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - ); - - return $build; -} diff --git a/core/modules/translation/translation.routing.yml b/core/modules/translation/translation.routing.yml deleted file mode 100644 index 7129075..0000000 --- a/core/modules/translation/translation.routing.yml +++ /dev/null @@ -1,7 +0,0 @@ -translation.node_overview: - path: '/node/{node}/translate' - defaults: - _title: 'Translate' - _content: '\Drupal\translation\Controller\TranslationController::nodeOverview' - requirements: - _access_translation_tab: 'node' diff --git a/core/modules/translation/translation.services.yml b/core/modules/translation/translation.services.yml deleted file mode 100644 index e6520d5..0000000 --- a/core/modules/translation/translation.services.yml +++ /dev/null @@ -1,5 +0,0 @@ -services: - access_check.translation.node_overview: - class: Drupal\translation\Access\TranslationNodeOverviewAccessCheck - tags: - - { name: access_check } diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php index 7ad88da..549163e 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php @@ -38,7 +38,7 @@ class HandlerAllTest extends HandlerTestBase { 'search', 'statistics', 'taxonomy', - 'translation', + 'translation_content', 'user', );