diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index fa73df5..9da2b41 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -75,10 +75,10 @@ function translation_menu() { * Only displays the translation tab for nodes that are not language-neutral * of types that have translation enabled. * - * @param $node + * @param object $node * A node object. * - * @return + * @return boolean * TRUE if the translation tab should be displayed, FALSE otherwise. * * @see translation_menu() @@ -119,9 +119,15 @@ function translation_permission() { function translation_form_node_type_form_alter(&$form, &$form_state) { // Add translation option to content type form. $form['workflow']['node_type_language']['#type'] = 'radios'; - $form['workflow']['node_type_language']['#options'] = array(t('Disabled'), t('Enabled'), TRANSLATION_ENABLED => t('Enabled, with translation')); + $form['workflow']['node_type_language']['#options'] = array( + 0 => t('Disabled'), + 1 => t('Enabled'), + TRANSLATION_ENABLED => t('Enabled, with translation'), + ); // Description based on text from node.module. - $form['workflow']['node_type_language']['#description'] = t('Add a language selection field to the editing form, allowing you to select from one of the enabled languages. You can also turn on translation for this content type, which lets you have content translated to any of the installed languages. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('@languages' => url('admin/config/regional/language'))); + $form['workflow']['node_type_language']['#description'] = t('Add a language selection field to the editing form, allowing you to select from one of the enabled languages. You can also turn on translation for this content type, which lets you have content translated to any of the installed languages. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array( + '@languages' => url('admin/config/regional/language'), + )); } /** @@ -164,14 +170,14 @@ function translation_form_node_form_alter(&$form, &$form_state) { $form['langcode']['#disabled'] = TRUE; } elseif (!empty($node->nid) && !empty($node->tnid)) { - // 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. + // 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_NOT_SPECIFIED]); foreach (translation_node_get_translations($node->tnid) as $langcode => $translation) { if ($translation->nid != $node->nid) { if ($translator_widget) { - $group = $groups[(int)!isset($disabled_languages[$langcode])]; + $group = $groups[(int) !isset($disabled_languages[$langcode])]; unset($form['langcode']['#options'][$group][$langcode]); } else { @@ -191,7 +197,7 @@ function translation_form_node_form_alter(&$form, &$form_state) { '#weight' => 30, ); if ($node->tnid == $node->nid) { - // This is the source node of the translation + // This is the source node of the translation. $form['translation']['retranslate'] = array( '#type' => 'checkbox', '#title' => t('Flag translations as outdated'), @@ -306,7 +312,11 @@ function translation_node_prepare($node) { if (!empty($source_node->tnid)) { $translations = translation_node_get_translations($source_node->tnid); 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->title, '%language' => $language_list[$langcode]->name, '%type' => $node->type)), 'error'); + 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->title, + '%language' => $language_list[$langcode]->name, + '%type' => $node->type, + )), 'error'); return; } } @@ -394,7 +404,7 @@ function translation_node_validate($node, $form) { if (translation_supported_type($node->type) && (!empty($node->tnid) || !empty($form['#node']->translation_source->nid))) { $tnid = !empty($node->tnid) ? $node->tnid : $form['#node']->translation_source->nid; $translations = translation_node_get_translations($tnid); - if (isset($translations[$node->langcode]) && $translations[$node->langcode]->nid != $node->nid ) { + if (isset($translations[$node->langcode]) && $translations[$node->langcode]->nid != $node->nid) { form_set_error('langcode', t('There is already a translation in this language.')); } } @@ -413,7 +423,7 @@ function translation_node_predelete($node) { /** * Removes a node from its translation set and updates accordingly. * - * @param $node + * @param object $node * A node object. */ function translation_remove_from_set($node) { @@ -423,7 +433,7 @@ function translation_remove_from_set($node) { 'tnid' => 0, 'translate' => 0, )); - if (db_query('SELECT COUNT(*) FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid))->fetchField() == 1) { + if (db_query('SELECT COUNT(nid) FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid))->fetchField() == 1) { // There is only one node left in the set: remove the set altogether. $query ->condition('tnid', $node->tnid) @@ -450,11 +460,11 @@ function translation_remove_from_set($node) { /** * Gets all nodes in a given translation set. * - * @param $tnid + * @param int $tnid * The translation source nid of the translation set, the identifier of the * node used to derive all translations in the set. * - * @return + * @return array * 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 @@ -484,7 +494,7 @@ function translation_node_get_translations($tnid) { /** * Returns whether the given content type has support for translations. * - * @return + * @return boolean * TRUE if translation is supported, and FALSE if not. */ function translation_supported_type($type) { @@ -494,10 +504,10 @@ function translation_supported_type($type) { /** * Returns the paths of all translations of a node, based on its Drupal path. * - * @param $path + * @param string $path * A Drupal path, for example node/432. * - * @return + * @return array * An array of paths of translations of the node accessible to the current * user, keyed with language codes. */ diff --git a/core/modules/translation/translation.pages.inc b/core/modules/translation/translation.pages.inc index 66dfc42..8dcb6f1 100644 --- a/core/modules/translation/translation.pages.inc +++ b/core/modules/translation/translation.pages.inc @@ -8,10 +8,10 @@ /** * Page callback: Displays a list of a node's translations. * - * @param $node + * @param object $node * A node object. * - * @return + * @return array * A render array for a page containing a list of content. * * @see translation_menu() diff --git a/core/modules/translation/translation.test b/core/modules/translation/translation.test index c0e158c..48a0d14 100644 --- a/core/modules/translation/translation.test +++ b/core/modules/translation/translation.test @@ -17,7 +17,7 @@ class TranslationTestCase extends DrupalWebTestCase { return array( 'name' => 'Translation functionality', 'description' => 'Create a basic page with translation, modify the page outdating translation, and update translation.', - 'group' => 'Translation' + 'group' => 'Translation', ); } @@ -25,8 +25,20 @@ class TranslationTestCase extends DrupalWebTestCase { parent::setUp('language', 'locale', 'translation', 'translation_test'); // Setup users. - $this->admin_user = $this->drupalCreateUser(array('bypass node access', 'administer nodes', 'administer languages', 'administer content types', 'administer blocks', 'access administration pages', 'translate content')); - $this->translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate content')); + $this->admin_user = $this->drupalCreateUser(array( + 'bypass node access', + 'administer nodes', + 'administer languages', + 'administer content types', + 'administer blocks', + 'access administration pages', + 'translate content', + )); + $this->translator = $this->drupalCreateUser(array( + 'create page content', + 'edit own page content', + 'translate content', + )); $this->drupalLogin($this->admin_user); @@ -64,7 +76,7 @@ class TranslationTestCase extends DrupalWebTestCase { function testContentTranslation() { // Create Basic page in English. $node_title = $this->randomName(); - $node_body = $this->randomName(); + $node_body = $this->randomName(); $node = $this->createPage($node_title, $node_body, 'en'); // Unpublish the original node to check that this has no impact on the // translation overview page, publish it again afterwards. @@ -266,10 +278,10 @@ class TranslationTestCase extends DrupalWebTestCase { /** * Returns an empty node data structure. * - * @param $langcode + * @param string $langcode * The language code. * - * @return + * @return object * An empty node data structure. */ function emptyNode($langcode) { @@ -279,7 +291,7 @@ class TranslationTestCase extends DrupalWebTestCase { /** * Installs the specified language, or enables it if it is already installed. * - * @param $language_code + * @param string $language_code * The language code to check. */ function addLanguage($language_code) { @@ -303,11 +315,11 @@ class TranslationTestCase extends DrupalWebTestCase { } elseif ($this->xpath('//input[@type="checkbox" and @name=:name and @checked="checked"]', array(':name' => 'languages[' . $language_code . '][enabled]'))) { // It's installed and enabled. No need to do anything. - $this->assertTrue(true, 'Language [' . $language_code . '] already installed and enabled.'); + $this->assertTrue(TRUE, 'Language [' . $language_code . '] already installed and enabled.'); } else { // It's installed but not enabled. Enable it. - $this->assertTrue(true, 'Language [' . $language_code . '] already installed.'); + $this->assertTrue(TRUE, 'Language [' . $language_code . '] already installed.'); $this->drupalPost(NULL, array('languages[' . $language_code . '][enabled]' => TRUE), t('Save configuration')); $this->assertRaw(t('Configuration saved.'), t('Language successfully enabled.')); } @@ -316,14 +328,14 @@ class TranslationTestCase extends DrupalWebTestCase { /** * Creates a "Basic page" in the specified language. * - * @param $title + * @param string $title * The title of a basic page in the specified language. - * @param $body + * @param string $body * The body of a basic page in the specified language. - * @param $langcode + * @param string $langcode * (optional) Language code. * - * @return + * @return object * A node object. */ function createPage($title, $body, $langcode = NULL) { @@ -347,16 +359,16 @@ class TranslationTestCase extends DrupalWebTestCase { /** * Creates a translation for a basic page in the specified language. * - * @param $node + * @param object $node * The basic page to create the translation for. - * @param $title + * @param string $title * The title of a basic page in the specified language. - * @param $body + * @param string $body * The body of a basic page in the specified language. - * @param $langcode + * @param string $langcode * (optional) Language code. * - * @return + * @return object * Translation object. */ function createTranslation($node, $title, $body, $langcode) { @@ -384,20 +396,20 @@ class TranslationTestCase extends DrupalWebTestCase { /** * Asserts an element identified by the given XPath has the given content. * - * @param $xpath + * @param array $xpath * The XPath used to find the element. * @param array $arguments * An array of arguments with keys in the form ':name' matching the * placeholders in the query. The values may be either strings or numeric * values. - * @param $value + * @param string $value * The text content of the matched element to assert. - * @param $message + * @param string $message * The message to display. - * @param $group + * @param string $group * The group this message belongs to. * - * @return + * @return boolean * TRUE on pass, FALSE on fail. */ function assertContentByXPath($xpath, array $arguments = array(), $value = NULL, $message = '', $group = 'Other') { @@ -408,16 +420,16 @@ class TranslationTestCase extends DrupalWebTestCase { /** * Tests whether the specified language switch links are found. * - * @param $node + * @param object $node * The node to display. - * @param $translation + * @param object $translation * The translation whose link has to be checked. - * @param $find + * @param boolean $find * TRUE if the link must be present in the node page. - * @param $types + * @param array $types * The page areas to be checked. * - * @return + * @return boolean * TRUE if the language switch links are found, FALSE if not. */ function assertLanguageSwitchLinks($node, $translation, $find = TRUE, $types = NULL) { @@ -437,7 +449,11 @@ class TranslationTestCase extends DrupalWebTestCase { $this->drupalGet("node/$node->nid", array('language' => $page_language)); foreach ($types as $type) { - $args = array('%translation_language' => $translation_language->name, '%page_language' => $page_language->name, '%type' => $type); + $args = array( + '%translation_language' => $translation_language->name, + '%page_language' => $page_language->name, + '%type' => $type, + ); if ($find) { $message = t('[%page_language] Language switch item found for %translation_language language in the %type page area.', $args); } @@ -462,16 +478,16 @@ class TranslationTestCase extends DrupalWebTestCase { /** * Searches for elements matching the given xpath and value. * - * @param $xpath + * @param array $xpath * The XPath used to find the element. * @param array $arguments * An array of arguments with keys in the form ':name' matching the * placeholders in the query. The values may be either strings or numeric * values. - * @param $value + * @param string $value * The text content of the matched element to assert. * - * @return + * @return boolean * TRUE if found, otherwise FALSE. */ function findContentByXPath($xpath, array $arguments = array(), $value = NULL) {