From eae3900a8bf050242e9af29bfe08b786cd5ab895 Mon Sep 17 00:00:00 2001 From: Alexander Schedrov Date: Sat, 25 Oct 2014 10:29:17 +0300 Subject: [PATCH 07/17] Fixed codesniffer notices in faq.admin.inc. --- faq.admin.inc | 38 +++++++++++++---------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/faq.admin.inc b/faq.admin.inc index 72cccac..9409a8d 100644 --- a/faq.admin.inc +++ b/faq.admin.inc @@ -8,15 +8,15 @@ /** * Generates the settings form for the FAQ module. * - * @param $op + * @param string $op * Default value is NULL; determines what are the permissions of the current * user on the FAQ. - * @return + * + * @return string * The output, which contains the HTML code for the settings form generated by * drupal_get_form() function. */ function faq_settings_page($op = NULL) { - $output = drupal_get_form('faq_general_settings_form'); return $output; @@ -25,7 +25,7 @@ function faq_settings_page($op = NULL) { /** * Define a form to edit the page header and descriptive text. * - * @return + * @return array * The general settings form code stored in the $form variable, before * converted to HTML. */ @@ -48,7 +48,12 @@ function faq_general_settings_form($form) { $form['faq_custom_breadcrumbs'] = array( '#type' => 'checkbox', '#title' => t('Create custom breadcrumbs for the FAQ'), - '#description' => t('This option set the breadcrumb path to "%home > %faqtitle > category trail".', array('%home' => t('Home'), '%faqtitle' => variable_get('faq_title', 'Frequently Asked Questions'))), + '#description' => t('This option set the breadcrumb path to "%home > %faqtitle > category trail".', + array( + '%home' => t('Home'), + '%faqtitle' => variable_get('faq_title', 'Frequently Asked Questions'), + ) + ), '#default_value' => variable_get('faq_custom_breadcrumbs', TRUE), ); @@ -58,7 +63,7 @@ function faq_general_settings_form($form) { /** * Define the elements for the FAQ Settings page - Questions tab. * - * @return + * @return array * The form code inside the $form array. */ function faq_questions_settings_form($form, &$form_state) { @@ -259,7 +264,7 @@ function faq_questions_settings_form($form, &$form_state) { /** * Define the elements for the FAQ Settings page - categories tab. * - * @return + * @return array * The form code inside the $form array. */ function faq_categories_settings_form($form, &$form_state) { @@ -459,9 +464,10 @@ function faq_categories_settings_form_submit($form, &$form_state) { /** * Define the elements for the FAQ Settings page - order tab. * - * @param $form_state + * @param array $form_state * Store the submitted form values. - * @return + * + * @return array * The form code, before being converted to HTML format. */ function faq_order_settings_form($form, $form_state, $category = NULL) { @@ -541,7 +547,7 @@ function faq_order_settings_form($form, $form_state, $category = NULL) { // $default_weight is an integer. $query->addExpression("COALESCE(w.weight, $default_weight)", 'effective_weight'); // Doesn't work in Postgres. - //$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight)); + // $query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight)); if (empty($category)) { $category = 0; @@ -594,16 +600,16 @@ function faq_order_settings_form($form, $form_state, $category = NULL) { ); } - return $form; } /** * Function set the rebuild of the form in the FAQ Settings - Weight tab. * - * @param $form + * @param array $form * Array, containing the form structure. - * @param &$form_state + * + * @param array &$form_state * The 'rebuild' key inside $form_state['rebuild'] structure, overrides the * 'redirect' key: when it is set to TRUE, the form will be rebuilt from * scratch and displayed on screen. @@ -615,9 +621,10 @@ function faq_order_settings_choose_cat_form_submit($form, &$form_state) { /** * Save the options set by the user in the FAQ Settings - Weight tab. * - * @param $form + * @param array $form * Array, containing the form structure. - * @param &$form_state + * + * @param array &$form_state * $form_state['values'] stores the submitted values from the form. */ function faq_order_settings_reorder_form_submit($form, &$form_state) { @@ -663,4 +670,3 @@ function faq_order_settings_reorder_form_submit($form, &$form_state) { drupal_set_message(t('Configuration has been updated.')); } } - From 29755abca880162e6f08758c9ed72bea960084b7 Mon Sep 17 00:00:00 2001 From: Alexander Schedrov Date: Sat, 25 Oct 2014 10:32:38 +0300 Subject: [PATCH 08/17] Fixed notices in faq.views.inc. --- views/faq.views.inc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/views/faq.views.inc b/views/faq.views.inc index 6b7336e..3b0a07a 100644 --- a/views/faq.views.inc +++ b/views/faq.views.inc @@ -1,6 +1,11 @@ Date: Sat, 25 Oct 2014 10:34:26 +0300 Subject: [PATCH 09/17] Fixed codesniffer notices in faq.views_default.inc. --- views/faq.views_default.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/views/faq.views_default.inc b/views/faq.views_default.inc index d6f9700..c7cbd09 100644 --- a/views/faq.views_default.inc +++ b/views/faq.views_default.inc @@ -11,7 +11,7 @@ function faq_views_default_views() { $export = array(); - $view = new view; + $view = new view(); $view->name = 'faq'; $view->description = 'FAQ listings'; $view->tag = 'default'; @@ -417,4 +417,3 @@ function faq_views_default_views() { return $export; } - From 32151a3953f1bb3455ccfb5d5a160083ce060c49 Mon Sep 17 00:00:00 2001 From: Alexander Schedrov Date: Sat, 25 Oct 2014 11:44:40 +0300 Subject: [PATCH 10/17] Fixed codesniffer notices in faq.install. --- faq.install | 137 +++++++++++++----------- 1 file changed, 75 insertions(+), 62 deletions(-) diff --git a/faq.install b/faq.install index bacdba9..92281ed 100644 --- a/faq.install +++ b/faq.install @@ -8,7 +8,7 @@ /** * Define the 'faq_weights' and 'faq_questions' table structures. * - * @return + * @return array * The schema which contains the structure for the faq module's tables. */ function faq_schema() { @@ -73,7 +73,6 @@ function faq_schema() { 'primary key' => array('nid', 'vid'), ); - return $schema; } @@ -86,7 +85,6 @@ function faq_install() { variable_set('node_type_faq', array('status')); $t = get_t(); - // Ensure the FAQ node type is available. node_types_rebuild(); $types = node_type_get_types(); @@ -98,9 +96,10 @@ function faq_install() { field_update_instance($body_instance); - _faq_add_custom_fields(); // Add the detailed question field - _faq_shift_fields_down(); // Shift all fields below the body field one down and put detailed question field where the body field was - + // Add the detailed question field. + _faq_add_custom_fields(); + // Shift all fields below the body field one down and put detailed question field where the body field was. + _faq_shift_fields_down(); } /** @@ -143,13 +142,13 @@ function faq_uninstall() { // Block settings. variable_del('faq_block_recent_faq_count'); variable_del('faq_block_random_faq_count'); - // Custom breadcrumbs control + // Custom breadcrumbs control. variable_del('faq_custom_breadcrumbs'); // Deprecated. variable_del('faq_more_link'); - // Remove content type and the fields created + // Remove content type and the fields created. $faq_type = 'faq'; $sql = 'SELECT nid FROM {node} n WHERE n.type = :type'; $result = db_query($sql, array(':type' => $faq_type)); @@ -162,7 +161,7 @@ function faq_uninstall() { node_type_delete($faq_type); field_purge_batch(500); - // Remove content type and the fields created + // Remove content type and the fields created. $faq_type = 'faq'; $sql = 'SELECT nid FROM {node} n WHERE n.type = :type'; $result = db_query($sql, array(':type' => $faq_type)); @@ -180,8 +179,6 @@ function faq_uninstall() { cache_clear_all('*', 'cache_filter', TRUE); cache_clear_all('*', 'cache_menu', TRUE); cache_clear_all('*', 'cache_page', TRUE); - - } /** @@ -272,7 +269,13 @@ function faq_update_2() { */ function faq_update_6003() { $ret = array(); - db_add_field('faq_questions', 'detailed_question', array('type' => 'text', 'size' => 'normal', 'not null' => TRUE)); + db_add_field('faq_questions', 'detailed_question', + array( + 'type' => 'text', + 'size' => 'normal', + 'not null' => TRUE, + ) + ); db_update('faq_questions') ->expression('detailed_question', 'question') @@ -285,7 +288,13 @@ function faq_update_6003() { * Make'detailed_question' column nullable. */ function faq_update_7000() { - db_change_field('faq_questions', 'detailed_question', 'detailed_question', array('type' => 'text', 'size' => 'normal', 'not null' => FALSE)); + db_change_field('faq_questions', 'detailed_question', 'detailed_question', + array( + 'type' => 'text', + 'size' => 'normal', + 'not null' => FALSE, + ) + ); return t('Detailed question field can now be null.'); } @@ -300,23 +309,24 @@ function faq_update_7001() { } /** - * Convert old-style detailed questions to new fields + * Convert old-style detailed questions to new fields. */ function faq_update_7002(&$sandbox) { + // Number of nodes to update each pass. + define('BATCH_SIZE_7002', '5'); - define('BATCH_SIZE_7002', '5'); // Number of nodes to update each pass - - if (!isset($sandbox['progress'])) { // Do this the first time + // Do this the first time. + if (!isset($sandbox['progress'])) { - // Initialize sandbox structure for multi-pass update + // Initialize sandbox structure for multi-pass update. $sandbox['progress'] = 0; $sandbox['current_idx'] = 0; - // Get faq nodes + // Get faq nodes and run the query as user 1. $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'faq') - ->addMetaData('account', user_load(1)); // Run the query as user 1. + ->addMetaData('account', user_load(1)); $result = $query->execute(); if (isset($result['node'])) { @@ -328,35 +338,35 @@ function faq_update_7002(&$sandbox) { $sandbox['max'] = 0; } - //_faq_delete_custom_fields(); // Remove existing field to make sure the conversion does not fail - _faq_add_custom_fields(); // Add the detailed question field + // Add the detailed question field. + _faq_add_custom_fields(); - // Adjust the weight of the field so that it is above the answer (body) + // Adjust the weight of the field so that it is above the answer (body). _faq_shift_fields_down(); - } $count = 0; - // Convert old-style detailed questions to new full field + // Convert old-style detailed questions to new full field. while (($nid = $sandbox['faq_items_nids'][$sandbox['current_idx']]) && $count < BATCH_SIZE_7002) { - // Load the full node to be updated + // Load the full node to be updated. $node = node_load($nid); - // Load the detailed question - $dq = $node->detailed_question; // from old field - if ($dq == '') { // If this field is empty - $select = db_select('faq_questions', 'f'); // Fetch from database + // Load the detailed question. + $dq = $node->detailed_question; + if ($dq == '') { + $select = db_select('faq_questions', 'f'); $dq = $select->condition('f.nid', $node->nid)->fields('f', array('detailed_question'))->execute()->fetchField(); } - // Get the default text filter format from DB as this might be integer if upgraded site or tekststring if new D7 site - $filter_format = reset(array_keys(filter_formats())); // Default filter format: Filtered HTML + // Get the default text filter format from DB as this might be integer if upgraded site or tekststring if new D7 site. + // Default filter format: Filtered HTML. + $filter_format = reset(array_keys(filter_formats())); // Get the language(s) from the body, making sure we have the same set for detailed question too. $langs = array_keys($node->body); - // Add proper taxonomy fields + // Add proper taxonomy fields. $txonselect = db_select('taxonomy_index', 't'); $taxres = $txonselect->fields('t', array('tid'))->condition('t.nid', $node->nid)->execute(); foreach ($taxres as $taxon) { @@ -364,41 +374,42 @@ function faq_update_7002(&$sandbox) { $vocab = taxonomy_vocabulary_load($term->vid); foreach ($langs as $language) { - // Find out if there is a field added with the vocabulary of this term + // Find out if there is a field added with the vocabulary of this term. if (isset($node->{$vocab->module . "_" . $vocab->machine_name})) { - $node->{$vocab->module . "_" . $vocab->machine_name}[$language][$term->tid] = (array)$term; + $node->{$vocab->module . "_" . $vocab->machine_name}[$language][$term->tid] = (array) $term; } } } - // Add detailed question field for all languages + // Add detailed question field for all languages. foreach ($langs as $language) { $node->field_detailed_question[$language][0]['value'] = $dq; - $node->field_detailed_question[$language][0]['format'] = $filter_format; // Filtered HTML + $node->field_detailed_question[$language][0]['format'] = $filter_format; $node->field_detailed_question[$language][0]['safe_value'] = check_markup($dq, $filter_format, $language); } -// drupal_set_message(t("Converted @nid:@title with
@voc: @tax", array('@nid' => $nid, '@title' => $node->title, '@voc' => $voc, '@tax' => implode(',',$tax)))); - - // Save resulting node + // Save resulting node. node_save($node); - $count++; // Should not be more than BATCH_SIZE_7002 - $sandbox['progress']++; // Progress counter - $sandbox['current_idx']++; // Node array index pointer - + // Should not be more than BATCH_SIZE_7002. + $count++; + // Progress counter. + $sandbox['progress']++; + // Node array index pointer. + $sandbox['current_idx']++; } $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); - return t('Custom field added, @count questions converted into fields.', array('@count' => $sandbox['max']+1)); + return t('Custom field added, @count questions converted into fields.', array('@count' => $sandbox['max'] + 1)); } -//============================================================== -// Local functions declarations -// Code examples modified from http://www.sitepoint.com/creating-a-new-drupal-node-type/ -// and http://www.thecarneyeffect.co.uk/creating-custom-content-type-adding-fields-programmatically-drupal-7 - +/** + * Code examples modified. + * + * @see http://www.sitepoint.com/creating-a-new-drupal-node-type/ + * @see http://www.thecarneyeffect.co.uk/creating-custom-content-type-adding-fields-programmatically-drupal-7 + */ function _faq_add_custom_fields() { foreach (_faq_installed_fields() as $field) { field_create_field($field); @@ -411,7 +422,7 @@ function _faq_add_custom_fields() { } /** - * Return the detailed question field definition + * Return the detailed question field definition. */ function _faq_installed_fields() { $t = get_t(); @@ -484,15 +495,16 @@ function _faq_installed_fields() { } /** - * Returns the detailed question field instance + * Returns the detailed question field instance. */ function _faq_installed_instances() { $t = get_t(); + // Position in the question and answer page. Body (Answer) is 0 and Question (Title) is -4. return array( 'detailed_question' => array( 'label' => 'Detailed question', 'widget' => array( - 'weight' => '-3', // Position in the question and answer page. Body (Answer) is 0 and Question (Title) is -4. + 'weight' => '-3', 'type' => 'text_textarea', 'module' => 'text', 'active' => 1, @@ -527,11 +539,12 @@ function _faq_installed_instances() { 'entity_type' => 'node', 'bundle' => 'page', 'deleted' => '0', - ), - ); + ), + ); } + /** - * Cleanup custom fields on uninstall + * Cleanup custom fields on uninstall. */ function _faq_delete_custom_fields() { foreach (array_keys(_faq_installed_fields()) as $field) { @@ -543,18 +556,20 @@ function _faq_delete_custom_fields() { } } +/** + * Shift fields down. + */ function _faq_shift_fields_down() { - - // Adjust the weight of the field so that it is above the answer (body) + // Adjust the weight of the field so that it is above the answer (body). $instance = field_read_instance('node', 'field_detailed_question', 'faq'); - // Get all bundle instances + // Get all bundle instances. $instances = field_info_instances('node', 'faq'); $body_widget_weight = $instances['body']['widget']['weight']; $body_default_weight = $instances['body']['display']['default']['weight']; $body_teaser_weight = $instances['body']['display']['teaser']['weight']; - // move all of them one down so that + // Move all of them one down so that. foreach ($instances as $field => $settings) { if ($settings['widget']['weight'] >= $body_widget_weight) { $settings['widget']['weight']++; @@ -569,12 +584,10 @@ function _faq_shift_fields_down() { } field_update_instance($settings); - } $instance['widget']['weight'] = $body_widget_weight; $instance['display']['default']['weight'] = $body_default_weight; $instance['display']['teaser']['weight'] = $body_teaser_weight; field_update_instance($instance); - } From 5bd01dbf9c99c4e3c6bbc2c7fc6630c75bf7e34d Mon Sep 17 00:00:00 2001 From: Alexander Schedrov Date: Sat, 25 Oct 2014 12:54:11 +0300 Subject: [PATCH 11/17] Fixed codesniffer notices in includes folder. --- .../faq/includes/faq-category-hide-answer.tpl.php | 3 +++ .../faq/includes/faq-category-new-page.tpl.php | 3 +++ .../includes/faq-category-questions-inline.tpl.php | 4 +++- .../faq-category-questions-top-answers.tpl.php | 11 ++++++----- .../includes/faq-category-questions-top.tpl.php | 15 +++++++------- .../custom/faq/includes/faq-hide-answer.tpl.php | 2 +- .../custom/faq/includes/faq-new-page.tpl.php | 3 +-- .../faq/includes/faq-questions-inline.tpl.php | 1 - .../custom/faq/includes/faq-questions-top.tpl.php | 4 ++-- .../custom/faq/includes/faq.hide_answer.inc | 5 ++--- .../modules/custom/faq/includes/faq.new_page.inc | 15 +++++++++----- .../custom/faq/includes/faq.questions_inline.inc | 6 ++---- .../custom/faq/includes/faq.questions_top.inc | 23 +++++++++++++++------- 13 files changed, 57 insertions(+), 38 deletions(-) diff --git a/includes/faq-category-hide-answer.tpl.php b/includes/faq-category-hide-answer.tpl.php index 04183f7..4111815 100644 --- a/includes/faq-category-hide-answer.tpl.php +++ b/includes/faq-category-hide-answer.tpl.php @@ -50,12 +50,15 @@ * The sub-categories faqs, recursively themed (by this template). */ +// @todo should be moved to better place. +// @codingStandardsIgnoreStart if ($category_depth > 0) { $hdr = 'h4'; } else { $hdr = 'h3'; } +// @codingStandardsIgnoreEnd ?>
- diff --git a/includes/faq-category-questions-top.tpl.php b/includes/faq-category-questions-top.tpl.php index 67ae312..67be2ab 100644 --- a/includes/faq-category-questions-top.tpl.php +++ b/includes/faq-category-questions-top.tpl.php @@ -60,13 +60,15 @@ * The sub-categories faqs, recursively themed (by this template). */ +// @todo should be moved to better place. +// @codingStandardsIgnoreStart if ($category_depth > 0) { $hdr = 'h4'; } else { $hdr = 'h3'; } - +// @codingStandardsIgnoreEnd ?>
@@ -115,14 +117,14 @@
- + $subcat_html): ?>
- +
< class="faq-ul-questions-top"> @@ -149,14 +151,14 @@
- +
$node): ?> -
+
@@ -185,5 +187,4 @@
- diff --git a/includes/faq-hide-answer.tpl.php b/includes/faq-hide-answer.tpl.php index e01a1b0..d442e8b 100644 --- a/includes/faq-hide-answer.tpl.php +++ b/includes/faq-hide-answer.tpl.php @@ -21,7 +21,7 @@ ?>
- +
diff --git a/includes/faq-new-page.tpl.php b/includes/faq-new-page.tpl.php index be08d16..f4b451e 100644 --- a/includes/faq-new-page.tpl.php +++ b/includes/faq-new-page.tpl.php @@ -16,5 +16,4 @@ * Pre-formatted list. */ ?> - diff --git a/includes/faq-questions-inline.tpl.php b/includes/faq-questions-inline.tpl.php index 45c1473..eb027f3 100644 --- a/includes/faq-questions-inline.tpl.php +++ b/includes/faq-questions-inline.tpl.php @@ -26,7 +26,6 @@
-
diff --git a/includes/faq-questions-top.tpl.php b/includes/faq-questions-top.tpl.php index 0f4f5c6..b7c74da 100644 --- a/includes/faq-questions-top.tpl.php +++ b/includes/faq-questions-top.tpl.php @@ -35,7 +35,7 @@
- +
@@ -54,7 +54,7 @@
- + $items, 'title' => NULL, 'type' => $list_style, 'attributes' => array("class" => "faq-question-listing"))); + $variables['list'] = theme('item_list', + array( + 'items' => $items, + 'title' => NULL, + 'type' => $list_style, + 'attributes' => array("class" => "faq-question-listing"), + ) + ); } /** * Create categorized FAQ page if set to show answer in a new page. * - * @param &$variables + * @param array &$variables * Array reference of arguments given to the theme() function. */ - function template_preprocess_faq_category_new_page(&$variables) { $data = $variables['data']; $category_display = $variables['category_display']; @@ -132,4 +138,3 @@ function template_preprocess_faq_category_new_page(&$variables) { $variables['question_list_style'] = variable_get('faq_question_listing', 'ul'); $variables['question_count'] = $count; } - diff --git a/includes/faq.questions_inline.inc b/includes/faq.questions_inline.inc index ea327dd..36c3f14 100644 --- a/includes/faq.questions_inline.inc +++ b/includes/faq.questions_inline.inc @@ -8,7 +8,7 @@ /** * Create the FAQ page if set to show the questions inline. * - * @param &$variables + * @param array &$variables * Array reference of arguments given to the theme() function. */ function template_preprocess_faq_questions_inline(&$variables) { @@ -46,7 +46,7 @@ function template_preprocess_faq_questions_inline(&$variables) { /** * Create categorized FAQ page if set to show/hide the questions inline. * - * @param &$variables + * @param array &$variables * Array reference of arguments given to the theme() function. */ function template_preprocess_faq_category_questions_inline(&$variables) { @@ -87,7 +87,6 @@ function template_preprocess_faq_category_questions_inline(&$variables) { $show_term_page_children = TRUE; } - // Configure "back to top" link. $back_to_top = faq_init_back_to_top($this_page); @@ -166,4 +165,3 @@ function template_preprocess_faq_category_questions_inline(&$variables) { $variables['nodes'] = $nodes; $variables['question_count'] = $count; } - diff --git a/includes/faq.questions_top.inc b/includes/faq.questions_top.inc index 784482b..232a5d2 100644 --- a/includes/faq.questions_top.inc +++ b/includes/faq.questions_top.inc @@ -8,9 +8,10 @@ /** * Create the structure of the page, when the questions are to be shown on top. * - * @param &$variables + * @param array &$variables * Array reference of arguments given to the theme() function. - * @return + * + * @return array * A variable holding the HTML formatted page. */ function template_preprocess_faq_questions_top(&$variables) { @@ -51,13 +52,22 @@ function template_preprocess_faq_questions_top(&$variables) { $variables['use_teaser'] = $teaser; $variables['questions'] = $questions; $variables['answers'] = $answers; - $variables['questions_list'] = theme('item_list', array('items' => $questions, 'title' => NULL, 'type' => $list_style, 'attributes' => array("class" => "faq-ul-questions-top"))); + $variables['questions_list'] = theme('item_list', + array( + 'items' => $questions, + 'title' => NULL, + 'type' => $list_style, + 'attributes' => array( + "class" => "faq-ul-questions-top", + ), + ) + ); } /** * Create categorized questions for FAQ page if set to show questions on top. * - * @param &$variables + * @param array &$variables * Array reference of arguments given to the theme() function. */ function template_preprocess_faq_category_questions_top(&$variables) { @@ -76,7 +86,7 @@ function template_preprocess_faq_category_questions_top(&$variables) { $show_term_page_children = variable_get('faq_show_term_page_children', FALSE); $group_questions_top = variable_get('faq_group_questions_top', FALSE); $default_sorting = variable_get('faq_default_sorting', 'DESC'); - + // Configure labels. $variables['question_label'] = ''; $variables['answer_label'] = ''; @@ -199,7 +209,7 @@ function template_preprocess_faq_category_questions_top(&$variables) { /** * Create categorized answers for FAQ page if set to show the questions on top. * - * @param &$variables + * @param array &$variables * Array reference of arguments given to the theme() function. */ function template_preprocess_faq_category_questions_top_answers(&$variables) { @@ -290,4 +300,3 @@ function template_preprocess_faq_category_questions_top_answers(&$variables) { $variables['display_header'] = TRUE; } } - From 53f4beacebe7c159e237d65ce49cb2d0dc9f093e Mon Sep 17 00:00:00 2001 From: Alexander Schedrov Date: Sat, 25 Oct 2014 12:54:29 +0300 Subject: [PATCH 12/17] Fixed codesniffer notices in faq.variable.inc. --- faq.variable.inc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/faq.variable.inc b/faq.variable.inc index 4d48d7c..357b2e8 100644 --- a/faq.variable.inc +++ b/faq.variable.inc @@ -1,6 +1,11 @@ Date: Sat, 25 Oct 2014 12:58:21 +0300 Subject: [PATCH 13/17] Fixed additional notices in includes folder. --- .../all/modules/custom/faq/includes/faq-category-hide-answer.tpl.php | 2 -- .../all/modules/custom/faq/includes/faq-category-new-page.tpl.php | 3 --- .../modules/custom/faq/includes/faq-category-questions-inline.tpl.php | 2 -- includes/faq-questions-top.tpl.php | 3 +-- includes/faq.hide_answer.inc | 1 - includes/faq.questions_top.inc | 1 - 6 files changed, 1 insertion(+), 11 deletions(-) diff --git a/includes/faq-category-hide-answer.tpl.php b/includes/faq-category-hide-answer.tpl.php index 4111815..4c210fa 100644 --- a/includes/faq-category-hide-answer.tpl.php +++ b/includes/faq-category-hide-answer.tpl.php @@ -133,7 +133,5 @@
-
-
diff --git a/includes/faq-category-new-page.tpl.php b/includes/faq-category-new-page.tpl.php index fe1854f..bec7275 100644 --- a/includes/faq-category-new-page.tpl.php +++ b/includes/faq-category-new-page.tpl.php @@ -122,8 +122,5 @@ >
- -
-
diff --git a/includes/faq-category-questions-inline.tpl.php b/includes/faq-category-questions-inline.tpl.php index 0c6533e..926ffd8 100644 --- a/includes/faq-category-questions-inline.tpl.php +++ b/includes/faq-category-questions-inline.tpl.php @@ -145,7 +145,5 @@
-
-
diff --git a/includes/faq-questions-top.tpl.php b/includes/faq-questions-top.tpl.php index b7c74da..6a85d44 100644 --- a/includes/faq-questions-top.tpl.php +++ b/includes/faq-questions-top.tpl.php @@ -56,5 +56,4 @@
- diff --git a/includes/faq.hide_answer.inc b/includes/faq.hide_answer.inc index 120eb18..d595723 100644 --- a/includes/faq.hide_answer.inc +++ b/includes/faq.hide_answer.inc @@ -76,7 +76,6 @@ function template_preprocess_faq_category_hide_answer(&$variables) { $show_term_page_children = TRUE; } - // Get number of questions, and account for hidden sub-categories. $count = 0; if ($display_faq_count && $hide_child_terms) { diff --git a/includes/faq.questions_top.inc b/includes/faq.questions_top.inc index 232a5d2..e9b7abc 100644 --- a/includes/faq.questions_top.inc +++ b/includes/faq.questions_top.inc @@ -281,7 +281,6 @@ function template_preprocess_faq_category_questions_top_answers(&$variables) { $variables['subcat_body_list'] = faq_get_child_categories_faqs($term, 'faq_category_questions_top_answers', $default_weight, $default_sorting, $category_display, $variables['class'], $parent_term); } - $nodes = array(); foreach ($data as $node) { $node_var = array(); From d22f66f0408e4136a95407cb1c65a25bcd04e94f Mon Sep 17 00:00:00 2001 From: Alexander Schedrov Date: Sat, 25 Oct 2014 13:22:00 +0300 Subject: [PATCH 14/17] Fixed codesniffer notices in faq.module. --- faq.module | 378 +++++++++++++++++-------- 1 file changed, 260 insertions(+), 118 deletions(-) diff --git a/faq.module b/faq.module index 0dd6a29..317c04a 100644 --- a/faq.module +++ b/faq.module @@ -18,6 +18,7 @@ function faq_help($path, $arg) { '

' . t("The 'Frequently Asked Questions' settings configuration screen will allow users with 'administer faq' permissions to specify different layouts of the questions and answers.") . '

' . '

' . t("All users with 'view faq page' permissions will be able to view the generated FAQ page.") . '

'; return $output; + case 'admin/modules#description': return t('Allows the user to configure the layout of questions and answers on a FAQ page.'); } @@ -192,7 +193,7 @@ function faq_node_info() { 'name' => t('FAQ'), 'base' => 'faq', 'description' => t('A frequently asked question and its answer.'), - 'has_title' => true, + 'has_title' => TRUE, 'title_label' => t('Question'), ), ); @@ -201,9 +202,9 @@ function faq_node_info() { /** * Implements hook_form(). * - * @param &$node object + * @param object &$node * The node being added or edited. - * @param &$form_state array + * @param array &$form_state * The hook can set this variable to an associative array of attributes to add * to the enclosing
tag. * @return array @@ -227,7 +228,7 @@ function faq_form($node, $form_state) { * * Inserts the faq node question text into the 'faq_questions' table. * - * @param $node + * @param object $node * The node object. */ function faq_insert($node) { @@ -237,7 +238,7 @@ function faq_insert($node) { 'nid' => $node->nid, 'vid' => $node->vid, 'question' => $node->title, - 'detailed_question' => $detailed_question['value'], //$node->field_detailed_question[$node->language][0]['value'], + 'detailed_question' => $detailed_question['value'], )) ->execute(); } @@ -247,7 +248,7 @@ function faq_insert($node) { * * Updates the faq node question text in the 'faq_questions' table. * - * @param $node + * @param object $node * The node object. */ function faq_update($node) { @@ -255,7 +256,8 @@ function faq_update($node) { faq_insert($node); } else { - $detailed_question = array('value' => ''); // Empty detailed question as default + // Empty detailed question as default. + $detailed_question = array('value' => ''); if ($items = field_get_items('node', $node, 'field_detailed_question')) { $detailed_question = reset($items); } @@ -278,7 +280,7 @@ function faq_update($node) { * * Deletes an FAQ node from the database. * - * @param &$node + * @param object &$node * Which node to delete. */ function faq_delete($node) { @@ -295,15 +297,16 @@ function faq_delete($node) { * * Initialises $node->question using the value in the 'faq_questions' table. * - * @param Array $nodes + * @param array $nodes * The node objects array. */ function faq_load($nodes) { return; + // @codingStandardsIgnoreStart /* foreach ($nodes as $nid => &$node) { - // TODO: change logic to load faq nodes - do not rely on specific faq table + // @todo: change logic to load faq nodes - do not rely on specific faq table $result = db_query('SELECT question, detailed_question FROM {faq_questions} WHERE nid = :nid AND vid = :vid', array( ':nid' => $node->nid, ':vid' => $node->vid, @@ -322,6 +325,7 @@ function faq_load($nodes) { } } */ + // @codingStandardsIgnoreEnd } /** @@ -338,42 +342,37 @@ function faq_node_revision_delete($node) { * Implements hook_view(). */ function faq_view($node, $view_mode) { - drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css'); $detailed_question = FALSE; - // Get the detailed question + // Get the detailed question. if ($field_items = field_get_items('node', $node, 'field_detailed_question')) { $detailed_question = reset($field_items); } // Only show the detailed question if there is something to show. if ($detailed_question && !empty($detailed_question['value'])) { - $show_question = FALSE; - - if ($view_mode == 'full') { - // The detailed question is always shown on the full node. - $show_question = TRUE; - } - else { - // On other pages, consider the admin settings. - if (variable_get('faq_question_length', 'short') == 'both' && variable_get('faq_display', 'questions_top') == 'hide_answer') { - $show_question = TRUE; - } + $show_question = FALSE; + if ($view_mode == 'full') { + // The detailed question is always shown on the full node. + $show_question = TRUE; + } + else { + // On other pages, consider the admin settings. + if (variable_get('faq_question_length', 'short') == 'both' && variable_get('faq_display', 'questions_top') == 'hide_answer') { + $show_question = TRUE; } + } - // Should be handled by themeing - create field--field_detailed_question.tpl.php + // Should be handled by theming - create field--field_detailed_question.tpl.php. if ($show_question) { - // We're here if we are showing the question + // We're here if we are showing the question. $node->content['field_detailed_question'] = array( '#markup' => theme('field_detailed_question', $detailed_question), - // '#markup' => '
' . $node->field_detailed_question[$node->language][0]['value'] . '
', - // '#weight' => '-1', ); - } else { - // We switch off the visibility of the detailed question + // We switch off the visibility of the detailed question. hide($node->content['field_detailed_question']); } } @@ -394,13 +393,16 @@ function faq_views_api() { /** * Function to display the faq page. * - * @param $tid int + * @param int $tid * Default is 0, determines if the questions and answers on the page * will be shown according to a category or non-categorized. - * @param $faq_display string + * + * @param string $faq_display * Optional parameter to override default question layout setting. - * @param $category_display string + * + * @param string $category_display * Optional parameter to override default category layout setting. + * * @return string|NULL * The output variable which contains an HTML formatted page with FAQ * questions and answers. @@ -411,7 +413,12 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') { } // Things to provide translations for. - $default_values = array(t('Frequently Asked Questions'), t('Back to Top'), t('Q:'), t('A:')); + $default_values = array( + t('Frequently Asked Questions'), + t('Back to Top'), + t('Q:'), + t('A:'), + ); $output = $output_answers = ''; drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css'); @@ -435,7 +442,6 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') { } } - if (empty($faq_display)) { $faq_display = variable_get('faq_display', 'questions_top'); } @@ -479,11 +485,16 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') { if ($default_sorting == 'ASC') { $default_weight = 1000000; } + // Works, but involves variable concatenation - safe though, since // $default_weight is an integer. $query->addExpression("COALESCE(w.weight, $default_weight)", 'effective_weight'); - // Doesn't work in Postgres. + + // @codingStandardsIgnoreStart + // @todo Doesn't work in Postgres. //$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight)); + // @codingStandardsIgnoreEnd + $query->orderBy('effective_weight', 'ASC') ->orderBy('n.sticky', 'DESC'); if ($default_sorting == 'ASC') { @@ -496,10 +507,8 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') { $query->condition('n.language', i18n_select_langcodes()); } - // Only need the nid column. $nids = $query->execute()->fetchCol(); - //dpm($nids); $data = node_load_multiple($nids); switch ($faq_display) { @@ -522,11 +531,9 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') { include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.new_page.inc'; $output = theme('faq_new_page', array('data' => $data)); break; - - } // End of switch. + } } - // Categorize questions. else { $hide_child_terms = variable_get('faq_hide_child_terms', FALSE); @@ -547,7 +554,6 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') { } } - $list_style = variable_get('faq_category_listing', 'ul'); $vocabularies = taxonomy_get_vocabularies('faq'); $vocab_omit = variable_get('faq_omit_vocabulary', array()); @@ -555,7 +561,6 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') { $vocab_items = array(); $valid_vocab = FALSE; - foreach ($vocabularies as $vid => $vobj) { if (isset($vocab_omit[$vid]) && $vocab_omit[$vid] != 0) { continue; @@ -584,15 +589,19 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') { _display_faq_by_category($faq_display, $category_display, $term, 1, $output, $output_answers); } break; - - - } // End of switch (category_display). - } // End of foreach term. - } // End of if $category_display != new_page. - } // End of foreach vocab. + } + } + } + } if ($category_display == "new_page") { - $output = theme('item_list', array('items' => $items, 'title' => NULL, 'type' => $list_style)); + $output = theme('item_list', + array( + 'items' => $items, + 'title' => NULL, + 'type' => $list_style, + ) + ); } if (!$valid_vocab) { drupal_set_message(t('Categories are enabled but no vocabulary is associated with the FAQ content type. Either create a vocabulary or disable categorization in order for questions to appear.'), 'error'); @@ -610,18 +619,23 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') { /** * Display FAQ questions and answers filtered by category. * - * @param $faq_display string + * @param string $faq_display * Define the way the FAQ is being shown; can have the values: * 'questions top',hide answers','questions inline','new page'. - * @param $category_display string + * + * @param string $category_display * The layout of categories which should be used. - * @param $term object + * + * @param object $term * The category / term to display FAQs for. - * @param $display_header int + * + * @param int $display_header * Set if the header will be shown or not. - * @param &$output string + * + * @param string &$output * Reference which holds the content of the page, HTML formatted. - * @param &$output_answers string + * + * @param string &$output_answers * Reference which holds the answers from the FAQ, when showing questions * on top. */ @@ -647,8 +661,12 @@ function _display_faq_by_category($faq_display, $category_display, $term, $displ // Works, but involves variable concatenation - safe though, since // $default_weight is an integer. $query->addExpression("COALESCE(w.weight, $default_weight)", 'effective_weight'); - // Doesn't work in Postgres. + + // @codingStandardsIgnoreStart + // @todo Doesn't work in Postgres. //$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight)); + // @codingStandardsIgnoreEnd + $query->orderBy('effective_weight', 'ASC') ->orderBy('n.sticky', 'DESC'); if ($default_sorting == 'ASC') { @@ -662,11 +680,9 @@ function _display_faq_by_category($faq_display, $category_display, $term, $displ $query->condition("{$td_alias}.language", i18n_select_langcodes()); } - // We only want the first column, which is nid, so that we can load all // related nodes. $nids = $query->execute()->fetchCol(); - $data = node_load_multiple($nids); // Handle indenting of categories. @@ -690,41 +706,81 @@ function _display_faq_by_category($faq_display, $category_display, $term, $displ $faq_path = drupal_get_path('module', 'faq') . '/includes'; switch ($faq_display) { - case 'questions_top': include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.questions_top.inc'; // @todo fix workaround: have to share result. - $output .= theme('faq_category_questions_top', array('data' => $data, 'display_header' => $display_header, 'category_display' => $category_display, 'term' => $term, 'class' => $faq_class, 'parent_term' => $term)); - $output_answers .= theme('faq_category_questions_top_answers', array('data' => $data, 'display_header' => $display_header, 'category_display' => $category_display, 'term' => $term, 'class' => $faq_class, 'parent_term' => $term)); + $output .= theme('faq_category_questions_top', + array( + 'data' => $data, + 'display_header' => $display_header, + 'category_display' => $category_display, + 'term' => $term, + 'class' => $faq_class, + 'parent_term' => $term, + ) + ); + $output_answers .= theme('faq_category_questions_top_answers', + array( + 'data' => $data, + 'display_header' => $display_header, + 'category_display' => $category_display, + 'term' => $term, + 'class' => $faq_class, + 'parent_term' => $term, + ) + ); break; - case 'hide_answer': include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.hide_answer.inc'; - $output .= theme('faq_category_hide_answer', array('data' => $data, 'display_header' => $display_header, 'category_display' => $category_display, 'term' => $term, 'class' => $faq_class, 'parent_term' => $term)); + $output .= theme('faq_category_hide_answer', + array( + 'data' => $data, + 'display_header' => $display_header, + 'category_display' => $category_display, + 'term' => $term, + 'class' => $faq_class, + 'parent_term' => $term, + ) + ); break; - case 'questions_inline': include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.questions_inline.inc'; - $output .= theme('faq_category_questions_inline', array('data' => $data, 'display_header' => $display_header, 'category_display' => $category_display, 'term' => $term, 'class' => $faq_class, 'parent_term' => $term)); + $output .= theme('faq_category_questions_inline', + array( + 'data' => $data, + 'display_header' => $display_header, + 'category_display' => $category_display, + 'term' => $term, + 'class' => $faq_class, + 'parent_term' => $term, + ) + ); break; case 'new_page': include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.new_page.inc'; - $output .= theme('faq_category_new_page', array('data' => $data, 'display_header' => $display_header, 'category_display' => $category_display, 'term' => $term, 'class' => $faq_class, 'parent_term' => $term)); + $output .= theme('faq_category_new_page', + array( + 'data' => $data, + 'display_header' => $display_header, + 'category_display' => $category_display, + 'term' => $term, + 'class' => $faq_class, + 'parent_term' => $term, + ) + ); break; - } // End of switch (faq_display). - + } // Handle indenting of categories. while ($depth > 0) { $output .= '
'; $depth--; } - } /** @@ -749,13 +805,27 @@ function faq_theme() { 'path' => $path, 'file' => 'faq.questions_top.inc', 'template' => 'faq-category-questions-top', - 'variables' => array('data' => NULL, 'display_header' => 0, 'category_display' => NULL, 'term' => NULL, 'class' => NULL, 'parent_term' => NULL), + 'variables' => array( + 'data' => NULL, + 'display_header' => 0, + 'category_display' => NULL, + 'term' => NULL, + 'class' => NULL, + 'parent_term' => NULL, + ), ), 'faq_category_questions_top_answers' => array( 'path' => $path, 'file' => 'faq.questions_top.inc', 'template' => 'faq-category-questions-top-answers', - 'variables' => array('data' => NULL, 'display_header' => 0, 'category_display' => NULL, 'term' => NULL, 'class' => NULL, 'parent_term' => NULL), + 'variables' => array( + 'data' => NULL, + 'display_header' => 0, + 'category_display' => NULL, + 'term' => NULL, + 'class' => NULL, + 'parent_term' => NULL, + ), ), 'faq_hide_answer' => array( 'path' => $path, @@ -767,7 +837,14 @@ function faq_theme() { 'path' => $path, 'file' => 'faq.hide_answer.inc', 'template' => 'faq-category-hide-answer', - 'variables' => array('data' => NULL, 'display_header' => 0, 'category_display' => NULL, 'term' => NULL, 'class' => NULL, 'parent_term' => NULL), + 'variables' => array( + 'data' => NULL, + 'display_header' => 0, + 'category_display' => NULL, + 'term' => NULL, + 'class' => NULL, + 'parent_term' => NULL, + ), ), 'faq_questions_inline' => array( 'path' => $path, @@ -779,7 +856,14 @@ function faq_theme() { 'path' => $path, 'file' => 'faq.questions_inline.inc', 'template' => 'faq-category-questions-inline', - 'variables' => array('data' => NULL, 'display_header' => 0, 'category_display' => NULL, 'term' => NULL, 'class' => NULL, 'parent_term' => NULL), + 'variables' => array( + 'data' => NULL, + 'display_header' => 0, + 'category_display' => NULL, + 'term' => NULL, + 'class' => NULL, + 'parent_term' => NULL, + ), ), 'faq_new_page' => array( 'path' => $path, @@ -791,10 +875,21 @@ function faq_theme() { 'path' => $path, 'file' => 'faq.new_page.inc', 'template' => 'faq-category-new-page', - 'variables' => array('data' => NULL, 'display_header' => 0, 'category_display' => NULL, 'term' => NULL, 'class' => NULL, 'parent_term' => NULL), + 'variables' => array( + 'data' => NULL, + 'display_header' => 0, + 'category_display' => NULL, + 'term' => NULL, + 'class' => NULL, + 'parent_term' => NULL, + ), ), 'faq_page' => array( - 'variables' => array('content' => '', 'answers' => '', 'description' => NULL), + 'variables' => array( + 'content' => '', + 'answers' => '', + 'description' => NULL, + ), ), ); } @@ -837,11 +932,17 @@ function faq_block_view($delta) { $items[] = l(faq_tt("taxonomy:term:$tid:name", $name), 'faq-page/' . $tid); } $list_style = variable_get('faq_category_listing', 'ul'); - $block['content'] = theme('item_list', array('items' => $items, 'title' => NULL, 'type' => $list_style)); + $block['content'] = theme('item_list', + array( + 'items' => $items, + 'title' => NULL, + 'type' => $list_style, + ) + ); } } break; - } // End switch($delta). + } return $block; } @@ -849,10 +950,12 @@ function faq_block_view($delta) { /** * Return a HTML formatted list of terms indented according to the term depth. * - * @param $vid int + * @param int $vid * Vocabulary id. - * @param $tid int + * + * @param int $tid * Term id. + * * @return string * Return a HTML formatted list of terms indented according to the term depth. */ @@ -954,6 +1057,7 @@ function faq_get_terms() { $vocab_items = _get_indented_faq_terms($vid, 0); $items = array_merge($items, $vocab_items); } + return theme('item_list', array('items' => $items)); } @@ -991,8 +1095,12 @@ function faq_get_faq_list() { // Works, but involves variable concatenation - safe though, since // $default_weight is an integer. $query->addExpression("COALESCE(w.weight, $default_weight)", 'effective_weight'); - // Doesn't work in Postgres. + + // @codingStandardsIgnoreStart + // @todo Doesn't work in Postgres. //$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight)); + // @codingStandardsIgnoreEnd + $query->orderBy('effective_weight', 'ASC') ->orderBy('n.sticky', 'DESC'); if ($default_sorting == 'ASC') { @@ -1020,6 +1128,9 @@ function faq_get_faq_list() { } if (!function_exists('array_diff_key')) { + /** + * Override array_diff_key function. + */ function array_diff_key() { $arrs = func_get_args(); $result = array_shift($arrs); @@ -1037,13 +1148,16 @@ if (!function_exists('array_diff_key')) { /** * Helper function to setup the faq question. * - * @param &$data + * @param array &$data * Array reference to store display data in. - * @param $node + * + * @param object $node * The node object. - * @param $path + * + * @param string $path * The path/url which the question should link to if links are disabled. - * @param $anchor + * + * @param string $anchor * Link anchor to use in question links. */ function faq_view_question(&$data, $node, $path = NULL, $anchor = NULL) { @@ -1080,7 +1194,7 @@ function faq_view_question(&$data, $node, $path = NULL, $anchor = NULL) { } $question = '' . $question . ''; - // Get the language of the body field + // Get the language of the body field. $language = 'und'; foreach ($node->body as $lang => $values) { if ($values[0]['value']) { @@ -1088,13 +1202,13 @@ function faq_view_question(&$data, $node, $path = NULL, $anchor = NULL) { } } - // Get the detailed question + // Get the detailed question. $detailed_question = ''; if ($dq = field_get_items('node', $node, 'field_detailed_question')) { $detailed_question = reset($dq); } - if ( variable_get('faq_display', 'questions_top') != 'hide_answer' + if (variable_get('faq_display', 'questions_top') != 'hide_answer' && !empty($detailed_question['value']) && variable_get('faq_question_length', 'short') == 'both') { $question .= '
' . $detailed_question['safe_value'] . '
'; @@ -1105,19 +1219,22 @@ function faq_view_question(&$data, $node, $path = NULL, $anchor = NULL) { /** * Helper function to setup the faq answer. * - * @param &$data + * @param array &$data * Array reference to store display data in. - * @param $node + * + * @param object $node * The node object. - * @param $back_to_top + * + * @param array $back_to_top * An array containing the "back to top" link. - * @param $teaser + * + * @param bool $teaser * Whether or not to use teasers. - * @param $links + * + * @param array $links * Whether or not to show node links. */ function faq_view_answer(&$data, $node, $back_to_top, $teaser, $links) { - $view_mode = $teaser ? 'teaser' : 'full'; $langcode = $GLOBALS['language_content']->language; @@ -1161,13 +1278,11 @@ function faq_view_answer(&$data, $node, $back_to_top, $teaser, $links) { $node_links = ($links ? $build['links']['node']['#links'] : (!empty($back_to_top) ? array($build['links']['node']['#links']['faq_back_to_top']) : NULL)); unset($build['links']); - unset($build['#theme']); // We don't want node title displayed. - $content = drupal_render($build); + // We don't want node title displayed. + unset($build['#theme']); - // Unset unused $node text so that a bad theme can not open a security hole. - // $node->body = NULL; - // $node->teaser = NULL; + $content = drupal_render($build); $data['body'] = $content; $data['links'] = !empty($node_links) ? theme('links', array('links' => $node_links, 'attributes' => array('class' => 'links inline'))) : ''; @@ -1176,10 +1291,11 @@ function faq_view_answer(&$data, $node, $back_to_top, $teaser, $links) { /** * Helper function to setup the "back to top" link. * - * @param $path string + * @param string $path * The path/url where the "back to top" link should bring the user too. This * could be the 'faq-page' page or one of the categorized faq pages, e.g 'faq-page/123' * where 123 is the tid. + * * @return array * An array containing the "back to top" link. */ @@ -1202,23 +1318,31 @@ function faq_init_back_to_top($path) { /** * Helper function for retrieving the sub-categories faqs. * - * @param $term object + * @param object $term * The category / term to display FAQs for. - * @param $theme_function string + * + * @param string $theme_function * Theme function to use to format the Q/A layout for sub-categories. - * @param $default_weight int + * + * @param int $default_weight * Is 0 for $default_sorting = DESC; is 1000000 for $default_sorting = ASC. - * @param $default_sorting string + * + * @param string $default_sorting * If 'DESC', nodes are sorted by creation date descending; if 'ASC', nodes * are sorted by creation date ascending. - * @param $category_display string + * + * @param string $category_display * The layout of categories which should be used. - * @param $class string + * + * @param string $class * CSS class which the HTML div will be using. A special class name is * required in order to hide and questions / answers. - * @param $parent_term string + * + * @param string $parent_term * The original, top-level, term we're displaying FAQs for. + * * @return string + * Returns markup. */ function faq_get_child_categories_faqs($term, $theme_function, $default_weight, $default_sorting, $category_display, $class, $parent_term = NULL) { $output = array(); @@ -1250,8 +1374,12 @@ function faq_get_child_categories_faqs($term, $theme_function, $default_weight, // Works, but involves variable concatenation - safe though, since // $default_weight is an integer. $query->addExpression("COALESCE(w.weight, $default_weight)", 'effective_weight'); - // Doesn't work in Postgres. + + // @codingStandardsIgnoreStart + // @todo Doesn't work in Postgres. //$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight)); + // @codingStandardsIgnoreEnd + $query->orderBy('effective_weight', 'ASC') ->orderBy('n.sticky', 'DESC'); if ($default_sorting == 'ASC') { @@ -1280,13 +1408,13 @@ function faq_get_child_categories_faqs($term, $theme_function, $default_weight, /** * Helper function to setup the list of sub-categories for the header. * - * @param $term object + * @param object $term * The term to setup the list of child terms for. + * * @return array * An array of sub-categories. */ function faq_view_child_category_headers($term) { - $child_categories = array(); $list = taxonomy_get_children($term->tid); @@ -1324,8 +1452,8 @@ function faq_pathauto($op) { $settings['patterndefault'] = t('faq-page/[term:tid]'); $settings['batch_update_callback'] = 'faq_pathauto_bulkupdate'; $settings['token_type'] = 'term'; - return (object) $settings; + default: break; } @@ -1448,8 +1576,9 @@ function faq_taxonomy_term_delete($term) { /** * Function to set up the FAQ breadcrumbs for a given taxonomy term. * - * @param $term object + * @param object $term * The taxonomy term object. + * * @return array|NULL */ function faq_set_breadcrumb($term = NULL) { @@ -1513,10 +1642,16 @@ function faq_filter_info() { return $filters; } +/** + * Filter settings. + */ function _faq_filter_settings($form, &$form_state, $filter, $format, $defaults, $filters) { return array(); } +/** + * Filter string. + */ function _faq_filter_process($text) { $text = preg_replace_callback('/\[faq:?([^\]]*)\]/', '_faq_faq_page_filter_replacer', $text); // Remove comments, as they're not supported by all input formats. @@ -1538,6 +1673,13 @@ function _faq_faq_page_filter_replacer($matches) { $tid = 0; $faq_display = ''; $category_display = ''; + $default_display = array( + 'questions_top', + 'hide_answer', + 'questions_inline', + 'new_page', + ); + $default_category_display = array('hide_qa', 'new_page', 'categories_inline'); if (drupal_strlen($matches[1])) { list($tid, $faq_display, $category_display) = explode(',', $matches[1] . ',,'); $tid = (int) trim($tid); @@ -1545,10 +1687,10 @@ function _faq_faq_page_filter_replacer($matches) { $category_display = trim($category_display); // These two checks ensure that a typo in the faq_display or // category_display string still results in the FAQ showing. - if ($faq_display && !in_array($faq_display, array('questions_top', 'hide_answer', 'questions_inline', 'new_page'))) { + if ($faq_display && !in_array($faq_display, $default_display)) { $faq_display = ''; } - if ($category_display && !in_array($category_display, array('hide_qa', 'new_page', 'categories_inline'))) { + if ($category_display && !in_array($category_display, $default_category_display)) { $category_display = ''; } } @@ -1622,13 +1764,15 @@ function theme_faq_page($variables) { } /** - * Theme function for the detailed questionfield + * Theme function for the detailed questionfield. + * + * @param array $variables + * Variables array. * - * @param Array $variables * @return string + * Markup. */ function theme_field_detailed_question($variables) { - // Render the label, if it's not hidden. $output = ''; @@ -1645,7 +1789,6 @@ function theme_field_detailed_question($variables) { } return $output; - } /** @@ -1673,4 +1816,3 @@ function theme_faq_draggable_question_order_table($variables) { $output .= drupal_render_children($form); return $output; } - From 3bf7b7800906b9749f9ec91e320d2909160d3109 Mon Sep 17 00:00:00 2001 From: Alexander Schedrov Date: Sat, 25 Oct 2014 13:26:58 +0300 Subject: [PATCH 15/17] Fixed codesniffer notices in faq.module. --- faq.module | 58 +++++++++++++++++--------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/faq.module b/faq.module index 317c04a..3d32c42 100644 --- a/faq.module +++ b/faq.module @@ -204,9 +204,11 @@ function faq_node_info() { * * @param object &$node * The node being added or edited. + * * @param array &$form_state * The hook can set this variable to an associative array of attributes to add * to the enclosing tag. + * * @return array * The form elements in the $form array. */ @@ -279,9 +281,6 @@ function faq_update($node) { * Implements hook_delete(). * * Deletes an FAQ node from the database. - * - * @param object &$node - * Which node to delete. */ function faq_delete($node) { db_delete('faq_weights') @@ -613,7 +612,13 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') { if ($format) { $faq_description = check_markup($faq_description, $format); } - return theme('faq_page', array('content' => $output, 'answers' => $output_answers, 'description' => $faq_description)); + return theme('faq_page', + array( + 'content' => $output, + 'answers' => $output_answers, + 'description' => $faq_description, + ) + ); } /** @@ -759,7 +764,6 @@ function _display_faq_by_category($faq_display, $category_display, $term, $displ ); break; - case 'new_page': include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.new_page.inc'; $output .= theme('faq_category_new_page', @@ -773,7 +777,6 @@ function _display_faq_by_category($faq_display, $category_display, $term, $displ ) ); break; - } // Handle indenting of categories. @@ -1398,7 +1401,16 @@ function faq_get_child_categories_faqs($term, $theme_function, $default_weight, $nids = $query->execute()->fetchCol(); $data = node_load_multiple($nids); - $output[] = theme($theme_function, array('data' => $data, 'display_header' => 1, 'category_display' => $category_display, 'term' => $child_term, 'class' => $class, 'parent_term' => $parent_term)); + $output[] = theme($theme_function, + array( + 'data' => $data, + 'display_header' => 1, + 'category_display' => $category_display, + 'term' => $child_term, + 'class' => $class, + 'parent_term' => $parent_term, + ) + ); } } @@ -1773,22 +1785,22 @@ function theme_faq_page($variables) { * Markup. */ function theme_field_detailed_question($variables) { - // Render the label, if it's not hidden. - $output = ''; + // Render the label, if it's not hidden. + $output = ''; - if (isset($variables['label']) && !$variables['label_hidden'] && $variables['label']) { - $output .= '
' . $variables['label'] . ': 
'; - } + if (isset($variables['label']) && !$variables['label_hidden'] && $variables['label']) { + $output .= '
' . $variables['label'] . ': 
'; + } - // Render the items. - $output .= '
' . $variables['safe_value'] . '
'; + // Render the items. + $output .= '
' . $variables['safe_value'] . '
'; - // Render the top-level DIV. - if (isset($variables['classes']) && isset($variables['attributes'])) { - $output = '
' . $output . '
'; - } + // Render the top-level DIV. + if (isset($variables['classes']) && isset($variables['attributes'])) { + $output = '
' . $output . '
'; + } - return $output; + return $output; } /** @@ -1812,7 +1824,13 @@ function theme_faq_draggable_question_order_table($variables) { 'class' => array('draggable'), ); } - $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'question-sort'))); + $output = theme('table', + array( + 'header' => $header, + 'rows' => $rows, + 'attributes' => array('id' => 'question-sort'), + ) + ); $output .= drupal_render_children($form); return $output; } From 91135fbfe31ba4863d1c35b30f20134aef66cdbe Mon Sep 17 00:00:00 2001 From: Alexander Schedrov Date: Sat, 25 Oct 2014 13:32:42 +0300 Subject: [PATCH 16/17] Fixed codesniffer notices in faq.module. --- faq.module | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/faq.module b/faq.module index 3d32c42..a09e291 100644 --- a/faq.module +++ b/faq.module @@ -202,10 +202,10 @@ function faq_node_info() { /** * Implements hook_form(). * - * @param object &$node + * @param object $node * The node being added or edited. * - * @param array &$form_state + * @param array $form_state * The hook can set this variable to an associative array of attributes to add * to the enclosing tag. * @@ -1592,6 +1592,7 @@ function faq_taxonomy_term_delete($term) { * The taxonomy term object. * * @return array|NULL + * Breadcrumbs. */ function faq_set_breadcrumb($term = NULL) { $breadcrumb = array(); From 0eeade2763df7f5f58691179651b1794360bebab Mon Sep 17 00:00:00 2001 From: Alexander Schedrov Date: Sat, 25 Oct 2014 13:39:49 +0300 Subject: [PATCH 17/17] Fixed JSHint notices. --- faq.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/faq.js b/faq.js index 84a2555..b2f8aca 100644 --- a/faq.js +++ b/faq.js @@ -122,7 +122,6 @@ }); }); } - } - } + }; })(jQuery);