diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index acc82d6..6a78081 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2617,6 +2617,13 @@ function drupal_language_initialize() { ->addMethodCall('extend', array($default)); } } + + // @todo Temporary backwards compatibility for code still using globals. + // Remove after these issues: + // - $language_url: http://drupal.org/node/1512310 + foreach ($types as $type) { + $GLOBALS[$type] = $container->get($type); + } } /** diff --git a/core/includes/install.inc b/core/includes/install.inc index 96e84b3..bc6e13e 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -188,6 +188,7 @@ function drupal_get_database_types() { * An array of settings that need to be updated. */ function drupal_rewrite_settings($settings = array()) { + $default_settings = 'sites/default/default.settings.php'; drupal_static_reset('conf_path'); $settings_file = conf_path(FALSE) . '/settings.php'; @@ -199,52 +200,62 @@ function drupal_rewrite_settings($settings = array()) { } $buffer = NULL; - $contents = file_get_contents(DRUPAL_ROOT . '/' . $settings_file); - if ($contents !== FALSE) { - // Step through each token in settings.php and replace any variables that - // are in the passed-in array. - $replacing_variable = FALSE; - foreach (token_get_all($contents) as $token) { - // Strip off the leading "$" before comparing the variable name. - if (is_array($token) && $token[0] == T_VARIABLE && ($variable_name = substr($token[1], 1)) && in_array($variable_name, $keys)) { - // Write the new value to settings.php in the following format: - // $[setting] = '[value]'; // [comment] - $setting = $settings[$variable_name]; - $buffer .= '$' . $variable_name . ' = ' . var_export($setting['value'], TRUE) . ';'; - if (!empty($setting['comment'])) { - $buffer .= ' // ' . $setting['comment']; + $first = TRUE; + if ($fp = fopen(DRUPAL_ROOT . '/' . $default_settings, 'r')) { + // Step line by line through settings.php. + while (!feof($fp)) { + $line = fgets($fp); + if ($first && substr($line, 0, 5) != ' $data) { - if (!empty($data['required'])) { + if ($data['required']) { $buffer .= "\$$setting = " . var_export($data['value'], TRUE) . ";\n"; } } - // Write the new settings file. - if (file_put_contents(DRUPAL_ROOT . '/' . $settings_file, $buffer) === FALSE) { + $fp = fopen(DRUPAL_ROOT . '/' . $settings_file, 'w'); + if ($fp && fwrite($fp, $buffer) === FALSE) { throw new Exception(st('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file))); } } else { - throw new Exception(st('Failed to open %settings. Verify the file permissions.', array('%settings' => $settings_file))); + throw new Exception(st('Failed to open %settings. Verify the file permissions.', array('%settings' => $default_settings))); } } diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 50bae76..5c43a84 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -880,7 +880,7 @@ function block_block_list_alter(&$blocks) { continue; } foreach ($block_langcodes[$block->module][$block->delta] as $language_type => $langcodes) { - if (isset($langcodes[drupal_container()->get($language_type)->langcode])) { + if (isset($langcodes[$GLOBALS[$language_type]->langcode])) { // Found a language type - langcode combination in the configuration // that is applicable to the current request. continue 2; diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 7c96247..ffa98a5 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1837,12 +1837,13 @@ function comment_form($form, &$form_state, Comment $comment) { } $form['node_type'] = array('#type' => 'value', '#value' => 'comment_node_' . $node->type); - // If a content type has multilingual support we set the comment to inherit the - // content language. Otherwise mark the comment as language neutral. + // Make the comment inherit the node language unless specifically set. $comment_langcode = $comment->langcode; - if (($comment_langcode == LANGUAGE_NOT_SPECIFIED) && variable_get('node_type_language_' . $node->type, 0)) { + if ($comment_langcode == LANGUAGE_NOT_SPECIFIED) { $comment_langcode = $language_content->langcode; } + + // Uses the language of the content as comment language. $form['langcode'] = array( '#type' => 'value', '#value' => $comment_langcode, diff --git a/core/modules/field/modules/text/text.test b/core/modules/field/modules/text/text.test index 49366e5..f191da0 100644 --- a/core/modules/field/modules/text/text.test +++ b/core/modules/field/modules/text/text.test @@ -443,7 +443,7 @@ class TextTranslationTestCase extends WebTestBase { $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); // Set "Article" content type to use multilingual support with translation. - $edit = array('node_type_language' => TRANSLATION_ENABLED); + $edit = array('node_type_language_hidden' => FALSE, 'node_type_language_translation_enabled' => TRANSLATION_ENABLED); $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Article')), t('Article content type has been updated.')); } diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 9689bb3..f6056fa 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -326,7 +326,7 @@ function field_ui_field_overview_form($form, &$form_state, $entity_type, $bundle t('Weight'), t('Parent'), t('Machine name'), - t('Field type'), + t('Field'), t('Widget'), array('data' => t('Operations'), 'colspan' => 2), ), diff --git a/core/modules/field_ui/field_ui.test b/core/modules/field_ui/field_ui.test index bd65018..c33552c 100644 --- a/core/modules/field_ui/field_ui.test +++ b/core/modules/field_ui/field_ui.test @@ -204,7 +204,7 @@ class FieldUIManageFieldsTestCase extends FieldUITestCase { $table_headers = array( t('Label'), t('Machine name'), - t('Field type'), + t('Field'), t('Widget'), t('Operations'), ); diff --git a/core/modules/forum/forum-icon.tpl.php b/core/modules/forum/forum-icon.tpl.php index fd1cd13..9cf2cd8 100644 --- a/core/modules/forum/forum-icon.tpl.php +++ b/core/modules/forum/forum-icon.tpl.php @@ -2,7 +2,7 @@ /** * @file - * Displays an appropriate icon for a forum post. + * Default theme implementation to display an appropriate icon for a forum post. * * Available variables: * - $new_posts: Indicates whether or not the topic contains new posts. @@ -12,8 +12,6 @@ * * @see template_preprocess_forum_icon() * @see theme_forum_icon() - * - * @ingroup themeable */ ?>
diff --git a/core/modules/forum/forum-list.tpl.php b/core/modules/forum/forum-list.tpl.php index 01c74a3..257cea9 100644 --- a/core/modules/forum/forum-list.tpl.php +++ b/core/modules/forum/forum-list.tpl.php @@ -2,35 +2,34 @@ /** * @file - * Displays a list of forums and containers. + * Default theme implementation to display a list of forums and containers. * * Available variables: * - $forums: An array of forums and containers to display. It is keyed to the - * numeric IDs of all child forums and containers. Each $forum in $forums - * contains: - * - $forum->is_container: TRUE if the forum can contain other forums. FALSE - * if the forum can contain only topics. - * - $forum->depth: How deep the forum is in the current hierarchy. - * - $forum->zebra: 'even' or 'odd' string used for row class. - * - $forum->icon_class: 'default' or 'new' string used for forum icon class. - * - $forum->icon_title: Text alternative for the forum icon. - * - $forum->name: The name of the forum. - * - $forum->link: The URL to link to this forum. - * - $forum->description: The description of this forum. - * - $forum->new_topics: TRUE if the forum contains unread posts. - * - $forum->new_url: A URL to the forum's unread posts. - * - $forum->new_text: Text for the above URL, which tells how many new posts. - * - $forum->old_topics: A count of posts that have already been read. - * - $forum->num_posts: The total number of posts in the forum. - * - $forum->last_reply: Text representing the last time a forum was posted or - * commented in. - * - $forum_id: Forum ID for the current forum. Parent to all items within the - * $forums array. + * numeric id's of all child forums and containers. + * - $forum_id: Forum id for the current forum. Parent to all items within + * the $forums array. + * + * Each $forum in $forums contains: + * - $forum->is_container: Is TRUE if the forum can contain other forums. Is + * FALSE if the forum can contain only topics. + * - $forum->depth: How deep the forum is in the current hierarchy. + * - $forum->zebra: 'even' or 'odd' string used for row class. + * - $forum->icon_class: 'default' or 'new' string used for forum icon class. + * - $forum->icon_title: Text alternative for the forum icon. + * - $forum->name: The name of the forum. + * - $forum->link: The URL to link to this forum. + * - $forum->description: The description of this forum. + * - $forum->new_topics: True if the forum contains unread posts. + * - $forum->new_url: A URL to the forum's unread posts. + * - $forum->new_text: Text for the above URL which tells how many new posts. + * - $forum->old_topics: A count of posts that have already been read. + * - $forum->num_posts: The total number of posts in the forum. + * - $forum->last_reply: Text representing the last time a forum was posted or + * commented in. * * @see template_preprocess_forum_list() * @see theme_forum_list() - * - * @ingroup themeable */ ?> diff --git a/core/modules/forum/forum-rtl.css b/core/modules/forum/forum-rtl.css index a0bdf2d..e9c6bc1 100644 --- a/core/modules/forum/forum-rtl.css +++ b/core/modules/forum/forum-rtl.css @@ -1,7 +1,3 @@ -/** - * @file - * Right-to-left styling for the Forum module. - */ #forum td.forum .icon { float: right; diff --git a/core/modules/forum/forum-submitted.tpl.php b/core/modules/forum/forum-submitted.tpl.php index 18fea8f..d310448 100644 --- a/core/modules/forum/forum-submitted.tpl.php +++ b/core/modules/forum/forum-submitted.tpl.php @@ -2,20 +2,18 @@ /** * @file - * Formats a forum post submission string. - * - * The submission string indicates when and by whom a topic was submitted. + * Default theme implementation to format a simple string indicated when and + * by whom a topic was submitted. * * Available variables: + * * - $author: The author of the post. * - $time: How long ago the post was created. - * - $topic: An object with the raw data of the post. Potentially unsafe. Be - * sure to clean this data before printing. + * - $topic: An object with the raw data of the post. Unsafe, be sure + * to clean this data before printing. * * @see template_preprocess_forum_submitted() * @see theme_forum_submitted() - * - * @ingroup themeable */ ?> diff --git a/core/modules/forum/forum-topic-list.tpl.php b/core/modules/forum/forum-topic-list.tpl.php index 6427814..3390703 100644 --- a/core/modules/forum/forum-topic-list.tpl.php +++ b/core/modules/forum/forum-topic-list.tpl.php @@ -2,39 +2,35 @@ /** * @file - * Displays a list of forum topics. + * Default theme implementation to display a list of forum topics. * * Available variables: * - $header: The table header. This is pre-generated with click-sorting * information. If you need to change this, see * template_preprocess_forum_topic_list(). * - $pager: The pager to display beneath the table. - * - $topics: An array of topics to be displayed. Each $topic in $topics - * contains: - * - $topic->icon: The icon to display. - * - $topic->moved: A flag to indicate whether the topic has been moved to - * another forum. - * - $topic->title: The title of the topic. Safe to output. - * - $topic->message: If the topic has been moved, this contains an - * explanation and a link. - * - $topic->zebra: 'even' or 'odd' string used for row class. - * - $topic->comment_count: The number of replies on this topic. - * - $topic->new_replies: A flag to indicate whether there are unread - * comments. - * - $topic->new_url: If there are unread replies, this is a link to them. - * - $topic->new_text: Text containing the translated, properly pluralized - * count. - * - $topic->created: A string representing when the topic was posted. Safe - * to output. - * - $topic->last_reply: An outputtable string representing when the topic was - * last replied to. - * - $topic->timestamp: The raw timestamp this topic was posted. - * - $topic_id: Numeric ID for the current forum topic. + * - $topics: An array of topics to be displayed. + * - $topic_id: Numeric id for the current forum topic. + * + * Each $topic in $topics contains: + * - $topic->icon: The icon to display. + * - $topic->moved: A flag to indicate whether the topic has been moved to + * another forum. + * - $topic->title: The title of the topic. Safe to output. + * - $topic->message: If the topic has been moved, this contains an + * explanation and a link. + * - $topic->zebra: 'even' or 'odd' string used for row class. + * - $topic->comment_count: The number of replies on this topic. + * - $topic->new_replies: A flag to indicate whether there are unread comments. + * - $topic->new_url: If there are unread replies, this is a link to them. + * - $topic->new_text: Text containing the translated, properly pluralized count. + * - $topic->created: An outputtable string represented when the topic was posted. + * - $topic->last_reply: An outputtable string representing when the topic was + * last replied to. + * - $topic->timestamp: The raw timestamp this topic was posted. * * @see template_preprocess_forum_topic_list() * @see theme_forum_topic_list() - * - * @ingroup themeable */ ?>
diff --git a/core/modules/forum/forum.admin.inc b/core/modules/forum/forum.admin.inc index dea573c..6645bb8 100644 --- a/core/modules/forum/forum.admin.inc +++ b/core/modules/forum/forum.admin.inc @@ -2,22 +2,7 @@ /** * @file - * Administrative page callbacks for the Forum module. - */ - -/** - * Page callback: Returns a form for creating a new forum or container. - * - * @param $type - * What is being added. Possible values are 'forum' and 'container'. - * @param $edit - * (optional) Associative array containing a forum term to be edited. - * Defaults to an empty array. - * - * @return - * A form for creating a new forum or container. - * - * @see forum_menu() + * Administrative page callbacks for the forum module. */ function forum_form_main($type, $edit = array()) { $edit = (array) $edit; @@ -35,14 +20,11 @@ function forum_form_main($type, $edit = array()) { } /** - * Form constructor for adding and editing a forum. - * - * @param $edit - * (optional) Associative array containing a forum term to be added or edited. - * Defaults to an empty array. + * Returns a form for adding a forum to the forum vocabulary * - * @see forum_form_submit() + * @param $edit Associative array containing a forum term to be added or edited. * @ingroup forms + * @see forum_form_submit() */ function forum_form_forum($form, &$form_state, $edit = array()) { $edit += array( @@ -85,7 +67,7 @@ function forum_form_forum($form, &$form_state, $edit = array()) { } /** - * Form submission handler for forum_form_forum() and forum_form_container(). + * Process forum form and container form submissions. */ function forum_form_submit($form, &$form_state) { if ($form['form_id']['#value'] == 'forum_form_container') { @@ -124,8 +106,8 @@ function forum_form_submit($form, &$form_state) { /** * Returns HTML for a forum form. * - * By default this does not alter the appearance of a form at all, but is - * provided as a convenience for themers. + * By default this does not alter the appearance of a form at all, + * but is provided as a convenience for themers. * * @param $variables * An associative array containing: @@ -138,14 +120,11 @@ function theme_forum_form($variables) { } /** - * Form constructor for adding and editing forum containers. - * - * @param $edit - * (optional) Associative array containing a container term to be added or edited. - * Defaults to an empty array. + * Returns a form for adding a container to the forum vocabulary * - * @see forum_form_submit() + * @param $edit Associative array containing a container term to be added or edited. * @ingroup forms + * @see forum_form_submit() */ function forum_form_container($form, &$form_state, $edit = array()) { $edit += array( @@ -199,13 +178,9 @@ function forum_form_container($form, &$form_state, $edit = array()) { } /** - * Form constructor for confirming deletion of a forum taxonomy term. - * - * @param $tid - * ID of the term to be deleted. + * Returns a confirmation page for deleting a forum taxonomy term. * - * @see forum_confirm_delete_submit() - * @ingroup forms + * @param $tid ID of the term to be deleted */ function forum_confirm_delete($form, &$form_state, $tid) { $term = taxonomy_term_load($tid); @@ -217,7 +192,7 @@ function forum_confirm_delete($form, &$form_state, $tid) { } /** - * Form submission handler for forum_confirm_delete(). + * Implement forms api _submit call. Deletes a forum after confirmation. */ function forum_confirm_delete_submit($form, &$form_state) { taxonomy_term_delete($form_state['values']['tid']); @@ -229,11 +204,9 @@ function forum_confirm_delete_submit($form, &$form_state) { } /** - * Form constructor for the forum settings page. + * Form builder for the forum settings page. * - * @see forum_menu() * @see system_settings_form() - * @ingroup forms */ function forum_admin_settings($form) { $number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500)); @@ -261,13 +234,7 @@ function forum_admin_settings($form) { } /** - * Form constructor for the forum overview form. - * - * Returns a form for controlling the hierarchy of existing forums and - * containers. - * - * @see forum_menu() - * @ingroup forms + * Returns an overview list of existing forums and containers */ function forum_overview($form, &$form_state) { module_load_include('inc', 'taxonomy', 'taxonomy.admin'); @@ -303,17 +270,11 @@ function forum_overview($form, &$form_state) { } /** - * Returns a select box for available parent terms. - * - * @param $tid - * ID of the term that is being added or edited. - * @param $title - * Title for the select box. - * @param $child_type - * Whether the child is a forum or a container. + * Returns a select box for available parent terms * - * @return - * A select form element. + * @param $tid ID of the term which is being added or edited + * @param $title Title to display the select box with + * @param $child_type Whether the child is forum or container */ function _forum_parent_select($tid, $title, $child_type) { diff --git a/core/modules/forum/forum.css b/core/modules/forum/forum.css index a758bc6..4a67c8b 100644 --- a/core/modules/forum/forum.css +++ b/core/modules/forum/forum.css @@ -1,7 +1,3 @@ -/** - * @file - * Styling for the Forum module. - */ #forum .description { font-size: 0.9em; diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index fb1ba4c..a16858c 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -2,7 +2,7 @@ /** * @file - * Install, update, and uninstall functions for the Forum module. + * Install, update and uninstall functions for the forum module. */ /** diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index ca9bf7e..2f17042 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -236,7 +236,7 @@ function forum_entity_info_alter(&$info) { } /** - * Entity URI callback used in forum_entity_info_alter(). + * Entity URI callback. */ function forum_uri($forum) { return array( @@ -245,7 +245,7 @@ function forum_uri($forum) { } /** - * Checks whether a node can be used in a forum, based on its content type. + * Check whether a content type can be used in a forum. * * @param Drupal\node\Node $node * A node entity. @@ -286,8 +286,7 @@ function forum_node_view(Node $node, $view_mode) { /** * Implements hook_node_validate(). * - * Checks in particular that the node is assigned only a "leaf" term in the - * forum taxonomy. + * Check in particular that only a "leaf" term in the associated taxonomy. */ function forum_node_validate(Node $node, $form) { if (_forum_node_check_node_type($node)) { @@ -323,7 +322,7 @@ function forum_node_validate(Node $node, $form) { /** * Implements hook_node_presave(). * - * Assigns the forum taxonomy when adding a topic from within a forum. + * Assign forum taxonomy when adding a topic from within a forum. */ function forum_node_presave(Node $node) { if (_forum_node_check_node_type($node)) { @@ -485,7 +484,7 @@ function forum_taxonomy_term_delete(Term $term) { /** * Implements hook_comment_publish(). * - * This actually handles the insertion and update of published nodes since + * This actually handles the insert and update of published nodes since * comment_save() calls hook_comment_publish() for all published comments. */ function forum_comment_publish($comment) { @@ -495,12 +494,12 @@ function forum_comment_publish($comment) { /** * Implements hook_comment_update(). * - * The Comment module doesn't call hook_comment_unpublish() when saving - * individual comments, so we need to check for those here. + * Comment module doesn't call hook_comment_unpublish() when saving individual + * comments so we need to check for those here. */ function forum_comment_update($comment) { - // comment_save() calls hook_comment_publish() for all published comments, - // so we need to handle all other values here. + // comment_save() calls hook_comment_publish() for all published comments + // so we to handle all other values here. if (!$comment->status) { _forum_update_forum_index($comment->nid); } @@ -673,8 +672,8 @@ function forum_block_save($delta = '', $edit = array()) { /** * Implements hook_block_view(). * - * Generates a block containing the currently active forum topics and the most - * recently added forum topics. + * Generates a block containing the currently active forum topics and the + * most recently added forum topics. */ function forum_block_view($delta = '') { $query = db_select('forum_index', 'f') @@ -704,12 +703,13 @@ function forum_block_view($delta = '') { } /** - * Render API callback: Lists nodes based on the element's #query property. - * - * This function can be used as a #pre_render callback. - * - * @see forum_block_view() - */ +* A #pre_render callback. Lists nodes based on the element's #query property. +* +* @see forum_block_view() +* +* @return +* A renderable array. +*/ function forum_block_view_pre_render($elements) { $result = $elements['#query']->execute(); if ($node_title_list = node_title_list($result)) { @@ -733,7 +733,7 @@ function forum_form(Node $node, &$form_state) { if (!empty($node->nid)) { $forum_terms = $node->taxonomy_forums; - // If editing, give option to leave shadows. + // If editing, give option to leave shadows $shadow = (count($forum_terms) > 1); $form['shadow'] = array('#type' => 'checkbox', '#title' => t('Leave shadow copy'), '#default_value' => $shadow, '#description' => t('If you move this topic, you can leave a link in the old forum to the new forum.')); $form['forum_tid'] = array('#type' => 'value', '#value' => $node->forum_tid); @@ -746,15 +746,13 @@ function forum_form(Node $node, &$form_state) { * Returns a tree of all forums for a given taxonomy term ID. * * @param $tid - * (optional) Taxonomy term ID of the forum. If not given all forums will be - * returned. - * + * (optional) Taxonomy ID of the forum, if not givin all forums will be returned. * @return * A tree of taxonomy objects, with the following additional properties: - * - num_topics: Number of topics in the forum. - * - num_posts: Total number of posts in all topics. - * - last_post: Most recent post for the forum. - * - forums: An array of child forums. + * - 'num_topics': Number of topics in the forum + * - 'num_posts': Total number of posts in all topics + * - 'last_post': Most recent post for the forum + * - 'forums': An array of child forums */ function forum_forum_load($tid = NULL) { $cache = &drupal_static(__FUNCTION__, array()); @@ -861,17 +859,8 @@ function forum_forum_load($tid = NULL) { } /** - * Calculates the number of new posts in a forum that the user has not yet read. - * - * Nodes are new if they are newer than NODE_NEW_LIMIT. - * - * @param $term - * The term ID of the forum. - * @param $uid - * The user ID. - * - * @return - * The number of new posts in the forum that have not been read by the user. + * Calculate the number of nodes the user has not yet read and are newer + * than NODE_NEW_LIMIT. */ function _forum_topics_unread($term, $uid) { $query = db_select('node', 'n'); @@ -887,23 +876,6 @@ function _forum_topics_unread($term, $uid) { ->fetchField(); } -/** - * Gets all the topics in a forum. - * - * @param $tid - * The term ID of the forum. - * @param $sortby - * One of the following integers indicating the sort criteria: - * - 1: Date - newest first. - * - 2: Date - oldest first. - * - 3: Posts with the most comments first. - * - 4: Posts with the least comments first. - * @param $forum_per_page - * The maximum number of topics to display per page. - * - * @return - * A list of all the topics in a forum. - */ function forum_get_topics($tid, $sortby, $forum_per_page) { global $user, $forum_topic_list_header; @@ -987,8 +959,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) { $first_new_found = FALSE; foreach ($result as $topic) { if ($user->uid) { - // A forum is new if the topic is new, or if there are new comments since - // the user's last visit. + // folder is new if topic is new or there are new comments since last visit if ($topic->forum_tid != $tid) { $topic->new = 0; } @@ -1034,22 +1005,15 @@ function forum_preprocess_block(&$variables) { } /** - * Preprocesses variables for forums.tpl.php. + * Process variables for forums.tpl.php * - * @param $variables - * An array containing the following elements: - * - forums: An array of all forum objects to display for the given taxonomy - * term ID. If tid = 0 then all the top-level forums are displayed. - * - topics: An array of all the topics in the current forum. - * - parents: An array of taxonomy term objects that are ancestors of the - * current term ID. - * - tid: Taxonomy term ID of the current forum. - * - sortby: One of the following integers indicating the sort criteria: - * - 1: Date - newest first. - * - 2: Date - oldest first. - * - 3: Posts with the most comments first. - * - 4: Posts with the least comments first. - * - forum_per_page: The maximum number of topics to display per page. + * The $variables array contains the following arguments: + * - $forums + * - $topics + * - $parents + * - $tid + * - $sortby + * - $forum_per_page * * @see forums.tpl.php */ @@ -1120,15 +1084,12 @@ function template_preprocess_forums(&$variables) { } /** - * Preprocesses variables for forum-list.tpl.php. + * Process variables to format a forum listing. * - * @param $variables - * An array containing the following elements: - * - forums: An array of all forum objects to display for the given taxonomy - * term ID. If tid = 0 then all the top-level forums are displayed. - * - parents: An array of taxonomy term objects that are ancestors of the - * current term ID. - * - tid: Taxonomy term ID of the current forum. + * $variables contains the following information: + * - $forums + * - $parents + * - $tid * * @see forum-list.tpl.php * @see theme_forum_list() @@ -1169,13 +1130,13 @@ function template_preprocess_forum_list(&$variables) { } /** - * Preprocesses variables for forum-topic-list.tpl.php. + * Preprocess variables to format the topic listing. * - * @param $variables - * An array containing the following elements: - * - tid: Taxonomy term ID of the current forum. - * - topics: An array of all the topics in the current forum. - * - forum_per_page: The maximum number of topics to display per page. + * $variables contains the following data: + * - $tid + * - $topics + * - $sortby + * - $forum_per_page * * @see forum-topic-list.tpl.php * @see theme_forum_topic_list() @@ -1225,7 +1186,7 @@ function template_preprocess_forum_topic_list(&$variables) { } } else { - // Make this safe for the template. + // Make this safe for the template $variables['topics'] = array(); } // Give meaning to $tid for themers. $tid actually stands for term id. @@ -1236,16 +1197,14 @@ function template_preprocess_forum_topic_list(&$variables) { } /** - * Preprocesses variables for forum-icon.tpl.php. + * Process variables to format the icon for each individual topic. * - * @param $variables - * An array containing the following elements: - * - new_posts: Indicates whether or not the topic contains new posts. - * - num_posts: The total number of posts in all topics. - * - comment_mode: An integer indicating whether comments are open, closed, - * or hidden. - * - sticky: Indicates whether the topic is sticky. - * - first_new: Indicates whether this is the first topic with new posts. + * $variables contains the following data: + * - $new_posts + * - $num_posts = 0 + * - $comment_mode = 0 + * - $sticky = 0 + * - $first_new * * @see forum-icon.tpl.php * @see theme_forum_icon() @@ -1273,14 +1232,9 @@ function template_preprocess_forum_icon(&$variables) { } /** - * Preprocesses variables for forum-submitted.tpl.php. - * - * The submission information will be displayed in the forum list and topic - * list. + * Process variables to format submission info for display in the forum list and topic list. * - * @param $variables - * An array containing the following elements: - * - topic: The topic object. + * $variables will contain: $topic * * @see forum-submitted.tpl.php * @see theme_forum_submitted() @@ -1290,16 +1244,6 @@ function template_preprocess_forum_submitted(&$variables) { $variables['time'] = isset($variables['topic']->created) ? format_interval(REQUEST_TIME - $variables['topic']->created) : ''; } -/** - * Gets the last time the user viewed a node. - * - * @param $nid - * The node ID. - * - * @return - * The timestamp when the user last viewed this node, if the user has - * previously viewed the node; otherwise NODE_NEW_LIMIT. - */ function _forum_user_last_visit($nid) { global $user; $history = &drupal_static(__FUNCTION__, array()); @@ -1313,21 +1257,6 @@ function _forum_user_last_visit($nid) { return isset($history[$nid]) ? $history[$nid] : NODE_NEW_LIMIT; } -/** - * Gets topic sorting information based on an integer code. - * - * @param $sortby - * One of the following integers indicating the sort criteria: - * - 1: Date - newest first. - * - 2: Date - oldest first. - * - 3: Posts with the most comments first. - * - 4: Posts with the least comments first. - * - * @return - * An array with the following values: - * - field: A field for an SQL query. - * - sort: 'asc' or 'desc'. - */ function _forum_get_topic_order($sortby) { switch ($sortby) { case 1: diff --git a/core/modules/forum/forum.pages.inc b/core/modules/forum/forum.pages.inc index 8538310..29307e7 100644 --- a/core/modules/forum/forum.pages.inc +++ b/core/modules/forum/forum.pages.inc @@ -2,20 +2,11 @@ /** * @file - * User page callbacks for the Forum module. + * User page callbacks for the forum module. */ /** - * Page callback: Prints a forum listing. - * - * @param $forum_term - * A tree of all forums for a given taxonomy term ID. Defaults to NULL. See - * the return object of forum_forum_load() for a complete definition. - * - * @return - * A string containing HTML representing the themed forum listing. - * - * @see forum_menu() + * Menu callback; prints a forum listing. */ function forum_page($forum_term = NULL) { if (!isset($forum_term)) { diff --git a/core/modules/forum/forums.tpl.php b/core/modules/forum/forums.tpl.php index 01919ab..55a760f 100644 --- a/core/modules/forum/forums.tpl.php +++ b/core/modules/forum/forums.tpl.php @@ -2,19 +2,16 @@ /** * @file - * Displays a forum. + * Default theme implementation to display a forum which may contain forum + * containers as well as forum topics. * - * May contain forum containers as well as forum topics. - * - * Available variables: - * - $forums: The forums to display (as processed by forum-list.tpl.php). - * - $topics: The topics to display (as processed by forum-topic-list.tpl.php). + * Variables available: + * - $forums: The forums to display (as processed by forum-list.tpl.php) + * - $topics: The topics to display (as processed by forum-topic-list.tpl.php) * - $forums_defined: A flag to indicate that the forums are configured. * * @see template_preprocess_forums() * @see theme_forums() - * - * @ingroup themeable */ ?> diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php index c64a9c9..49f136d 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -2,7 +2,7 @@ /** * @file - * Tests for forum.module. + * Definition of Drupal\forum\Tests\ForumTest. */ namespace Drupal\forum\Tests; @@ -10,49 +10,14 @@ namespace Drupal\forum\Tests; use Drupal\node\Node; use Drupal\simpletest\WebTestBase; -/** - * Provides automated tests for the Forum module. - */ class ForumTest extends WebTestBase { - - /** - * A user with various administrative privileges. - */ protected $admin_user; - - /** - * A user that can create forum topics and edit its own topics. - */ protected $edit_own_topics_user; - - /** - * A user that can create, edit, and delete forum topics. - */ protected $edit_any_topics_user; - - /** - * A user with no special privileges. - */ protected $web_user; - - /** - * An array representing a container. - */ protected $container; - - /** - * An array representing a forum. - */ protected $forum; - - /** - * An array representing a root forum. - */ protected $root_forum; - - /** - * An array of forum topic node IDs. - */ protected $nids; public static function getInfo() { @@ -63,6 +28,9 @@ class ForumTest extends WebTestBase { ); } + /** + * Enable modules and create users with specific permissions. + */ function setUp() { parent::setUp(array('taxonomy', 'comment', 'forum', 'node', 'block', 'menu', 'help')); // Create users. @@ -90,12 +58,12 @@ class ForumTest extends WebTestBase { } /** - * Tests disabling and re-enabling the Forum module. + * Tests disabling and re-enabling forum. */ function testEnableForumField() { $this->drupalLogin($this->admin_user); - // Disable the Forum module. + // Disable the forum module. $edit = array(); $edit['modules[Core][forum][enable]'] = FALSE; $this->drupalPost('admin/modules', $edit, t('Save configuration')); @@ -103,7 +71,7 @@ class ForumTest extends WebTestBase { module_list(TRUE); $this->assertFalse(module_exists('forum'), t('Forum module is not enabled.')); - // Attempt to re-enable the Forum module and ensure it does not try to + // Attempt to re-enable the forum module and ensure it does not try to // recreate the taxonomy_forums field. $edit = array(); $edit['modules[Core][forum][enable]'] = 'forum'; @@ -114,7 +82,7 @@ class ForumTest extends WebTestBase { } /** - * Tests forum functionality through the admin and user interfaces. + * Login users, create forum nodes, and test forum functionality through the admin and user interfaces. */ function testForum() { //Check that the basic forum install creates a default forum topic @@ -208,10 +176,7 @@ class ForumTest extends WebTestBase { } /** - * Tests that forum nodes can't be added without a parent. - * - * Verifies that forum nodes are not created without choosing "forum" from the - * select list. + * Forum nodes should not be created without choosing forum from select list. */ function testAddOrphanTopic() { // Must remove forum topics to test creating orphan topics. @@ -233,10 +198,9 @@ class ForumTest extends WebTestBase { } /** - * Runs admin tests on the admin user. + * Run admin tests on the admin user. * - * @param object $user - * The logged-in user. + * @param object $user The logged in user. */ private function doAdminTests($user) { // Login the user. @@ -325,7 +289,7 @@ class ForumTest extends WebTestBase { } /** - * Edits the forum taxonomy. + * Edit the forum taxonomy. */ function editForumTaxonomy() { // Backup forum taxonomy. @@ -363,15 +327,15 @@ class ForumTest extends WebTestBase { } /** - * Creates a forum container or a forum. + * Create a forum container or a forum. * * @param $type - * The forum type (forum container or forum). + * Forum type (forum container or forum). * @param $parent - * The forum parent. This defaults to 0, indicating a root forum. - * + * Forum parent (default = 0 = a root forum; >0 = a forum container or + * another forum). * @return - * The created taxonomy term data. + * taxonomy_term_data created. */ function createForum($type, $parent = 0) { // Generate a random name/description. @@ -404,7 +368,7 @@ class ForumTest extends WebTestBase { } /** - * Deletes a forum. + * Delete a forum. * * @param $tid * The forum ID. @@ -425,7 +389,7 @@ class ForumTest extends WebTestBase { } /** - * Runs basic tests on the indicated user. + * Run basic tests on the indicated user. * * @param $user * The logged in user. @@ -444,15 +408,15 @@ class ForumTest extends WebTestBase { } /** - * Creates a forum topic. + * Create forum topic. * * @param array $forum - * A forum array. + * Forum array. * @param boolean $container - * TRUE if $forum is a container; FALSE otherwise. + * True if $forum is a container. * * @return object - * The created topic node. + * Topic node created. */ function createForumTopic($forum, $container = FALSE) { // Generate a random subject/body. @@ -494,7 +458,7 @@ class ForumTest extends WebTestBase { } /** - * Verifies that the logged in user has access to a forum node. + * Verify the logged in user has access to a forum nodes. * * @param $node_user * The user who creates the node. @@ -574,12 +538,10 @@ class ForumTest extends WebTestBase { } /** - * Verifies the display of a forum page. + * Verify display of forum page. * * @param $forum - * A row from the taxonomy_term_data table in an array. - * @param $parent - * (optional) An array representing the forum's parent. + * A row from taxonomy_term_data table in array. */ private function verifyForumView($forum, $parent = NULL) { // View forum page. @@ -599,10 +561,9 @@ class ForumTest extends WebTestBase { } /** - * Generates forum topics to test the display of an active forum block. + * Generate forum topics to test display of active forum block. * - * @param array $forum - * The forum array (a row from taxonomy_term_data table). + * @param array $forum Forum array (a row from taxonomy_term_data table). */ private function generateForumTopics($forum) { $this->nids = array(); @@ -613,10 +574,10 @@ class ForumTest extends WebTestBase { } /** - * Views forum topics to test the display of an active forum block. + * View forum topics to test display of active forum block. * - * @todo The logic here is completely incorrect, since the active forum topics - * block is determined by comments on the node, not by views. + * @todo The logic here is completely incorrect, since the active + * forum topics block is determined by comments on the node, not by views. * @todo DIE * * @param $nids diff --git a/core/modules/locale/lib/Drupal/locale/LocaleLookup.php b/core/modules/locale/lib/Drupal/locale/LocaleLookup.php deleted file mode 100644 index 897eaa1..0000000 --- a/core/modules/locale/lib/Drupal/locale/LocaleLookup.php +++ /dev/null @@ -1,88 +0,0 @@ -langcode = $langcode; - $this->context = (string) $context; - - // Add the current user's role IDs to the cache key, this ensures that, for - // example, strings for admin menu items and settings forms are not cached - // for anonymous users. - $rids = implode(':', array_keys($GLOBALS['user']->roles)); - parent::__construct("locale:$langcode:$context:$rids", 'cache'); - } - - /** - * Overrides DrupalCacheArray::resolveCacheMiss(). - */ - protected function resolveCacheMiss($offset) { - $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context", array( - ':language' => $this->langcode, - ':source' => $offset, - ':context' => $this->context, - ))->fetchObject(); - if ($translation) { - if ($translation->version != VERSION) { - // This is the first use of this string under current Drupal version. - // Update the {locales_source} table to indicate the string is current. - db_update('locales_source') - ->fields(array('version' => VERSION)) - ->condition('lid', $translation->lid) - ->execute(); - } - $value = !empty($translation->translation) ? $translation->translation : TRUE; - } - else { - // We don't have the source string, update the {locales_source} table to - // indicate the string is not translated. - db_merge('locales_source') - ->insertFields(array( - 'location' => request_uri(), - 'version' => VERSION, - )) - ->key(array( - 'source' => $offset, - 'context' => $this->context, - )) - ->execute(); - $value = TRUE; - } - $this->storage[$offset] = $value; - // Disabling the usage of string caching allows a module to watch for - // the exact list of strings used on a page. From a performance - // perspective that is a really bad idea, so we have no user - // interface for this. Be careful when turning this option off! - if (variable_get('locale_cache_strings', 1)) { - $this->persist($offset); - } - return $value; - } -} diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleCommentLanguageTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleCommentLanguageTest.php index 16fc83f..9bb8bc0 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleCommentLanguageTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleCommentLanguageTest.php @@ -38,7 +38,7 @@ class LocaleCommentLanguageTest extends WebTestBase { $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); // Set "Article" content type to use multilingual support. - $edit = array('node_type_language' => 1); + $edit = array('node_type_language_hidden' => FALSE); $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); // Enable content language negotiation UI. diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php index 0c5cea3..fbedc33 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php @@ -82,9 +82,9 @@ class LocaleContentTest extends WebTestBase { // Set "Basic page" content type to use multilingual support. $this->drupalGet('admin/structure/types/manage/page'); - $this->assertText(t('Multilingual support'), t('Multilingual support fieldset present on content type configuration form.')); + $this->assertText(t('Language settings'), t('Multilingual support fieldset present on content type configuration form.')); $edit = array( - 'node_type_language' => 1, + 'node_type_language_hidden' => FALSE, ); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), t('Basic page content type has been updated.')); @@ -152,7 +152,7 @@ class LocaleContentTest extends WebTestBase { // Set "Article" content type to use multilingual support. $this->drupalGet('admin/structure/types/manage/article'); $edit = array( - 'node_type_language' => 1, + 'node_type_language_hidden' => FALSE, ); $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Article')), t('Article content type has been updated.')); diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleMultilingualFieldsTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleMultilingualFieldsTest.php index 2a8299a..92af494 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleMultilingualFieldsTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleMultilingualFieldsTest.php @@ -44,7 +44,7 @@ class LocaleMultilingualFieldsTest extends WebTestBase { // Set "Basic page" content type to use multilingual support. $edit = array( - 'node_type_language' => 1, + 'node_type_language_hidden' => FALSE, ); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), t('Basic page content type has been updated.')); @@ -60,7 +60,7 @@ class LocaleMultilingualFieldsTest extends WebTestBase { */ function testMultilingualNodeForm() { // Create "Basic page" content. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = node_type_get_default_langcode('page'); $title_key = "title"; $title_value = $this->randomName(8); $body_key = "body[$langcode][0][value]"; @@ -70,7 +70,6 @@ class LocaleMultilingualFieldsTest extends WebTestBase { $edit = array(); $edit[$title_key] = $title_value; $edit[$body_key] = $body_value; - $edit['langcode'] = 'en'; $this->drupalPost('node/add/page', $edit, t('Save')); // Check that the node exists in the database. @@ -109,7 +108,7 @@ class LocaleMultilingualFieldsTest extends WebTestBase { */ function testMultilingualDisplaySettings() { // Create "Basic page" content. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = node_type_get_default_langcode('page'); $title_key = "title"; $title_value = $this->randomName(8); $body_key = "body[$langcode][0][value]"; @@ -119,7 +118,6 @@ class LocaleMultilingualFieldsTest extends WebTestBase { $edit = array(); $edit[$title_key] = $title_value; $edit[$body_key] = $body_value; - $edit['langcode'] = 'en'; $this->drupalPost('node/add/page', $edit, t('Save')); // Check that the node exists in the database. diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php index 72868e9..098e276 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php @@ -52,11 +52,9 @@ class LocaleUninstallTest extends WebTestBase { $this->assertEqual(drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode, $this->langcode, t('Current language: %lang', array('%lang' => drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode))); // Enable multilingual workflow option for articles. - variable_set('node_type_language_article', 1); - + variable_set('node_type_language_hidden_article',FALSE); // Change JavaScript translations directory. variable_set('locale_js_directory', 'js_translations'); - // Build the JavaScript translation file for French. $user = $this->drupalCreateUser(array('translate interface', 'access administration pages')); $this->drupalLogin($user); diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index ae4c5f0..829af97 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -11,8 +11,6 @@ * Gettext portable object files are supported. */ -use Drupal\locale\LocaleLookup; - /** * Regular expression pattern used to localize JavaScript strings. */ @@ -408,11 +406,76 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) { $langcode = isset($langcode) ? $langcode : $language_interface->langcode; - // Strings are cached by langcode, context and roles, using instances of the - // LocaleLookup class to handle string lookup and caching. - if (!isset($locale_t[$langcode][$context]) && isset($language_interface)) { - $locale_t[$langcode][$context] = new LocaleLookup($langcode, $context); + // Store database cached translations in a static variable. Only build the + // cache after $language_interface has been set to avoid an unnecessary cache + // rebuild. + if (!isset($locale_t[$langcode]) && isset($language_interface)) { + $locale_t[$langcode] = array(); + // Disabling the usage of string caching allows a module to watch for + // the exact list of strings used on a page. From a performance + // perspective that is a really bad idea, so we have no user + // interface for this. Be careful when turning this option off! + if (variable_get('locale_cache_strings', 1) == 1) { + if ($cache = cache()->get('locale:' . $langcode)) { + $locale_t[$langcode] = $cache->data; + } + elseif (lock_acquire('locale_cache_' . $langcode)) { + // Refresh database stored cache of translations for given language. + // We only store short strings used in current version, to improve + // performance and consume less memory. + $result = db_query("SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.version = :version AND LENGTH(s.source) < :length", array(':language' => $langcode, ':version' => VERSION, ':length' => variable_get('locale_cache_length', 75))); + foreach ($result as $data) { + $locale_t[$langcode][$data->context][$data->source] = (empty($data->translation) ? TRUE : $data->translation); + } + cache()->set('locale:' . $langcode, $locale_t[$langcode]); + lock_release('locale_cache_' . $langcode); + } + } } + + // If we have the translation cached, skip checking the database + if (!isset($locale_t[$langcode][$context][$string])) { + + // We do not have this translation cached, so get it from the DB. + $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context", array( + ':language' => $langcode, + ':source' => $string, + ':context' => (string) $context, + ))->fetchObject(); + if ($translation) { + // We have the source string at least. + // Cache translation string or TRUE if no translation exists. + $locale_t[$langcode][$context][$string] = (empty($translation->translation) ? TRUE : $translation->translation); + + if ($translation->version != VERSION) { + // This is the first use of this string under current Drupal version. Save version + // and clear cache, to include the string into caching next time. Saved version is + // also a string-history information for later pruning of the tables. + db_update('locales_source') + ->fields(array('version' => VERSION)) + ->condition('lid', $translation->lid) + ->execute(); + cache()->deletePrefix('locale:'); + } + } + else { + // We don't have the source string, cache this as untranslated. + db_merge('locales_source') + ->insertFields(array( + 'location' => request_uri(), + 'version' => VERSION, + )) + ->key(array( + 'source' => $string, + 'context' => (string) $context, + )) + ->execute(); + $locale_t[$langcode][$context][$string] = TRUE; + // Clear locale cache so this string can be added in a later request. + cache()->deletePrefix('locale:'); + } + } + return ($locale_t[$langcode][$context][$string] === TRUE ? $string : $locale_t[$langcode][$context][$string]); } diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc index 6bb7969..ffa796c 100644 --- a/core/modules/node/content_types.inc +++ b/core/modules/node/content_types.inc @@ -185,11 +185,42 @@ function node_type_form($form, &$form_state, $type = NULL) { '#description' => t('Users with the Administer content permission will be able to override these options.'), ); if (module_exists('language')) { - $form['workflow']['node_type_language'] = array( + $languages = language_list(); + $lang_options = array( + LANGUAGE_NOT_SPECIFIED => t('Not specified'), + LANGUAGE_NOT_APPLICABLE => t('Not applicable'), + LANGUAGE_MULTIPLE => t('Multiple languages'), + 'site_default' => t("Site's default language"), + 'current_interface' => t('Current interface language'), + 'authors_default' => t("Author's preferred language"), + ); + $lang_descriptions = array( + LANGUAGE_NOT_SPECIFIED => t('Use this setting if the language is not (yet) specified'), + LANGUAGE_NOT_APPLICABLE => t('Use this setting if an language assignement is not applicable'), + LANGUAGE_MULTIPLE => t('Use this setting if a single content contains multiple languages'), + ); + foreach ($languages as $langcode => $language) { + $lang_options[$langcode] = $language->name; + } + + $form['language'] = array( + '#type' => 'fieldset', + '#title' => t('Language settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'additional_settings', + ); + $form['language']['node_type_language_default'] = array( + '#type' => 'select', + '#title' => t('Default language'), + '#options' => $lang_options, + '#default_value' => variable_get('node_type_language_default_' . $type->type, 'site_default'), + '#description' => t('Explanation of the language options is found on the languages list page.', array('@languages_list_page' => url('admin/config/regional/language'))), + ); + $form['language']['node_type_language_hidden'] = array( '#type' => 'checkbox', - '#title' => t('Multilingual support'), - '#default_value' => variable_get('node_type_language_' . $type->type, 0), - '#description' => t('Add a language selection field to the editing form, allowing you to select from one of the enabled 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'))), + '#title' => t('Hide language selector'), + '#default_value' => variable_get('node_type_language_hidden_' . $type->type, TRUE), ); } $form['display'] = array( diff --git a/core/modules/node/content_types.js b/core/modules/node/content_types.js index 5c1c44e..7c0abdd 100644 --- a/core/modules/node/content_types.js +++ b/core/modules/node/content_types.js @@ -21,6 +21,15 @@ Drupal.behaviors.contentTypes = { } return vals.join(', '); }); + $('fieldset#edit-language', context).drupalSetSummary(function(context) { + var vals = []; + + $('input:checked', context).next('label').each(function() { + vals.push(Drupal.checkPlain($(this).text())); + }); + + return vals.join(', '); + }); $context.find('fieldset#edit-display').drupalSetSummary(function(context) { var vals = []; var $context = $(context); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php new file mode 100644 index 0000000..16d9275 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php @@ -0,0 +1,70 @@ + 'Node type initial language', + 'description' => 'Tests node type initial language settings.', + 'group' => 'Node', + ); + } + + function setUp() { + parent::setUp(array('language')); + $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer languages')); + $this->drupalLogin($web_user); + } + + /** + * Tests the node type initial language defaults, and modify them. + * + * The default initial language must be the site's default, and the language + * locked option must be on. + */ + function testNodeTypeInitialLanguageDefaults() { + $this->drupalGet('admin/structure/types/manage/article'); + $this->assertOptionSelected('edit-node-type-language-default', 'site_default', 'The default inital language is the site default.'); + $this->assertFieldChecked('edit-node-type-language-hidden', 'Language selector is hidden by default.'); + + $this->drupalGet('node/add/article'); + $this->assertNoField('langcode', 'Language is not selectable on node add/edit page by default.'); + + // Adds a new language and set it as default. + $edit = array( + 'predefined_langcode' => 'hu', + ); + $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); + $edit = array( + 'site_default' => 'hu', + ); + $this->drupalPost('admin/config/regional/language', $edit, t('Save configuration')); + + // Tests the initial language after changing the site default language. + // First unhide the language selector + $edit = array( + 'node_type_language_hidden' => FALSE, + ); + $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); + $this->drupalGet('node/add/article'); + $this->assertField('langcode', "Language is selectable on node add/edit page when language not hidden."); + $this->assertOptionSelected('edit-langcode', 'hu', 'The inital language is the site default on the node add page after the site default language is changed.'); + + // Changes the inital language settings. + $edit = array( + 'node_type_language_default' => 'en', + ); + $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); + $this->drupalGet('node/add/article'); + $this->assertOptionSelected('edit-langcode', 'en', 'The inital language is the defined language.'); + } +} diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 6f806e9..4738839 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -458,9 +458,12 @@ function node_uninstall() { ->condition('name', 'node_options_' . $type) ->condition('name', 'node_submitted_' . $type) ->condition('name', 'node_permissions_' . $type) - ->condition('name', 'node_type_language_' . $type) + ->condition('name', 'node_type_language_default_' . $type) + ->condition('name', 'node_type_language_hidden_' . $type) ) ->execute(); + // TODO: node_type_language_translation_enabled_ in the translation module + // ->condition('name', 'node_type_language_translation_enabled_' . $type) } // Delete node search ranking variables. @@ -520,9 +523,9 @@ function _update_7000_node_get_types() { function node_update_8001() { $types = db_query('SELECT type FROM {node_type}')->fetchCol(); foreach ($types as $type) { - $language = variable_get('language_content_type_' . $type); - if (isset($language)) { - variable_set('node_type_language_' . $type, $language); + $node_type_language = variable_get('language_content_type_' . $type); + if (isset($node_type_language)) { + variable_set('node_type_language_' . $type, $node_type_language); } variable_del('language_content_type_' . $type); } @@ -543,6 +546,29 @@ function node_update_8002() { } /** - * @} End of "addtogroup updates-7.x-to-8.x". + * Rename node type language variable names. + */ +function node_update_8003() { + $types = db_query('SELECT type FROM {node_type}')->fetchCol(); + foreach ($types as $type) { + variable_set('node_type_language_default_' . $type, LANGUAGE_NOT_SPECIFIED); + $node_type_language = variable_get('node_type_language_' . $type, 0); + if ($node_type_language == 0) { + variable_set('node_type_language_hidden_' . $type, TRUE); + } + if ($node_type_language == 2) { + // Translation was enabled, so enable it again and + // unhide the language selector. Because if language is + // LANGUAGE_NOT_SPECIFIED and the selector hidden, translation + // cannot be enabled. + variable_set('node_type_language_hidden_' . $type, FALSE); + variable_set('node_type_language_translation_enabled_' . $type, 2); + } + variable_del('node_type_language_' . $type); + } +} + +/** + * @} End of "addtogroup updates-7.x-to-8.x" * The next series of updates should start at 9000. */ diff --git a/core/modules/node/node.module b/core/modules/node/node.module index e787c7d..6e6af36 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -629,6 +629,47 @@ function node_field_extra_fields() { } /** + * Get the default language for a node type. + * + * @param string $node_type + * The type of node. + * + * @return (string) + * The language code of the node type's default langcode. + */ +function node_type_get_default_langcode($node_type) { + $default_value = variable_get('node_type_language_default_' . $node_type, 'site_default'); + + $language_interface = drupal_container()->get(LANGUAGE_TYPE_INTERFACE); + + if ($default_value == LANGUAGE_NOT_SPECIFIED) { + return LANGUAGE_NOT_SPECIFIED; + } + + switch ($default_value) { + case 'site_default': + $default_value = language_default()->langcode; + break; + + case 'current_interface': + $default_value = $language_interface->langcode; + break; + + case 'authors_default': + global $user; + if (!empty($user->preferred_langcode)) { + $default_value = $user->preferred_langcode; + } + else { + $default_value = $language_interface->langcode; + } + break; + } + + return $default_value; +} + +/** * Deletes a node type from the database. * * @param $name @@ -1132,7 +1173,7 @@ function node_revision_delete($revision_id) { */ function node_view(Node $node, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = drupal_container()->get(LANGUAGE_TYPE_CONTENT)->langcode; + $langcode = $GLOBALS['language_content']->langcode; } // Populate $node->content with a render() array. @@ -1194,7 +1235,7 @@ function node_view(Node $node, $view_mode = 'full', $langcode = NULL) { */ function node_build_content(Node $node, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = drupal_container()->get(LANGUAGE_TYPE_CONTENT)->langcode; + $langcode = $GLOBALS['language_content']->langcode; } // Remove previously built content, if exists. diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 70383b7..5b120dc 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -91,7 +91,7 @@ function node_add($type) { 'uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => node_type_get_default_langcode($type) )); drupal_set_title(t('Create @name', array('@name' => $types[$type]->name)), PASS_THROUGH); $output = drupal_get_form($type . '_node_form', $node); @@ -186,7 +186,7 @@ function node_form($form, &$form_state, Node $node) { // @todo D8: Remove. Modules should access the node using $form_state['node']. $form['#node'] = $node; - if (variable_get('node_type_language_' . $node->type, 0) && module_exists('language')) { + if (module_exists('language')) { $languages = language_list(); $language_options = array(); foreach ($languages as $langcode => $language) { @@ -199,13 +199,15 @@ function node_form($form, &$form_state, Node $node) { '#options' => $language_options, '#empty_value' => LANGUAGE_NOT_SPECIFIED, ); + if (variable_get('node_type_language_hidden_' . $node->type, TRUE)) { + $form['langcode']['#access'] = FALSE; + } } else { $form['langcode'] = array( '#type' => 'value', - // New nodes without multilingual support get the default language, old - // nodes keep their language if language.module is not available. - '#value' => !isset($form['#node']->nid) ? language_default()->langcode : $node->langcode, + // Use default language when language module is inactive. + '#value' => $node->langcode, ); } diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php index 096729f..961df51 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php @@ -42,7 +42,8 @@ class PathLanguageTest extends PathTestBase { */ function testAliasTranslation() { // Set 'page' content type to enable translation. - variable_set('node_type_language_page', TRANSLATION_ENABLED); + variable_set('node_type_language_hidden_page', FALSE); + variable_set('node_type_language_translation_enabled_page', TRANSLATION_ENABLED); $english_node = $this->drupalCreateNode(array('type' => 'page')); $english_alias = $this->randomName(); diff --git a/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php b/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php index 6b89cad..168166e 100644 --- a/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php +++ b/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php @@ -50,8 +50,7 @@ class PollTranslateTest extends PollTestBase { // Set "Poll" content type to use multilingual support with translation. $this->drupalGet('admin/structure/types/manage/poll'); - $edit = array(); - $edit['node_type_language'] = TRANSLATION_ENABLED; + $edit = array('node_type_language_hidden' => FALSE, 'node_type_language_translation_enabled' => TRANSLATION_ENABLED); $this->drupalPost('admin/structure/types/manage/poll', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Poll')), t('Poll content type has been updated.')); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 9ba7c4c..168f2fc 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -116,7 +116,6 @@ function system_requirements($phase) { 'session', 'SimpleXML', 'SPL', - 'tokenizer', 'xml', ); foreach ($required_extensions as $extension) { diff --git a/core/modules/system/tests/upgrade/upgrade.language.test b/core/modules/system/tests/upgrade/upgrade.language.test index 91e1fec..2f2eb46 100644 --- a/core/modules/system/tests/upgrade/upgrade.language.test +++ b/core/modules/system/tests/upgrade/upgrade.language.test @@ -72,12 +72,11 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase { $this->assertRaw('', 'There is a Chuvash translation of the node.'); $this->assertLinkByHref("node/$translation_nid", 0, 'The translation table links to the Chuvash translation.'); $this->assertRaw('', 'There is no Catalan translation of this node.'); - // Check for node content type settings upgrade. $this->drupalGet('node/add/article'); - $this->assertFieldByName('langcode'); + $this->assertField('langcode', 'There is a langauge selector'); $this->drupalGet('node/add/page'); - $this->assertNoFieldByName('langcode'); + $this->assertNoField('langcode', 'There is no langauge selector'); // Check that the user language value was retained in both langcode and // preferred_langcode. diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index ba74a9a..30eba40 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -584,7 +584,7 @@ function taxonomy_term_delete_multiple(array $tids) { */ function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = drupal_container()->get(LANGUAGE_TYPE_CONTENT)->langcode; + $langcode = $GLOBALS['language_content']->langcode; } field_attach_prepare_view('taxonomy_term', array($term->tid => $term), $view_mode, $langcode); @@ -1128,7 +1128,7 @@ function taxonomy_field_widget_info_alter(&$info) { */ function taxonomy_options_list($field, $instance, $entity_type, $entity) { $function = !empty($field['settings']['options_list_callback']) ? $field['settings']['options_list_callback'] : 'taxonomy_allowed_values'; - return $function($field, $instance, $entity_type, $entity); + return $function($field); } /** @@ -1281,20 +1281,10 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance, * * @param $field * The field definition. - * @param $instance - * The instance definition. It is recommended to only use instance level - * properties to filter out values from a list defined by field level - * properties. - * @param $entity_type - * The entity type the field is attached to. - * @param $entity - * The entity object the field is attached to, or NULL if no entity - * exists (e.g. in field settings page). - * * @return * The array of valid terms for this field, keyed by term id. */ -function taxonomy_allowed_values($field, $instance, $entity_type, $entity) { +function taxonomy_allowed_values($field) { $options = array(); foreach ($field['settings']['allowed_values'] as $tree) { if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) { diff --git a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php index e09c8b0..a685376 100644 --- a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php +++ b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php @@ -42,8 +42,7 @@ class TranslationTest extends WebTestBase { // Set "Basic page" content type to use multilingual support with // translation. $this->drupalGet('admin/structure/types/manage/page'); - $edit = array(); - $edit['node_type_language'] = TRANSLATION_ENABLED; + $edit = array('node_type_language_hidden' => FALSE, 'node_type_language_translation_enabled' => TRANSLATION_ENABLED); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), t('Basic page content type has been updated.')); @@ -222,7 +221,7 @@ class TranslationTest extends WebTestBase { // Disable translation support to check that the language switcher is left // untouched only for new nodes. $this->drupalLogin($this->admin_user); - $edit = array('node_type_language' => 0); + $edit = array('node_type_language_hidden' => TRUE, 'node_type_language_translation_enabled' => FALSE); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->drupalLogin($this->translator); diff --git a/core/modules/translation/translation.js b/core/modules/translation/translation.js new file mode 100644 index 0000000..00ccd83 --- /dev/null +++ b/core/modules/translation/translation.js @@ -0,0 +1,21 @@ +(function ($) { + +"use strict"; + +Drupal.behaviors.TranslationEnable = { + attach: function (context) { + $('#edit-node-type-language-default, #edit-node-type-language-hidden', context).change(function(context) { + var default_language = $('#edit-node-type-language-default').val(); + + if ((default_language == 'und' || default_language == 'zxx' || default_language == 'mul') && $('#edit-node-type-language-hidden').attr('checked')) { + $('.form-item-node-type-language-translation-enabled').hide(); + $('#edit-node-type-language-translation-enabled').removeAttr('checked'); + } else { + $('.form-item-node-type-language-translation-enabled').show(); + } + }); + $('#edit-node-type-language-default', context).trigger('change'); + } +}; + +})(jQuery); \ No newline at end of file diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index b2c0635..9768e77 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -119,11 +119,30 @@ function translation_permission() { * 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']['js'] = array( + drupal_get_path('module', 'translation') . '/translation.js', + ); // 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')); - // 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['language']['node_type_language_translation_enabled'] = array( + '#type' => 'checkbox', + '#title' => t('Enable translation'), + '#return_value' => TRANSLATION_ENABLED, + '#default_value' => variable_get('node_type_language_translation_enabled_' . $form['#node_type']->type, FALSE), + '#element_validate' => array('translation_node_type_language_translation_enabled_validate'), + '#prefix' => "", + ); +} + +/** + * Checks if default language=none && default language=locked + */ +function translation_node_type_language_translation_enabled_validate($element, &$form_state, $form){ + $language_default = (($form_state['values']['node_type_language_default'] == 'und' || $form_state['values']['node_type_language_default'] == 'zxx' || $form_state['values']['node_type_language_default'] == 'mul') ? TRUE : FALSE); + if ($language_default && $form_state['values']['node_type_language_hidden'] && $form_state['values']['node_type_language_translation_enabled'] == TRANSLATION_ENABLED) { + form_set_error('node_type_language_translation_enabled', t('Translation cannot be enabled if no default language is set and locked.')); + } } /** @@ -461,7 +480,7 @@ function translation_node_get_translations($tnid) { * TRUE if translation is supported, and FALSE if not. */ function translation_supported_type($type) { - return variable_get('node_type_language_' . $type, 0) == TRANSLATION_ENABLED; + return variable_get('node_type_language_translation_enabled_' . $type, 0) == TRANSLATION_ENABLED; } /** diff --git a/core/modules/update/update.fetch.inc b/core/modules/update/update.fetch.inc index 8cd0909..92f4cc1 100644 --- a/core/modules/update/update.fetch.inc +++ b/core/modules/update/update.fetch.inc @@ -363,12 +363,7 @@ function _update_cron_notify() { else { $target_language = $default_language; } - $message = drupal_mail('update', 'status_notify', $target, $target_language, $params); - // Track when the last mail was successfully sent to avoid sending - // too many e-mails. - if ($message['result']) { - variable_set('update_last_email_notification', REQUEST_TIME); - } + drupal_mail('update', 'status_notify', $target, $target_language, $params); } } } diff --git a/core/modules/update/update.install b/core/modules/update/update.install index 3495a61..406b9ae 100644 --- a/core/modules/update/update.install +++ b/core/modules/update/update.install @@ -82,7 +82,6 @@ function update_uninstall() { 'update_check_frequency', 'update_fetch_url', 'update_last_check', - 'update_last_email_notification', 'update_notification_threshold', 'update_notify_emails', 'update_max_fetch_attempts', diff --git a/core/modules/update/update.module b/core/modules/update/update.module index 2293799..aed68ad 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -300,18 +300,13 @@ function update_cron() { // configured notifications about the new status. update_refresh(); update_fetch_data(); + _update_cron_notify(); } else { // Otherwise, see if any individual projects are now stale or still // missing data, and if so, try to fetch the data. update_get_available(TRUE); } - if ((REQUEST_TIME - variable_get('update_last_email_notification', 0)) > $interval) { - // If configured time between notifications elapsed, send email about - // updates possibly available. - module_load_include('inc', 'update', 'update.fetch'); - _update_cron_notify(); - } // Clear garbage from disk. update_clear_update_disk_cache(); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 6f21c5c..6a04d7c 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -2367,7 +2367,7 @@ function user_view_page($account) { */ function user_view($account, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = drupal_container()->get(LANGUAGE_TYPE_CONTENT)->langcode; + $langcode = $GLOBALS['language_content']->langcode; } // Retrieve all profile fields and attach to $account->content. @@ -2404,7 +2404,7 @@ function user_view($account, $view_mode = 'full', $langcode = NULL) { */ function user_build_content($account, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = drupal_container()->get(LANGUAGE_TYPE_CONTENT)->langcode; + $langcode = $GLOBALS['language_content']->langcode; } // Remove previously built content, if exists.
ChuvashCatalann/aNot translated