diff --git a/sites/all/modules/context/context.core.inc b/sites/all/modules/context/context.core.inc
index 41ed93a..9e19831 100644
--- a/sites/all/modules/context/context.core.inc
+++ b/sites/all/modules/context/context.core.inc
@@ -94,11 +94,27 @@ function context_theme_registry_alter(&$theme_registry) {
*/
function context_ctools_render_alter($info, $page, $data) {
extract($data);
- if ($page && in_array($task['name'], array('node_view', 'node_edit'), TRUE)) {
- foreach ($contexts as $ctools_context) {
- if (in_array('node', $ctools_context->type) && !empty($ctools_context->data)) {
- context_node_condition($ctools_context->data, $task['name'] === 'node_view' ? 'view' : 'form');
- break;
+
+ // Check for page handlers.
+ if ($page) {
+ // Check for node page handler.
+ if (in_array($task['name'], array('node_view', 'node_edit'), TRUE)) {
+ foreach ($contexts as $ctools_context) {
+ if (in_array('node', $ctools_context->type) && !empty($ctools_context->data)) {
+ context_node_condition($ctools_context->data, $task['name'] === 'node_view' ? 'view' : 'form');
+ break;
+ }
+ }
+ }
+ // Check for taxonomy term page handler.
+ elseif (in_array($task['name'], array('term_view', 'term_edit'), TRUE)) {
+ foreach ($contexts as $ctools_context) {
+ if (in_array('taxonomy_term', $ctools_context->type) && !empty($ctools_context->data)) {
+ if ($plugin = context_get_plugin('condition', 'taxonomy_term')) {
+ $plugin->execute($ctools_context->data, $task['name'] === 'term_view' ? 'view' : 'form');
+ }
+ break;
+ }
}
}
}
diff --git a/sites/all/modules/context/context.info b/sites/all/modules/context/context.info
index a980c87..eef3a9c 100644
--- a/sites/all/modules/context/context.info
+++ b/sites/all/modules/context/context.info
@@ -8,9 +8,8 @@ files[] = tests/context.test
files[] = tests/context.conditions.test
files[] = tests/context.reactions.test
-; Information added by Drupal.org packaging script on 2015-01-06
-version = "7.x-3.6"
+; Information added by Drupal.org packaging script on 2019-02-26
+version = "7.x-3.10"
core = "7.x"
project = "context"
-datestamp = "1420573188"
-
+datestamp = "1551220089"
diff --git a/sites/all/modules/context/context.install b/sites/all/modules/context/context.install
index 0a5a145..0d902ef 100644
--- a/sites/all/modules/context/context.install
+++ b/sites/all/modules/context/context.install
@@ -103,7 +103,7 @@ function context_update_7000() {
}
}
if (empty($updated)) {
- $ret = t('No contexts requiring migration detected');
+ $ret = t('No contexts requiring migration detected.');
}
else {
$ret = t('The following contexts had theme reaction data migrated: @names', array('@names' => join(', ', $updated)));
diff --git a/sites/all/modules/context/context.module b/sites/all/modules/context/context.module
index 96808dd..c83b15e 100644
--- a/sites/all/modules/context/context.module
+++ b/sites/all/modules/context/context.module
@@ -192,11 +192,66 @@ function context_init() {
* theme('menu_link') for the menu rendering to html.
*/
function context_preprocess_menu_link(&$variables) {
- if($contexts = context_active_contexts()){
- foreach($contexts as $context){
- if((isset($context->reactions['menu']))){
- if ($variables['element']['#href'] == $context->reactions['menu']) {
- $variables['element']['#localized_options']['attributes']['class'][] = "active";
+ if ($contexts = context_active_contexts()) {
+ foreach ($contexts as $context) {
+ if (isset($context->reactions['menu'])) {
+ // In context module < v3.2 the url was a string. In version 3.3+ this is
+ // an array of urls. Implement interims BC layer.
+ //
+ // Examples:
+ // - OLD < v3.2 context reaction structure:
+ // array('menu' => 'taxonomy/term/1')
+ //
+ // - NEW 3.3+ context reaction structure:
+ // array(
+ // 'menu' => array(
+ // 0 => 'navigation:taxonomy/term/1'
+ // 1 => 'foo-menu:taxonomy/term/1'
+ // )
+ // )
+ $reactions_menu = is_array($context->reactions['menu']) ? array_values($context->reactions['menu']) : array($context->reactions['menu']);
+
+ // Get everything after the first ':' character (if found) as the url to
+ // match against element '#href'.
+ $urls = array();
+ foreach ($reactions_menu as $url) {
+ if (strpos($url, ':') !== FALSE) {
+ // Get unique menu name 'navigation' from 'navigation:taxonomy/term/1'
+ $reaction_menu = explode(':', $url);
+ $path = $reaction_menu[1];
+ $urls[$path] = $reaction_menu[0];
+ }
+ else {
+ // BC layer for menu contexts that have not re-saved. This is for
+ // urls like 'taxonomy/term/1'. We need to add a fake menu key
+ // 'bc-context-menu-layer' or the BC link get's removed by
+ // array_intersect below.
+ //
+ // @TODO: Remove BC layer in 4.x
+ $urls[$url] = 'context-reaction-menu-bc-layer';
+ }
+ }
+
+ // Filter urls by the menu name of the current link. The link reaction
+ // can be configured per menu link in specific menus and the contect
+ // reaction should not applied to other menus with the same menu link.
+ $menu_name = $variables['element']['#original_link']['menu_name'];
+ $menu_paths = array_intersect($urls, array($menu_name, 'context-reaction-menu-bc-layer'));
+ $reaction_menu_paths = array_keys($menu_paths);
+
+ // - If menu href and context reaction menu url match, add the 'active'
+ // css class to the link of this menu.
+ // - Do not add class twice on current page.
+ if (in_array($variables['element']['#href'], $reaction_menu_paths) && $variables['element']['#href'] != $_GET['q']) {
+ // Initialize classes array if not set.
+ if (!isset($variables['element']['#localized_options']['attributes']['class'])) {
+ $variables['element']['#localized_options']['attributes']['class'] = array();
+ }
+
+ // Do not add the 'active' class twice in views tabs.
+ if (!in_array('active', $variables['element']['#localized_options']['attributes']['class'])) {
+ $variables['element']['#localized_options']['attributes']['class'][] = 'active';
+ }
}
}
}
diff --git a/sites/all/modules/context/context.plugins.inc b/sites/all/modules/context/context.plugins.inc
index a0849bb..95d003d 100644
--- a/sites/all/modules/context/context.plugins.inc
+++ b/sites/all/modules/context/context.plugins.inc
@@ -37,7 +37,7 @@ function _context_context_registry() {
'plugin' => 'context_condition_path',
),
'query_string' => array(
- 'title' => t('Query String'),
+ 'title' => t('Query string'),
'description' => t('Set this context when any of the query strings above match the page query string. Put each query string on a separate line. You can use the "*" character as a wildcard and ~
to exclude one or more query strings.'),
'plugin' => 'context_condition_query_string',
),
@@ -119,7 +119,7 @@ function _context_context_registry() {
'plugin' => 'context_reaction_template_suggestions',
),
'theme' => array(
- 'title' => t('Theme Page'),
+ 'title' => t('Theme page'),
'description' => t('Control page theme variables using context.'),
'plugin' => 'context_reaction_theme',
),
diff --git a/sites/all/modules/context/context_layouts/context_layouts.info b/sites/all/modules/context/context_layouts/context_layouts.info
index 5ddb2cf..65880e3 100644
--- a/sites/all/modules/context/context_layouts/context_layouts.info
+++ b/sites/all/modules/context/context_layouts/context_layouts.info
@@ -6,9 +6,8 @@ core = 7.x
files[] = plugins/context_layouts_reaction_block.inc
-; Information added by Drupal.org packaging script on 2015-01-06
-version = "7.x-3.6"
+; Information added by Drupal.org packaging script on 2019-02-26
+version = "7.x-3.10"
core = "7.x"
project = "context"
-datestamp = "1420573188"
-
+datestamp = "1551220089"
diff --git a/sites/all/modules/context/context_ui/context_ui.info b/sites/all/modules/context/context_ui/context_ui.info
index 0006699..e5d17f8 100644
--- a/sites/all/modules/context/context_ui/context_ui.info
+++ b/sites/all/modules/context/context_ui/context_ui.info
@@ -8,9 +8,8 @@ configure = admin/structure/context
files[] = context.module
files[] = tests/context_ui.test
-; Information added by Drupal.org packaging script on 2015-01-06
-version = "7.x-3.6"
+; Information added by Drupal.org packaging script on 2019-02-26
+version = "7.x-3.10"
core = "7.x"
project = "context"
-datestamp = "1420573188"
-
+datestamp = "1551220089"
diff --git a/sites/all/modules/context/context_ui/context_ui.js b/sites/all/modules/context/context_ui/context_ui.js
index 308164f..56aa62a 100644
--- a/sites/all/modules/context/context_ui/context_ui.js
+++ b/sites/all/modules/context/context_ui/context_ui.js
@@ -12,11 +12,11 @@ function DrupalContextPlugins(form) {
$('.context-plugin-list > li', this.form).each(function() {
var plugin = $(this).attr('class').split('context-plugin-')[1].split(' ')[0];
if ($(this).is('.disabled')) {
- $('.context-plugin-selector select option[value='+plugin+']', this.form).show();
+ $('.context-plugin-selector select option[value="'+plugin+'"]', this.form).show();
}
else {
state.push(plugin);
- $('.context-plugin-selector select option[value='+plugin+']', this.form).hide();
+ $('.context-plugin-selector select option[value="'+plugin+'"]', this.form).hide();
}
});
// Set the hidden plugin list state.
diff --git a/sites/all/modules/context/context_ui/context_ui.module b/sites/all/modules/context/context_ui/context_ui.module
index 2ed2aa6..d694870 100644
--- a/sites/all/modules/context/context_ui/context_ui.module
+++ b/sites/all/modules/context/context_ui/context_ui.module
@@ -81,7 +81,7 @@ function context_ui_permission() {
'description' => 'Associate menus, views, blocks, etc. with different contexts to structure your site.'
);
$permissions['context ajax block access'] = array(
- 'title' => t('Access All Blocks'),
+ 'title' => t('Access all blocks'),
'description' => t('Allows users to access all rendered blocks via an AJAX callback. If you have some blocks that should not be rendered for some users but need those users to be able to use context UI, then implement hook_context_allow_ajax_block_access with the necessary logic.'),
);
return $permissions;
@@ -143,7 +143,7 @@ function context_ui_editor($form, &$form_state, $contexts) {
$form['title'] = array(
'#prefix' => '
', - '#markup' => t('Select which context, or layer of blocks, to edit. - Each context is configured to appear on different sets of pages so read the description carefully. - When you are done editing click Done and save your changes. - You may use the Stop Editing Layout link to close the editor.'), + '#markup' => t('Select which context, or layer of blocks, to edit. Each context is configured to appear on different sets of pages so read the description carefully. When you are done editing click Done and save your changes. You may use the Stop Editing Layout link to close the editor.'), '#suffix' => '
', '#weight' => -1, ); @@ -166,10 +163,9 @@ function context_ui_editor($form, &$form_state, $contexts) { $edit = l(t('Edit'), $_GET['q'], array('fragment' => $context->name, 'attributes' => array('class' => array('edit')))); $done = l(t('Done'), $_GET['q'], array('fragment' => $context->name, 'attributes' => array('class' => array('done')))); $readable_name = ucwords(str_replace('_', ' ', $context->name)); - $description = empty($context->description) ? '' : - "theme
') .'theme
') . 'About
'; + $output .= '' . 'The link provides a standard custom content field for links. Links can be easily added to any content types and profiles and include advanced validating and different ways of storing internal or external links and URLs. It also supports additional link text title, site wide tokens for titles and title attributes, target attributes, css class attribution, static repeating values, input conversion, and many more.' . '
'; + $output .= '' . 'Requirements / Dependencies' . '
'; + $output .= '' . 'Fields API is provided already by core [no dependencies].' . '
'; + $output .= 'Configuration
'; + $output .= '' . 'Configuration is only slightly more complicated than a text field. Link text titles for URLs can be made required, set as instead of URL, optional (default), or left out entirely. If no link text title is provided, the trimmed version of the complete URL will be displayed. The target attribute should be set to "_blank", "top", or left out completely (checkboxes provide info). The rel=nofollow attribute prevents the link from being followed by certain search engines.' . '
'; + return $output; + } +} + /** * Implements hook_field_info(). */ @@ -35,7 +49,7 @@ function link_field_info() { 'url' => 0, 'title' => 'optional', 'title_value' => '', - 'title_maxlength' => 128, //patch #1307788 from nmc + 'title_maxlength' => 128, 'enable_tokens' => 1, 'display' => array( 'url_cutoff' => 80, @@ -46,12 +60,14 @@ function link_field_info() { 'url' => 0, 'title' => 'optional', 'title_value' => '', - 'title_maxlength' => 128, // patch #1307788 from nmc + 'title_label_use_field_label' => FALSE, + 'title_maxlength' => 128, 'enable_tokens' => 1, 'display' => array( 'url_cutoff' => 80, ), 'validate_url' => 1, + 'absolute_url' => 1, ), 'default_widget' => 'link_field', 'default_formatter' => 'link_default', @@ -69,7 +85,14 @@ function link_field_instance_settings_form($field, $instance) { $form = array( '#element_validate' => array('link_field_settings_form_validate'), ); - + + $form['absolute_url'] = array( + '#type' => 'checkbox', + '#title' => t('Absolute URL'), + '#default_value' => isset($instance['settings']['absolute_url']) && ($instance['settings']['absolute_url'] !== '') ? $instance['settings']['absolute_url'] : TRUE, + '#description' => t('If checked, the URL will always render as an absolute URL.'), + ); + $form['validate_url'] = array( '#type' => 'checkbox', '#title' => t('Validate URL'), @@ -89,6 +112,7 @@ function link_field_instance_settings_form($field, $instance) { 'optional' => t('Optional Title'), 'required' => t('Required Title'), 'value' => t('Static Title'), + 'select' => t('Selected Title'), 'none' => t('No Title'), ); @@ -97,51 +121,65 @@ function link_field_instance_settings_form($field, $instance) { '#title' => t('Link Title'), '#default_value' => isset($instance['settings']['title']) ? $instance['settings']['title'] : 'optional', '#options' => $title_options, - '#description' => t('If the link title is optional or required, a field will be displayed to the end user. If the link title is static, the link will always use the same title. If token module is installed, the static title value may use any other node field as its value. Static and token-based titles may include most inline XHTML tags such as strong, em, img, span, etc.'), + '#description' => t('If the link title is optional or required, a field will be displayed to the end user. If the link title is static, the link will always use the same title. If token module is installed, the static title value may use any other entity field as its value. Static and token-based titles may include most inline XHTML tags such as strong, em, img, span, etc.'), ); $form['title_value'] = array( '#type' => 'textfield', - '#title' => t('Static title'), + '#title' => t('Static or default title'), '#default_value' => isset($instance['settings']['title_value']) ? $instance['settings']['title_value'] : '', - '#description' => t('This title will always be used if “Static Title” is selected above.'), + '#description' => t('This title will 1) always be used if "Static Title" is selected above, or 2) used if "Optional title" is selected above and no title is entered when creating content.'), + '#states' => array( + 'visible' => array( + ':input[name="instance[settings][title]"]' => array('value' => 'value'), + ), + ), ); - $form['title_maxlength'] = array( // patch #1307788 from nmc + $form['title_allowed_values'] = array( + '#type' => 'textarea', + '#title' => t('Title allowed values'), + '#default_value' => isset($instance['settings']['title_allowed_values']) ? $instance['settings']['title_allowed_values'] : '', + '#description' => t('When using "Selected Title", you can allow users to select the title from a limited set of values (eg. Home, Office, Other). Enter here all possible values that title can take, one value per line.'), + '#states' => array( + 'visible' => array( + ':input[name="instance[settings][title]"]' => array('value' => 'select'), + ), + ), + ); + + $form['title_label_use_field_label'] = array( + '#type' => 'checkbox', + '#title' => t('Use field label as the label for the title field'), + '#default_value' => isset($instance['settings']['title_label_use_field_label']) ? $instance['settings']['title_label_use_field_label'] : FALSE, + '#description' => t('If this is checked the field label will be hidden.'), + ); + + $form['title_maxlength'] = array( '#type' => 'textfield', '#title' => t('Max length of title field'), '#default_value' => isset($instance['settings']['title_maxlength']) ? $instance['settings']['title_maxlength'] : '128', '#description' => t('Set a maximum length on the title field (applies only if Link Title is optional or required). The maximum limit is 255 characters.'), '#maxlength' => 3, '#size' => 3, - ); + ); if (module_exists('token')) { - // Add token module replacements fields - $form['tokens'] = array( - '#type' => 'fieldset', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#title' => t('Placeholder tokens'), - '#description' => t("The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."), - ); - $token_type = array( - 'theme' => 'token_tree', - 'token_types' => array($instance['entity_type']), - 'global_types' => TRUE, - 'click_insert' => TRUE, - 'recursion_limit' => 2, - ); - $form['tokens']['help'] = array( - '#type' => 'markup', - '#markup' => theme('token_tree', $token_type), - ); - + // Add token module replacements fields. $form['enable_tokens'] = array( '#type' => 'checkbox', '#title' => t('Allow user-entered tokens'), '#default_value' => isset($instance['settings']['enable_tokens']) ? $instance['settings']['enable_tokens'] : 1, - '#description' => t('Checking will allow users to enter tokens in URLs and Titles on the node edit form. This does not affect the field settings on this page.'), + '#description' => t('Checking will allow users to enter tokens in URLs and Titles on the entity edit form. This does not affect the field settings on this page.'), + ); + + $entity_info = entity_get_info($instance['entity_type']); + $form['tokens_help'] = array( + '#theme' => 'token_tree', + '#token_types' => array($entity_info['token type']), + '#global_types' => TRUE, + '#click_insert' => TRUE, + '#dialog' => TRUE, ); } @@ -154,7 +192,7 @@ function link_field_instance_settings_form($field, $instance) { '#default_value' => isset($instance['settings']['display']['url_cutoff']) ? $instance['settings']['display']['url_cutoff'] : '80', '#description' => t('If the user does not include a title for this link, the URL will be used as the title. When should the link title be trimmed and finished with an elipsis (…)? Leave blank for no limit.'), '#maxlength' => 3, - '#size' => 3, + '#size' => 3, ); $target_options = array( @@ -175,16 +213,33 @@ function link_field_instance_settings_form($field, $instance) { $form['attributes']['rel'] = array( '#type' => 'textfield', '#title' => t('Rel Attribute'), - '#description' => t('When output, this link will have this rel attribute. The most common usage is rel="nofollow" which prevents some search engines from spidering entered links.'), + '#description' => t('When output, this link will have this rel attribute. The most common usage is rel="nofollow" which prevents some search engines from spidering entered links.'), '#default_value' => empty($instance['settings']['attributes']['rel']) ? '' : $instance['settings']['attributes']['rel'], '#field_prefix' => 'rel = "', '#field_suffix' => '"', '#size' => 20, ); + $rel_remove_options = array( + 'default' => t('Keep rel as set up above (untouched/default)'), + 'rel_remove_external' => t('Remove rel if given link is external'), + 'rel_remove_internal' => t('Remove rel if given link is internal'), + ); + $form['rel_remove'] = array( + '#type' => 'radios', + '#title' => t('Remove rel attribute automatically'), + '#default_value' => !isset($instance['settings']['rel_remove']) ? 'default' : $instance['settings']['rel_remove'], + '#description' => t('Turn on/off if rel attribute should be removed automatically, if user given link is internal/external'), + '#options' => $rel_remove_options, + ); + $form['attributes']['configurable_class'] = array( + '#title' => t("Allow the user to enter a custom link class per link"), + '#type' => 'checkbox', + '#default_value' => empty($instance['settings']['attributes']['configurable_class']) ? '' : $instance['settings']['attributes']['configurable_class'], + ); $form['attributes']['class'] = array( '#type' => 'textfield', '#title' => t('Additional CSS Class'), - '#description' => t('When output, this link will have this class attribute. Multiple classes should be separated by spaces.'), + '#description' => t('When output, this link will have this class attribute. Multiple classes should be separated by spaces. Only alphanumeric characters and hyphens are allowed'), '#default_value' => empty($instance['settings']['attributes']['class']) ? '' : $instance['settings']['attributes']['class'], ); $form['attributes']['configurable_title'] = array( @@ -195,7 +250,7 @@ function link_field_instance_settings_form($field, $instance) { $form['attributes']['title'] = array( '#title' => t("Default link 'title' Attribute"), '#type' => 'textfield', - '#description' => t('When output, links will use this "title" attribute if the user does not provide one and when different from the link text. Read WCAG 1.0 Guidelines for links comformances. Tokens values will be evaluated.'), + '#description' => t('When output, links will use this "title" attribute if the user does not provide one and when different from the link text. Read WCAG 1.0 Guidelines for links comformances. Tokens values will be evaluated.'), '#default_value' => empty($instance['settings']['attributes']['title']) ? '' : $instance['settings']['attributes']['title'], '#field_prefix' => 'title = "', '#field_suffix' => '"', @@ -205,29 +260,34 @@ function link_field_instance_settings_form($field, $instance) { } /** - * Validate the field settings form. + * Form validate. + * + * #element_validate handler for link_field_instance_settings_form(). */ function link_field_settings_form_validate($element, &$form_state, $complete_form) { - if ($form_state['values']['instance']['settings']['title'] === 'value' - && empty($form_state['values']['instance']['settings']['title_value'])) { - form_set_error('title_value', t('A default title must be provided if the title is a static value.')); + if ($form_state['values']['instance']['settings']['title'] === 'value' && empty($form_state['values']['instance']['settings']['title_value'])) { + form_set_error('instance][settings][title_value', t('A default title must be provided if the title is a static value.')); } - if (!empty($form_state['values']['instance']['settings']['display']['url_cutoff']) // patch #1307788 from nmc - && !is_numeric($form_state['values']['instance']['settings']['display']['url_cutoff'])) { + if ($form_state['values']['instance']['settings']['title'] === 'select' + && empty($form_state['values']['instance']['settings']['title_allowed_values'])) { + form_set_error('instance][settings][title_allowed_values', t('You must enter one or more allowed values for link Title, the title is a selected value.')); + } + if (!empty($form_state['values']['instance']['settings']['display']['url_cutoff']) && !is_numeric($form_state['values']['instance']['settings']['display']['url_cutoff'])) { form_set_error('display', t('URL Display Cutoff value must be numeric.')); } - if (empty($form_state['values']['instance']['settings']['title_maxlength'])) { // patch #1307788 from nmc + if (empty($form_state['values']['instance']['settings']['title_maxlength'])) { form_set_value($element['title_maxlength'], '128', $form_state); - } elseif (!is_numeric($form_state['values']['instance']['settings']['title_maxlength'])) { + } + elseif (!is_numeric($form_state['values']['instance']['settings']['title_maxlength'])) { form_set_error('title_maxlength', t('The max length of the link title must be numeric.')); - } elseif ($form_state['values']['instance']['settings']['title_maxlength'] > 255) { + } + elseif ($form_state['values']['instance']['settings']['title_maxlength'] > 255) { form_set_error('title_maxlength', t('The max length of the link title cannot be greater than 255 characters.')); } - } /** - * Implement hook_field_is_empty(). + * Implements hook_field_is_empty(). */ function link_field_is_empty($item, $field) { return empty($item['title']) && empty($item['url']); @@ -251,21 +311,44 @@ function link_field_validate($entity_type, $entity, $field, $instance, $langcode $optional_field_found = FALSE; if ($instance['settings']['validate_url'] !== 0 || is_null($instance['settings']['validate_url']) || !isset($instance['settings']['validate_url'])) { foreach ($items as $delta => $value) { - _link_validate($items[$delta], $delta, $field, $entity, $instance, $optional_field_found); + _link_validate($items[$delta], $delta, $field, $entity, $instance, $langcode, $optional_field_found, $errors); + } + } + + foreach ($items as $delta => $value) { + if (isset($value['attributes']) && is_string($value['attributes'])) { + $errors[$field['field_name']][$langcode][$delta][] = array( + 'error' => 'link_required', + 'message' => t('String values are not acceptable for attributes.'), + 'error_element' => array('url' => TRUE, 'title' => FALSE), + ); } } if ($instance['settings']['url'] === 'optional' && $instance['settings']['title'] === 'optional' && $instance['required'] && !$optional_field_found) { - form_set_error($field['field_name'] .'][0][title', t('At least one title or URL must be entered.')); + $errors[$field['field_name']][$langcode][0][] = array( + 'error' => 'link_required', + 'message' => t('At least one title or URL must be entered.'), + 'error_element' => array('url' => FALSE, 'title' => TRUE), + ); } } /** - * Implements hook_field_presave(). + * Implements hook_field_insert(). */ -function link_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) { +function link_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { foreach ($items as $delta => $value) { - _link_process($items[$delta], $delta, $field, $entity); + _link_process($items[$delta], $delta, $field, $entity, $instance); + } +} + +/** + * Implements hook_field_update(). + */ +function link_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { + foreach ($items as $delta => $value) { + _link_process($items[$delta], $delta, $field, $entity, $instance); } } @@ -304,17 +387,29 @@ function link_field_widget_form(&$form, &$form_state, $field, $instance, $langco return $element; } +/** + * Implements hook_field_widget_error(). + */ +function link_field_widget_error($element, $error, $form, &$form_state) { + if (!empty($error['error_element']['title'])) { + form_error($element['title'], $error['message']); + } + elseif (!empty($error['error_element']['url'])) { + form_error($element['url'], $error['message']); + } +} + /** * Unpacks the item attributes for use. */ function _link_load($field, $item, $instance) { - /*return $item['attributes'] = isset($item['attributes']) ? - unserialize($item['attributes']) : - $instance['settings']['attributes'];*/ if (isset($item['attributes'])) { - return unserialize($item['attributes']); + if (!is_array($item['attributes'])) { + $item['attributes'] = unserialize($item['attributes']); + } + return $item['attributes']; } - else if (isset($instance['settings']['attributes'])) { + elseif (isset($instance['settings']['attributes'])) { return $instance['settings']['attributes']; } else { @@ -324,12 +419,29 @@ function _link_load($field, $item, $instance) { /** * Prepares the item attributes and url for storage. + * + * @param array $item + * Link field values. + * @param array $delta + * The sequence number for current values. + * @param array $field + * The field structure array. + * @param object $entity + * Entity object. + * @param array $instance + * The instance structure for $field on $entity's bundle. + * + * @codingStandardsIgnoreStart */ -function _link_process(&$item, $delta = 0, $field, $entity) { +function _link_process(&$item, $delta, $field, $entity, $instance) { + // @codingStandardsIgnoreEnd // Trim whitespace from URL. - $item['url'] = trim($item['url']); + if (!empty($item['url'])) { + $item['url'] = trim($item['url']); + } - // if no attributes are set then make sure $item['attributes'] is an empty array - this lets $field['attributes'] override it. + // If no attributes are set then make sure $item['attributes'] is an empty + // array, so $field['attributes'] can override it. if (empty($item['attributes'])) { $item['attributes'] = array(); } @@ -340,9 +452,9 @@ function _link_process(&$item, $delta = 0, $field, $entity) { } // Don't save an invalid default value (e.g. 'http://'). - if ((isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url']) - && is_object($node)) { - if (!link_validate_url($item['url'])) { + if ((isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url']) && is_object($entity)) { + $langcode = !empty($entity) ? field_language($instance['entity_type'], $entity, $instance['field_name']) : LANGUAGE_NONE; + if (!link_validate_url($item['url'], $langcode)) { unset($item['url']); } } @@ -351,128 +463,190 @@ function _link_process(&$item, $delta = 0, $field, $entity) { /** * Validates that the link field has been entered properly. */ -function _link_validate(&$item, $delta, $field, $node, $instance, &$optional_field_found) { - if ($item['url'] - && !(isset($instance['default_value'][$delta]['url']) - && $item['url'] === $instance['default_value'][$delta]['url'] - && !$instance['required'])) { +function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, &$optional_field_found, &$errors) { + if ($item['url'] && !(isset($instance['default_value'][$delta]['url']) && $item['url'] === $instance['default_value'][$delta]['url'] && !$instance['required'])) { // Validate the link. - if (link_validate_url(trim($item['url'])) == FALSE) { - form_set_error($field['field_name'] .']['. $delta .'][url', t('Not a valid URL.')); + if (!link_validate_url(trim($item['url']), $langcode)) { + $errors[$field['field_name']][$langcode][$delta][] = array( + 'error' => 'link_required', + 'message' => t('The value %value provided for %field is not a valid URL.', array( + '%value' => trim($item['url']), + '%field' => $instance['label'], + )), + 'error_element' => array('url' => TRUE, 'title' => FALSE), + ); } // Require a title for the link if necessary. if ($instance['settings']['title'] == 'required' && strlen(trim($item['title'])) == 0) { - form_set_error($field['field_name'] .']['. $delta .'][title', t('Titles are required for all links.')); + $errors[$field['field_name']][$langcode][$delta][] = array( + 'error' => 'link_required', + 'message' => t('Titles are required for all links.'), + 'error_element' => array('url' => FALSE, 'title' => TRUE), + ); } } // Require a link if we have a title. - if ($instance['settings']['url'] !== 'optional' - && strlen(isset($item['title']) ? $item['title'] : NULL) > 0 - && strlen(trim($item['url'])) == 0) { - form_set_error($field['field_name'] .']['. $delta .'][url', t('You cannot enter a title without a link url.')); + if ($instance['settings']['url'] !== 'optional' && strlen(isset($item['title']) ? $item['title'] : NULL) > 0 && strlen(trim($item['url'])) == 0) { + $errors[$field['field_name']][$langcode][$delta][] = array( + 'error' => 'link_required', + 'message' => t('You cannot enter a title without a link url.'), + 'error_element' => array('url' => TRUE, 'title' => FALSE), + ); } - // In a totally bizzaro case, where URLs and titles are optional but the field is required, ensure there is at least one link. - if ($instance['settings']['url'] === 'optional' - && $instance['settings']['title'] === 'optional' - && (strlen(trim($item['url'])) !== 0 || strlen(trim($item['title'])) !== 0)) { + // In a totally bizzaro case, where URLs and titles are optional but the field + // is required, ensure there is at least one link. + if ($instance['settings']['url'] === 'optional' && $instance['settings']['title'] === 'optional' + && (strlen(trim($item['url'])) !== 0 || strlen(trim($item['title'])) !== 0)) { $optional_field_found = TRUE; } - // Require entire field - if ($instance['settings']['url'] === 'optional' - && $instance['settings']['title'] === 'optional' - && $instance['required'] == 1 - && !$optional_field_found - && isset($instance['id'])) { - form_set_error($instance['field_name'] .'][0][title', - t('At least one title or URL must be entered.')); + // Require entire field. + if ($instance['settings']['url'] === 'optional' && $instance['settings']['title'] === 'optional' && $instance['required'] == 1 && !$optional_field_found && isset($instance['id'])) { + $errors[$field['field_name']][$langcode][$delta][] = array( + 'error' => 'link_required', + 'message' => t('At least one title or URL must be entered.'), + 'error_element' => array('url' => FALSE, 'title' => TRUE), + ); } } /** - * Cleanup user-entered values for a link field according to field settings. + * Clean up user-entered values for a link field according to field settings. * - * @param $item + * @param array $item * A single link item, usually containing url, title, and attributes. - * @param $delta + * @param int $delta * The delta value if this field is one of multiple fields. - * @param $field + * @param array $field * The CCK field definition. - * @param $node - * The node containing this link. + * @param object $entity + * The entity containing this link. + * + * @codingStandardsIgnoreStart */ -function _link_sanitize(&$item, $delta, &$field, $instance, &$node) { +function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) { + // @codingStandardsIgnoreEnd // Don't try to process empty links. if (empty($item['url']) && empty($item['title'])) { return; } - - // Replace URL tokens. - if (isset($instance['settings']['enable_tokens']) && $instance['settings']['enable_tokens']) { - global $user; - // Load the node if necessary for nodes in views. - $token_node = isset($node->nid) ? node_load($node->nid) : $node; - $item['url'] = token_replace($item['url'], array('node' => $token_node)); + if (empty($item['html'])) { + $item['html'] = FALSE; } - $type = link_validate_url($item['url']); - // If we can't determine the type of url, and we've been told not to validate it, - // then we assume it's a LINK_EXTERNAL type for later processing. #357604 + // Replace URL tokens. + $entity_type = $instance['entity_type']; + $entity_info = entity_get_info($entity_type); + $property_id = $entity_info['entity keys']['id']; + $entity_token_type = isset($entity_info['token type']) ? $entity_info['token type'] : ( + $entity_type == 'taxonomy_term' || $entity_type == 'taxonomy_vocabulary' ? str_replace('taxonomy_', '', $entity_type) : $entity_type + ); + if (isset($instance['settings']['enable_tokens']) && $instance['settings']['enable_tokens']) { + $text_tokens = token_scan($item['url']); + if (!empty($text_tokens)) { + // Load the entity if necessary for entities in views. + if (isset($entity->{$property_id})) { + $entity_loaded = entity_load($entity_type, array($entity->{$property_id})); + $entity_loaded = array_pop($entity_loaded); + } + else { + $entity_loaded = $entity; + } + $item['url'] = token_replace($item['url'], array($entity_token_type => $entity_loaded)); + } + } + + $type = link_url_type($item['url']); + // If the type of the URL cannot be determined and URL validation is disabled, + // then assume LINK_EXTERNAL for later processing. if ($type == FALSE && $instance['settings']['validate_url'] === 0) { $type = LINK_EXTERNAL; } $url = link_cleanup_url($item['url']); + $url_parts = _link_parse_url($url); - // Separate out the anchor if any. - if (strpos($url, '#') !== FALSE) { - $item['fragment'] = substr($url, strpos($url, '#') + 1); - $url = substr($url, 0, strpos($url, '#')); + if (!empty($url_parts['url'])) { + $item['url'] = url($url_parts['url'], + array( + 'query' => isset($url_parts['query']) ? $url_parts['query'] : NULL, + 'fragment' => isset($url_parts['fragment']) ? $url_parts['fragment'] : NULL, + 'absolute' => !empty($instance['settings']['absolute_url']), + 'html' => TRUE, + ) + ); } - // Separate out the query string if any. - if (strpos($url, '?') !== FALSE) { - $query = substr($url, strpos($url, '?') + 1); - parse_str($query, $query_array); - $item['query'] = $query_array; - $url = substr($url, 0, strpos($url, '?')); - } - - $item['url'] = check_plain($url); // Create a shortened URL for display. - $display_url = $type == LINK_EMAIL ? - str_replace('mailto:', '', $url) : - url($url, array('query' => isset($item['query']) ? - $item['query'] : - NULL, - 'fragment' => isset($item['fragment']) ? - $item['fragment'] : - NULL, - 'absolute' => TRUE)); + if ($type == LINK_EMAIL) { + $display_url = str_replace('mailto:', '', $url); + } + else { + $display_url = url($url_parts['url'], + array( + 'query' => isset($url_parts['query']) ? $url_parts['query'] : NULL, + 'fragment' => isset($url_parts['fragment']) ? $url_parts['fragment'] : NULL, + 'absolute' => !empty($instance['settings']['absolute_url']), + ) + ); + } if ($instance['settings']['display']['url_cutoff'] && strlen($display_url) > $instance['settings']['display']['url_cutoff']) { - $display_url = substr($display_url, 0, $instance['settings']['display']['url_cutoff']) ."..."; + $display_url = substr($display_url, 0, $instance['settings']['display']['url_cutoff']) . "..."; } $item['display_url'] = $display_url; // Use the title defined at the instance level. if ($instance['settings']['title'] == 'value' && strlen(trim($instance['settings']['title_value']))) { $title = $instance['settings']['title_value']; + if (function_exists('i18n_string_translate')) { + $i18n_string_name = "field:{$instance['field_name']}:{$instance['bundle']}:title_value"; + $title = i18n_string_translate($i18n_string_name, $title); + } } // Use the title defined by the user at the widget level. - else if (isset($item['title'])) { + elseif (drupal_strlen(trim($item['title']))) { $title = $item['title']; } + // Use the static title if a user-defined title is optional and a static title + // has been defined. + elseif ($instance['settings']['title'] == 'optional' && drupal_strlen(trim($instance['settings']['title_value']))) { + $title = $instance['settings']['title_value']; + } else { $title = ''; } - // Replace tokens. + // Replace title tokens. + if ($title && $instance['settings']['enable_tokens']) { + $text_tokens = token_scan($title); + if (!empty($text_tokens)) { + // Load the entity if necessary for entities in views. + if (isset($entity->{$property_id})) { + $entity_loaded = entity_load($entity_type, array($entity->{$property_id})); + $entity_loaded = array_pop($entity_loaded); + } + else { + $entity_loaded = $entity; + } + $title = token_replace($title, array($entity_token_type => $entity_loaded)); + } + } if ($title && ($instance['settings']['title'] == 'value' || $instance['settings']['enable_tokens'])) { - // Load the node if necessary for nodes in views. - $token_node = isset($node->nid) ? node_load($node->nid) : $node; - $title = filter_xss(token_replace($title, array('node' => $token_node)), - array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u')); + $title = filter_xss($title, array( + 'b', + 'br', + 'code', + 'em', + 'i', + 'img', + 'span', + 'strong', + 'sub', + 'sup', + 'tt', + 'u', + )); $item['html'] = TRUE; } - $item['title'] = empty($title) ? $item['display_url'] : $title; + $item['title'] = empty($title) && $title !== '0' ? $item['display_url'] : $title; if (!isset($item['attributes'])) { $item['attributes'] = array(); @@ -480,11 +654,11 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$node) { // Unserialize attributtes array if it has not been unserialized yet. if (!is_array($item['attributes'])) { - $item['attributes'] = (array)unserialize($item['attributes']); + $item['attributes'] = (array) unserialize($item['attributes']); } // Add default attributes. - if (!is_array($instance['settings']['attributes'])){ + if (!is_array($instance['settings']['attributes'])) { $instance['settings']['attributes'] = _link_default_attributes(); } else { @@ -499,24 +673,62 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$node) { if ($instance['settings']['attributes']['target'] != LINK_TARGET_USER) { $item['attributes']['target'] = $instance['settings']['attributes']['target']; } + elseif ($item['attributes']['target'] == LINK_TARGET_USER) { + $item['attributes']['target'] = LINK_TARGET_DEFAULT; + } // Remove the target attribute if the default (no target) is selected. - if (empty($item['attributes']) || $item['attributes']['target'] == LINK_TARGET_DEFAULT) { + if (empty($item['attributes']) || (isset($item['attributes']['target']) && $item['attributes']['target'] == LINK_TARGET_DEFAULT)) { unset($item['attributes']['target']); } - // Remove the rel=nofollow for internal links. - if ($type != LINK_EXTERNAL && strpos($item['attributes']['rel'], 'nofollow') !== FALSE) { - $item['attributes']['rel'] = str_replace('nofollow', '', $item['attributes']); + // Remove rel attribute for internal or external links if selected. + if (isset($item['attributes']['rel']) && isset($instance['settings']['rel_remove']) && $instance['settings']['rel_remove'] != 'default') { + if (($instance['settings']['rel_remove'] != 'rel_remove_internal' && $type != LINK_INTERNAL) || + ($instance['settings']['rel_remove'] != 'rel_remove_external' && $type != LINK_EXTERNAL)) { + unset($item['attributes']['rel']); + } } // Handle "title" link attribute. if (!empty($item['attributes']['title']) && module_exists('token')) { - // Load the node (necessary for nodes in views). - $token_node = isset($node->nid) ? node_load($node->nid) : $node; - $item['attributes']['title'] = filter_xss(token_replace($item['attributes']['title'], array('node' => $token_node)), - array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u')); + $text_tokens = token_scan($item['attributes']['title']); + if (!empty($text_tokens)) { + // Load the entity (necessary for entities in views). + if (isset($entity->{$property_id})) { + $entity_loaded = entity_load($entity_type, array($entity->{$property_id})); + $entity_loaded = array_pop($entity_loaded); + } + else { + $entity_loaded = $entity; + } + $item['attributes']['title'] = token_replace($item['attributes']['title'], array($entity_token_type => $entity_loaded)); + } + $item['attributes']['title'] = filter_xss($item['attributes']['title'], array( + 'b', + 'br', + 'code', + 'em', + 'i', + 'img', + 'span', + 'strong', + 'sub', + 'sup', + 'tt', + 'u', + )); } + // Handle attribute classes. + if (!empty($item['attributes']['class'])) { + $classes = explode(' ', $item['attributes']['class']); + foreach ($classes as &$class) { + $class = drupal_clean_css_identifier($class); + } + $item['attributes']['class'] = implode(' ', $classes); + } + unset($item['attributes']['configurable_class']); + // Remove title attribute if it's equal to link text. if (isset($item['attributes']['title']) && $item['attributes']['title'] == $item['title']) { unset($item['attributes']['title']); @@ -525,16 +737,66 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$node) { // Remove empty attributes. $item['attributes'] = array_filter($item['attributes']); +} - // Sets title to trimmed url if one exists - // @TODO: Do we need this? It seems not. - /*if(!empty($item['display_url']) && empty($item['title'])) { - $item['title'] = $item['display_url']; +/** + * Because parse_url doesn't work with relative urls. + * + * @param string $url + * URL to parse. + * + * @return array + * Array of url pieces - only 'url', 'query', and 'fragment'. + */ +function _link_parse_url($url) { + $url_parts = array(); + // Separate out the anchor, if any. + if (strpos($url, '#') !== FALSE) { + $url_parts['fragment'] = substr($url, strpos($url, '#') + 1); + $url = substr($url, 0, strpos($url, '#')); } - elseif(!isset($item['title'])) { - $item['title'] = $item['url']; - }*/ + // Separate out the query string, if any. + if (strpos($url, '?') !== FALSE) { + $query = substr($url, strpos($url, '?') + 1); + $url_parts['query'] = _link_parse_str($query); + $url = substr($url, 0, strpos($url, '?')); + } + $url_parts['url'] = $url; + return $url_parts; +} +/** + * Replaces the PHP parse_str() function. + * + * Because parse_str replaces the following characters in query parameters name + * in order to maintain compatibility with deprecated register_globals + * directive: + * + * - chr(32) ( ) (space) + * - chr(46) (.) (dot) + * - chr(91) ([) (open square bracket) + * - chr(128) - chr(159) (various) + * + * @param string $query + * Query to parse. + * + * @return array + * Array of query parameters. + * + * @see http://php.net/manual/en/language.variables.external.php#81080 + */ +function _link_parse_str($query) { + $query_array = array(); + + $pairs = explode('&', $query); + foreach ($pairs as $pair) { + $name_value = explode('=', $pair, 2); + $name = urldecode($name_value[0]); + $value = isset($name_value[1]) ? urldecode($name_value[1]) : NULL; + $query_array[$name] = $value; + } + + return $query_array; } /** @@ -542,29 +804,42 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$node) { */ function link_theme() { return array( - /*'link_field_settings' => array( - 'variables' => array('element' => NULL), - ),*/ 'link_formatter_link_default' => array( - 'variables' => array('element' => NULL), + 'variables' => array('element' => NULL, 'field' => NULL), ), 'link_formatter_link_plain' => array( + 'variables' => array('element' => NULL, 'field' => NULL), + ), + 'link_formatter_link_host' => array( 'variables' => array('element' => NULL), ), + 'link_formatter_link_absolute' => array( + 'variables' => array('element' => NULL, 'field' => NULL), + ), + 'link_formatter_link_domain' => array( + 'variables' => array( + 'element' => NULL, + 'display' => NULL, + 'field' => NULL, + ), + ), + 'link_formatter_link_no_protocol' => array( + 'variables' => array('element' => NULL, 'field' => NULL), + ), 'link_formatter_link_title_plain' => array( - 'variables' => array('element' => NULL), + 'variables' => array('element' => NULL, 'field' => NULL), ), 'link_formatter_link_url' => array( - 'variables' => array('element' => NULL), + 'variables' => array('element' => NULL, 'field' => NULL), ), 'link_formatter_link_short' => array( - 'variables' => array('element' => NULL), + 'variables' => array('element' => NULL, 'field' => NULL), ), 'link_formatter_link_label' => array( - 'variables' => array('element' => NULL), + 'variables' => array('element' => NULL, 'field' => NULL), ), 'link_formatter_link_separate' => array( - 'variables' => array('element' => NULL), + 'variables' => array('element' => NULL, 'field' => NULL), ), 'link_field' => array( 'render element' => 'element', @@ -573,32 +848,35 @@ function link_theme() { } /** - * FAPI theme for an individual text elements. + * Formats a link field widget. */ function theme_link_field($vars) { - drupal_add_css(drupal_get_path('module', 'link') .'/link.css'); - + drupal_add_css(drupal_get_path('module', 'link') . '/link.css'); $element = $vars['element']; // Prefix single value link fields with the name of the field. if (empty($element['#field']['multiple'])) { if (isset($element['url']) && !isset($element['title'])) { - unset($element['url']['#title']); + $element['url']['#title_display'] = 'invisible'; } } $output = ''; $output .= ''. print_r($field, TRUE) .''); - $field_db_info = content_database_info($field);*/ - - //$this->acquireNodes(2); - /*$node = $this->drupalCreateNode(array('type' => $content_type_machine, - 'promote' => 1)); - $test_nid = $node->nid;*/ - - //$node = node_load($this->nodes[0]->nid); - //$node->promote = 1; // We want this to show on front page for the teaser test. - /*$this->assert('debug', print_r($node, TRUE), 'Debug'); - $node->{$single_field_name}['und'][0] = $this->createLink('http://www.example.com', 'Test Link'); - node_save($node); - $this->assert('debug', print_r($node, TRUE), 'Debug');*/ - - //$this->drupalGet('node/'. $test_nid .'/edit'); - $this->drupalGet('node/add/'. $content_type_machine); - - // lets add a node: + // Create a node: $edit = array( 'title' => $title, 'field_' . $single_field_name_machine . '[und][0][url]' => 'http://www.example.com/', @@ -164,29 +160,21 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { // Now we can fill in the second item in the multivalue field and save. $this->drupalPost(NULL, $edit, t('Save')); - $this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title))); + $this->assertText(t('@content_type_friendly @title has been created', array( + '@content_type_friendly' => $content_type_friendly, + '@title' => $title, + ))); $this->assertText('Display'); - //$this->assertText('http://www.example.com/'); $this->assertLinkByHref('http://www.example.com'); } - private function createNodeType($content_type_machine, $content_type_friendly) { - $this->drupalGet('admin/structure/types'); - - // Create the content type. - $this->clickLink(t('Add content type')); - - $edit = array ( - 'name' => $content_type_friendly, - 'type' => $content_type_machine, - ); - $this->drupalPost(NULL, $edit, t('Save and add fields')); - $this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly))); - } - - private function createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine) { - $edit = array ( + /** + * Create Simple Link Field. + */ + protected function createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine) { + $this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/fields'); + $edit = array( 'fields[_add_new_field][label]' => $single_field_name_friendly, 'fields[_add_new_field][field_name]' => $single_field_name_machine, 'fields[_add_new_field][type]' => 'link_field', @@ -209,22 +197,26 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $this->assertTrue($type_exists, 'The new content type has been created in the database.'); } - function createNodeTypeUser($content_type_machine) { + /** + * Create Node Type User. + */ + protected function createNodeTypeUser($content_type_machine) { $permission = 'create ' . $content_type_machine . ' content'; - $permission_edit = 'edit ' . $content_type_machine . ' content'; // Reset the permissions cache. $this->checkPermissions(array($permission), TRUE); // Now that we have a new content type, create a user that has privileges // on the content type. $permissions = array_merge($this->permissions, array($permission)); - $account = $this->drupalCreateUser($permissions); - $this->drupalLogin($account); + $this->web_user = $this->drupalCreateUser($permissions); + $this->drupalLogin($this->web_user); } - function createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $title, $url, $node_title = '') { - // Go to page. - $this->drupalGet('node/add/'. $content_type_machine); + /** + * Create Node For Testing. + */ + protected function createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $title, $url, $node_title = '') { + $this->drupalGet('node/add/' . $content_type_machine); if (!$node_title) { $node_title = $this->randomName(20); @@ -239,29 +231,91 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $edit['field_' . $single_field_name_machine . '[und][0][title]'] = $title; } - // Now we can fill in the second item in the multivalue field and save. $this->drupalPost(NULL, $edit, t('Save')); - $this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $node_title))); + $this->assertText(t('@content_type_friendly @title has been created', array( + '@content_type_friendly' => $content_type_friendly, + '@title' => $node_title, + ))); } - function testFormatterPlain() { + /** + * Test the link_plain formatter and it's output. + */ + public function testFormatterPlain() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); - $this->createNodeType($content_type_machine, $content_type_friendly); + $this->drupalCreateContentType(array( + 'type' => $content_type_machine, + 'name' => $content_type_friendly, + )); // Now add a singleton field. $single_field_name_friendly = $this->randomName(20); $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; + // $single_field_name = 'field_'. $single_field_name_machine;. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); + $this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display'); $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain', + 'fields[field_' . $single_field_name_machine . '][label]' => 'above', + 'fields[field_' . $single_field_name_machine . '][type]' => 'link_plain', + ); + $this->drupalPost(NULL, $edit, t('Save')); + + $this->createNodeTypeUser($content_type_machine); + + $link_tests = array( + 'plain' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/', + ), + 'query' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/?q=test', + ), + 'fragment' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/#test', + ), + ); + + foreach ($link_tests as $link_test) { + $link_text = $link_test['text']; + $link_url = $link_test['url']; + $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); + + $this->assertText($link_url); + $this->assertNoText($link_text); + $this->assertNoLinkByHref($link_url); + } + } + + /** + * Formatter Host. + */ + public function testFormatterHost() { + $content_type_friendly = $this->randomName(20); + $content_type_machine = strtolower($this->randomName(10)); + + $this->drupalCreateContentType(array( + 'type' => $content_type_machine, + 'name' => $content_type_friendly, + )); + + // Now add a singleton field. + $single_field_name_friendly = $this->randomName(20); + $single_field_name_machine = strtolower($this->randomName(10)); + // $single_field_name = 'field_'. $single_field_name_machine;. + $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); + + // Okay, now we want to make sure this display is changed: + $this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display'); + $edit = array( + 'fields[field_' . $single_field_name_machine . '][label]' => 'above', + 'fields[field_' . $single_field_name_machine . '][type]' => 'link_host', ); $this->drupalPost(NULL, $edit, t('Save')); @@ -271,90 +325,253 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $link_url = 'http://www.example.com/'; $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - $this->assertText($link_url); + $this->assertText('www.example.com'); $this->assertNoText($link_text); $this->assertNoLinkByHref($link_url); } - function testFormatterPlainWithQuerystring() { + /** + * Formatter URL. + * + * @codingStandardsIgnoreStart + */ + public function testFormatterURL() { + // @codingStandardsIgnoreEnd $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); - $this->createNodeType($content_type_machine, $content_type_friendly); + $this->drupalCreateContentType(array( + 'type' => $content_type_machine, + 'name' => $content_type_friendly, + )); // Now add a singleton field. $single_field_name_friendly = $this->randomName(20); $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; + // $single_field_name = 'field_'. $single_field_name_machine;. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); + $this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display'); $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain', + 'fields[field_' . $single_field_name_machine . '][label]' => 'above', + 'fields[field_' . $single_field_name_machine . '][type]' => 'link_url', ); $this->drupalPost(NULL, $edit, t('Save')); $this->createNodeTypeUser($content_type_machine); - $link_text = 'Display'; - $link_url = 'http://www.example.com/?q=test'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); + $link_tests = array( + 'plain' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/', + ), + 'query' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/?q=test', + ), + 'fragment' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/#test', + ), + ); - $this->assertText($link_url); - $this->assertNoText($link_text); - $this->assertNoLinkByHref($link_url); + foreach ($link_tests as $link_test) { + $link_text = $link_test['text']; + $link_url = $link_test['url']; + $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); + + $this->assertNoText($link_text); + $this->assertLinkByHref($link_url); + } } - function testFormatterPlainWithFragment() { + /** + * Formatter Short. + */ + public function testFormatterShort() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); - $this->createNodeType($content_type_machine, $content_type_friendly); + $this->drupalCreateContentType(array( + 'type' => $content_type_machine, + 'name' => $content_type_friendly, + )); // Now add a singleton field. $single_field_name_friendly = $this->randomName(20); $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; + // $single_field_name = 'field_'. $single_field_name_machine;. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); + $this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display'); $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain', + 'fields[field_' . $single_field_name_machine . '][label]' => 'above', + 'fields[field_' . $single_field_name_machine . '][type]' => 'link_short', ); $this->drupalPost(NULL, $edit, t('Save')); $this->createNodeTypeUser($content_type_machine); - $link_text = 'Display'; - $link_url = 'http://www.example.com/#test'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); + $link_tests = array( + 'plain' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/', + ), + 'query' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/?q=test', + ), + 'fragment' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/#test', + ), + ); - $this->assertText($link_url); - $this->assertNoText($link_text); - $this->assertNoLinkByHref($link_url); + foreach ($link_tests as $link_test) { + $link_text = $link_test['text']; + $link_url = $link_test['url']; + $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); + + $this->assertText('Link'); + $this->assertNoText($link_text); + $this->assertLinkByHref($link_url); + } } - function testFormatterURL() { + /** + * Formatter Label. + */ + public function testFormatterLabel() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10)); - $this->createNodeType($content_type_machine, $content_type_friendly); + $this->drupalCreateContentType(array( + 'type' => $content_type_machine, + 'name' => $content_type_friendly, + )); // Now add a singleton field. $single_field_name_friendly = $this->randomName(20); $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; + // $single_field_name = 'field_'. $single_field_name_machine;. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); + $this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display'); $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_url', + 'fields[field_' . $single_field_name_machine . '][label]' => 'above', + 'fields[field_' . $single_field_name_machine . '][type]' => 'link_label', + ); + $this->drupalPost(NULL, $edit, t('Save')); + + $this->createNodeTypeUser($content_type_machine); + + $link_tests = array( + 'plain' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/', + ), + 'query' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/?q=test', + ), + 'fragment' => array( + 'text' => 'Display', + 'url' => 'http://www.example.com/#test', + ), + ); + + foreach ($link_tests as $link_test) { + $link_text = $link_test['text']; + $link_url = $link_test['url']; + $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); + + $this->assertNoText($link_text); + $this->assertText($single_field_name_friendly); + $this->assertLinkByHref($link_url); + } + } + + /** + * Formatter Separate. + */ + public function testFormatterSeparate() { + $content_type_friendly = $this->randomName(20); + $content_type_machine = strtolower($this->randomName(10)); + + $this->drupalCreateContentType(array( + 'type' => $content_type_machine, + 'name' => $content_type_friendly, + )); + + // Now add a singleton field. + $single_field_name_friendly = $this->randomName(20); + $single_field_name_machine = strtolower($this->randomName(10)); + // $single_field_name = 'field_'. $single_field_name_machine;. + $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); + + // Okay, now we want to make sure this display is changed: + $this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display'); + $edit = array( + 'fields[field_' . $single_field_name_machine . '][label]' => 'above', + 'fields[field_' . $single_field_name_machine . '][type]' => 'link_separate', + ); + $this->drupalPost(NULL, $edit, t('Save')); + + $this->createNodeTypeUser($content_type_machine); + + $plain_url = 'http://www.example.com/'; + $link_tests = array( + 'plain' => array( + 'text' => $this->randomName(20), + 'url' => $plain_url, + ), + 'query' => array( + 'text' => $this->randomName(20), + 'url' => $plain_url . '?q=test', + ), + 'fragment' => array( + 'text' => $this->randomName(20), + 'url' => $plain_url . '#test', + ), + ); + + foreach ($link_tests as $link_test) { + $link_text = $link_test['text']; + $link_url = $link_test['url']; + $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); + + $this->assertText($link_text); + $this->assertLink($plain_url); + $this->assertLinkByHref($link_url); + } + } + + /** + * Formatter Plain Title. + */ + public function testFormatterPlainTitle() { + $content_type_friendly = $this->randomName(20); + $content_type_machine = strtolower($this->randomName(10)); + + $this->drupalCreateContentType(array( + 'type' => $content_type_machine, + 'name' => $content_type_friendly, + )); + + // Now add a singleton field. + $single_field_name_friendly = $this->randomName(20); + $single_field_name_machine = strtolower($this->randomName(10)); + // $single_field_name = 'field_'. $single_field_name_machine;. + $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); + + // Okay, now we want to make sure this display is changed: + $this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display'); + $edit = array( + 'fields[field_' . $single_field_name_machine . '][label]' => 'above', + 'fields[field_' . $single_field_name_machine . '][type]' => 'link_title_plain', ); $this->drupalPost(NULL, $edit, t('Save')); @@ -364,418 +581,9 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $link_url = 'http://www.example.com/'; $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - $this->assertNoText($link_text); - $this->assertLinkByHref($link_url); - } - - function testFormatterURLWithQuerystring() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_url', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = 'Display'; - $link_url = 'http://www.example.com/?q=test'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertNoText($link_text); - $this->assertLinkByHref($link_url); - } - - function testFormatterURLWithAnchor() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_url', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = 'Display'; - $link_url = 'http://www.example.com/#test'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertNoText($link_text); - $this->assertLinkByHref($link_url); - } - - function testFormatterShort() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_short', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = 'Display'; - $link_url = 'http://www.example.com/'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertText('Link'); - $this->assertNoText($link_text); - $this->assertLinkByHref($link_url); - } - - function testFormatterShortWithQuerystring() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_short', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = 'Display'; - $link_url = 'http://www.example.com/?q=test'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertText('Link'); - $this->assertNoText($link_text); - $this->assertLinkByHref($link_url); - } - - function testFormatterShortWithFragment() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_short', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = 'Display'; - $link_url = 'http://www.example.com/#test'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertText('Link'); - $this->assertNoText($link_text); - $this->assertLinkByHref($link_url); - } - - function testFormatterLabel() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_label', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = 'Display'; - $link_url = 'http://www.example.com/'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertNoText($link_text); - $this->assertText($single_field_name_friendly); - $this->assertLinkByHref($link_url); - } - - function testFormatterLabelWithQuerystring() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_label', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = 'Display'; - $link_url = 'http://www.example.com/?q=test'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertNoText($link_text); - $this->assertText($single_field_name_friendly); - $this->assertLinkByHref($link_url); - } - - function testFormatterLabelWithFragment() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_label', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = 'Display'; - $link_url = 'http://www.example.com/#test'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertNoText($link_text); - $this->assertText($single_field_name_friendly); - $this->assertLinkByHref($link_url); - } - - function testFormatterSeparate() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = $this->randomName(20); - $link_url = 'http://www.example.com/'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertText($link_text); - $this->assertLink($link_url); - $this->assertLinkByHref($link_url); - } - - function testFormatterSeparateWithQuerystring() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = $this->randomName(20); - $link_url = 'http://www.example.com/?q=test'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertText($link_text); - $this->assertLink('http://www.example.com/'); - $this->assertLinkByHref($link_url); - } - - function testFormatterSeparateWithFragment() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = $this->randomName(20); - $link_url = 'http://www.example.com/#test'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - - $this->assertText($link_text); - $this->assertLink('http://www.example.com/'); - $this->assertLinkByHref($link_url); - } - - function testFormatterPlainTitle() { - $content_type_friendly = $this->randomName(20); - $content_type_machine = strtolower($this->randomName(10)); - - $this->createNodeType($content_type_machine, $content_type_friendly); - - // Now add a singleton field. - $single_field_name_friendly = $this->randomName(20); - $single_field_name_machine = strtolower($this->randomName(10)); - //$single_field_name = 'field_'. $single_field_name_machine; - $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); - - // Okay, now we want to make sure this display is changed: - $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); - $edit = array( - 'fields[field_'. $single_field_name_machine .'][label]' => 'above', - 'fields[field_'. $single_field_name_machine .'][type]' => 'link_title_plain', - ); - $this->drupalPost(NULL, $edit, t('Save')); - - $this->createNodeTypeUser($content_type_machine); - - $link_text = 'Display'; - $link_url = 'http://www.example.com/'; - $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); - $this->assertText($link_text); $this->assertNoText($link_url); $this->assertNoLinkByHref($link_url); } - /** - * This test sees that we can create a link field with a defined class, and make sure - * that class displays properly when the link is displayed. - */ - /*function testLinkWithClassOnField() { - $this->acquireContentTypes(1); - $field_settings = array( - 'type' => 'link', - 'widget_type' => 'link', - 'type_name' => $this->content_types[0]->name, - 'attributes' => array( - 'class' => 'test-class', - 'target' => 'default', - 'rel' => FALSE, - ), - ); - - $field = $this->createField($field_settings, 0); - //$this->pass('
'. print_r($field, TRUE) .''); - $field_db_info = content_database_info($field); - - $this->acquireNodes(2); - - $node = node_load($this->nodes[0]->nid); - $node->promote = 1; // We want this to show on front page for the teaser test. - $node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link'); - node_save($node); - - // Does this display on the node page? - $this->drupalGet('node/'. $this->nodes[0]->nid); - //$this->outputScreenContents('Link field with class', 'link_'); - $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class')))); - - // Does this display on the front page? - $this->drupalGet('
'. print_r($instances, TRUE) .'', 'Debug'); - $instance = $instances['field_'. $name]; - //$this->assertTrue(1 === $instance['validate_url'], 'Make sure validation is on.'); + + $instance = $instances['field_' . $name]; $this->assertFalse($instance['required'], 'Make sure field is not required.'); $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.'); - $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be off by default.'); + $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.'); + $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.'); $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.'); $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"'); $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.'); $this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.'); $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); - - //$this->fail('
'. print_r($fields['field_'. $name], TRUE) .''); } + + /** + * CRUD Create Field With Class. + * + * If we're creating a new field and just hit 'save' on the default options, + * we want to make sure they are set to the expected results. + * + * @codingStandardsIgnoreStart + */ + public function testCRUDCreateFieldWithClass() { + // @codingStandardsIgnoreEnd + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'access content', + 'create page content', + )); + $this->drupalLogin($this->web_user); + + // Create field. + $name = strtolower($this->randomName()); + $edit = array( + 'fields[_add_new_field][label]' => $name, + 'fields[_add_new_field][field_name]' => $name, + 'fields[_add_new_field][type]' => 'link_field', + 'fields[_add_new_field][widget_type]' => 'link_field', + ); + $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save')); + + $this->drupalPost(NULL, array(), t('Save field settings')); + $link_class_name = 'basic-link-' . strtolower($this->randomName()); + $edit = array( + 'instance[settings][attributes][class]' => $link_class_name, + ); + $this->drupalPost(NULL, $edit, t('Save settings')); + + // Is field created? + $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added'); + node_types_rebuild(); + menu_rebuild(); + + _field_info_collate_fields(TRUE); + $instances = field_info_instances('node', 'page'); + + $instance = $instances['field_' . $name]; + $this->assertFalse($instance['required'], 'Make sure field is not required.'); + $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.'); + $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.'); + $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.'); + $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.'); + $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"'); + $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.'); + $this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'One class should be set.'); + $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); + + // Now, let's create a node with this field and make sure the link shows up: + // create page form. + $field_name = 'field_' . $name; + $this->drupalGet('node/add/page'); + $this->assertField($field_name . '[und][0][url]', 'URL found'); + + $input = array( + 'title' => 'This & That', + 'href' => 'http://www.example.com/', + ); + + $edit = array( + 'title' => $field_name, + $field_name . '[und][0][title]' => $input['title'], + $field_name . '[und][0][url]' => $input['href'], + ); + $this->drupalPost(NULL, $edit, t('Save')); + + $url = $this->getUrl(); + + // Change to anonymous user. + $this->drupalLogout(); + $this->drupalGet($url); + + $this->assertRaw('This & That'); + $this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Class $link_class_name exists on page."); + } + + /** + * CRUD Create Field With Two Classes. + * + * If we're creating a new field and just hit 'save' on the default options, + * we want to make sure they are set to the expected results. + * + * @codingStandardsIgnoreStart + */ + public function testCRUDCreateFieldWithTwoClasses() { + // @codingStandardsIgnoreEnd + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'access content', + 'create page content', + )); + $this->drupalLogin($this->web_user); + + // Create field. + $name = strtolower($this->randomName()); + $edit = array( + 'fields[_add_new_field][label]' => $name, + 'fields[_add_new_field][field_name]' => $name, + 'fields[_add_new_field][type]' => 'link_field', + 'fields[_add_new_field][widget_type]' => 'link_field', + ); + $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save')); + + $this->drupalPost(NULL, array(), t('Save field settings')); + $link_class_name = 'basic-link ' . strtoupper($this->randomName()); + $edit = array( + 'instance[settings][attributes][class]' => $link_class_name, + ); + $this->drupalPost(NULL, $edit, t('Save settings')); + + // Is field created? + $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added'); + node_types_rebuild(); + menu_rebuild(); + + _field_info_collate_fields(TRUE); + $instances = field_info_instances('node', 'page'); + + $instance = $instances['field_' . $name]; + $this->assertFalse($instance['required'], 'Make sure field is not required.'); + $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.'); + $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.'); + $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.'); + $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.'); + $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"'); + $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.'); + $this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'Two classes should be set.'); + $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); + + // Now, let's create a node with this field and make sure the link shows up: + // create page form. + $field_name = 'field_' . $name; + $this->drupalGet('node/add/page'); + $this->assertField($field_name . '[und][0][url]', 'URL found'); + + $input = array( + 'title' => 'This & That', + 'href' => 'http://www.example.com/', + ); + + $edit = array( + 'title' => $field_name, + $field_name . '[und][0][title]' => $input['title'], + $field_name . '[und][0][url]' => $input['href'], + ); + $this->drupalPost(NULL, $edit, t('Save')); + + $url = $this->getUrl(); + + // Change to anonymous user. + $this->drupalLogout(); + $this->drupalGet($url); + + $this->assertRaw('This & That'); + $this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Classes $link_class_name exist on page."); + } + } diff --git a/sites/all/modules/link/tests/link.entity_token.test b/sites/all/modules/link/tests/link.entity_token.test new file mode 100644 index 0000000..6c42655 --- /dev/null +++ b/sites/all/modules/link/tests/link.entity_token.test @@ -0,0 +1,164 @@ + 'Link entity tokens test', + 'description' => 'Tests that a link field appears properly in entity tokens', + 'group' => 'Link', + 'dependencies' => array('token', 'entity', 'entity_token'), + ); + } + + /** + * Setup. + */ + public function setUp($modules = array()) { + parent::setUp(array('token', 'entity', 'entity_token')); + } + + /** + * Creates a link field, fills it, then uses a loaded node to test tokens. + */ + public function testFieldTokenNodeLoaded() { + // Create field. + $settings = array( + 'instance[settings][enable_tokens]' => 0, + ); + $field_name = $this->createLinkField('page', + $settings); + + // Create page form. + $this->drupalGet('node/add/page'); + // $field_name = 'field_' . $name;. + $this->assertField($field_name . '[und][0][title]', 'Title found'); + $this->assertField($field_name . '[und][0][url]', 'URL found'); + + $token_url_tests = array( + 1 => array( + 'href' => 'http://example.com/' . $this->randomName(), + 'label' => $this->randomName(), + ), + 2 => array( + 'href' => 'http://example.com/' . $this->randomName() . '?property=value', + 'label' => $this->randomName(), + ), + 3 => array( + 'href' => 'http://example.com/' . $this->randomName() . '#position', + 'label' => $this->randomName(), + ), + 4 => array( + 'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2', + 'label' => $this->randomName(), + ), + ); + // @codingStandardsIgnoreLine + // $this->assert('pass', '
' . print_r($token_url_tests, TRUE) . '');. + foreach ($token_url_tests as &$input) { + $this->drupalGet('node/add/page'); + + $edit = array( + 'title' => $input['label'], + $field_name . '[und][0][title]' => $input['label'], + $field_name . '[und][0][url]' => $input['href'], + ); + $this->drupalPost(NULL, $edit, t('Save')); + $url = $this->getUrl(); + $input['url'] = $url; + } + + // Change to anonymous user. + $this->drupalLogout(); + + foreach ($token_url_tests as $index => $input2) { + $node = node_load($index); + $this->assertNotEqual(NULL, $node, "Do we have a node?"); + $this->assertEqual($node->nid, $index, "Test that we have a node."); + $token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]'; + $assert_data = token_replace($token_name, + array('node' => $node)); + $this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data); + } + } + + /** + * Field Token Node Viewed. + * + * Creates a link field, fills it, then uses a loaded and node_view'd node to + * test tokens. + */ + public function testFieldTokenNodeViewed() { + // Create field. + $settings = array( + 'instance[settings][enable_tokens]' => 0, + ); + $field_name = $this->createLinkField('page', + $settings); + + // Create page form. + $this->drupalGet('node/add/page'); + // $field_name = 'field_' . $name;. + $this->assertField($field_name . '[und][0][title]', 'Title found'); + $this->assertField($field_name . '[und][0][url]', 'URL found'); + + $token_url_tests = array( + 1 => array( + 'href' => 'http://example.com/' . $this->randomName(), + 'label' => $this->randomName(), + ), + 2 => array( + 'href' => 'http://example.com/' . $this->randomName() . '?property=value', + 'label' => $this->randomName(), + ), + 3 => array( + 'href' => 'http://example.com/' . $this->randomName() . '#position', + 'label' => $this->randomName(), + ), + 4 => array( + 'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2', + 'label' => $this->randomName(), + ), + ); + + //@codingStandardsIgnoreLine + // $this->assert('pass', '' . print_r($token_url_tests, TRUE) . '');. + foreach ($token_url_tests as &$input) { + $this->drupalGet('node/add/page'); + + $edit = array( + 'title' => $input['label'], + $field_name . '[und][0][title]' => $input['label'], + $field_name . '[und][0][url]' => $input['href'], + ); + $this->drupalPost(NULL, $edit, t('Save')); + $url = $this->getUrl(); + $input['url'] = $url; + } + + // Change to anonymous user. + $this->drupalLogout(); + + foreach ($token_url_tests as $index => $input2) { + $node = node_load($index); + $this->assertNotEqual(NULL, $node, "Do we have a node?"); + $this->assertEqual($node->nid, $index, "Test that we have a node."); + $token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]'; + $assert_data = token_replace($token_name, + array('node' => $node)); + $this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data); + } + } + +} diff --git a/sites/all/modules/link/tests/link.test b/sites/all/modules/link/tests/link.test index dfb4dda..dd9adb4 100644 --- a/sites/all/modules/link/tests/link.test +++ b/sites/all/modules/link/tests/link.test @@ -5,10 +5,15 @@ * Link base test file - contains common functions for testing links. */ +/** + * Base Test Class. + */ class LinkBaseTestClass extends DrupalWebTestCase { - public $permissions = array( + + protected $permissions = array( 'access content', 'administer content types', + 'administer fields', 'administer nodes', 'administer filters', 'access comments', @@ -17,21 +22,24 @@ class LinkBaseTestClass extends DrupalWebTestCase { 'create page content', ); - public $account; + /** + * Setup. + */ + public function setUp() { + $modules = func_get_args(); + $modules = (isset($modules[0]) && is_array($modules[0]) ? $modules[0] : $modules); + $modules[] = 'field_ui'; + $modules[] = 'link'; + parent::setUp($modules); - function setUp($modules = array()) { - if ($modules) { - parent::setUp($modules); - } - else { - parent::setUp('field_ui', 'link'); - } - $this->account = $this->drupalCreateUser($this->permissions); - $this->drupalLogin($this->account); + $this->web_user = $this->drupalCreateUser($this->permissions); + $this->drupalLogin($this->web_user); } - function createLinkField($node_type = 'page', - $settings = array()) { + /** + * Create Link Field. + */ + protected function createLinkField($node_type = 'page', $settings = array()) { $name = strtolower($this->randomName()); $edit = array( 'fields[_add_new_field][label]' => $name, @@ -39,8 +47,8 @@ class LinkBaseTestClass extends DrupalWebTestCase { 'fields[_add_new_field][type]' => 'link_field', 'fields[_add_new_field][widget_type]' => 'link_field', ); - $field_name = 'field_'. $name; - $this->drupalPost('admin/structure/types/manage/'. $node_type .'/fields', $edit, t('Save')); + $field_name = 'field_' . $name; + $this->drupalPost('admin/structure/types/manage/' . $node_type . '/fields', $edit, t('Save')); $this->drupalPost(NULL, array(), t('Save field settings')); $this->drupalPost(NULL, $settings, t('Save settings')); @@ -51,4 +59,5 @@ class LinkBaseTestClass extends DrupalWebTestCase { return $field_name; } + } diff --git a/sites/all/modules/link/tests/link.token.test b/sites/all/modules/link/tests/link.token.test index d23f46a..edbb1df 100644 --- a/sites/all/modules/link/tests/link.token.test +++ b/sites/all/modules/link/tests/link.token.test @@ -6,10 +6,13 @@ */ /** - * Testing that tokens can be used in link titles + * Testing that tokens can be used in link titles. */ class LinkTokenTest extends LinkBaseTestClass { + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link tokens - browser test', @@ -19,40 +22,38 @@ class LinkTokenTest extends LinkBaseTestClass { ); } - function setUp($modules = array()) { - $modules[] = 'field_ui'; - $modules[] = 'link'; - $modules[] = 'token'; - parent::setUp($modules); + /** + * Setup. + */ + public function setUp($modules = array()) { + parent::setUp(array('token')); } /** * Creates a link field with a required title enabled for user-entered tokens. + * * Creates a node with a token in the link title and checks the value. */ - function testUserTokenLinkCreate() { - /*$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); - $this->drupalLogin($account);*/ - - // create field + public function testUserTokenLinkCreate() { + // Create field. $settings = array( 'instance[settings][enable_tokens]' => 1, ); $field_name = $this->createLinkField('page', - $settings); + $settings); - // create page form + // Create page form. $this->drupalGet('node/add/page'); - //$field_name = 'field_' . $name; + // $field_name = 'field_' . $name;. $this->assertField($field_name . '[und][0][title]', 'Title found'); $this->assertField($field_name . '[und][0][url]', 'URL found'); $input = array( - 'href' => 'http://example.com/' . $this->randomName(), - 'label' => $this->randomName(), + 'href' => 'http://example.com/' . $this->randomName(), + 'label' => $this->randomName(), ); - //$this->drupalLogin($account); + // $this->drupalLogin($this->web_user);. $this->drupalGet('node/add/page'); $edit = array( @@ -63,36 +64,37 @@ class LinkTokenTest extends LinkBaseTestClass { $this->drupalPost(NULL, $edit, t('Save')); $url = $this->getUrl(); - // change to anonymous user + // Change to anonymous user. $this->drupalLogout(); $this->drupalGet($url); $this->assertRaw(l($input['label'] . ' page', $input['href'])); } - /** * Creates a link field with a static title and an admin-entered token. + * * Creates a node with a link and checks the title value. */ - function testStaticTokenLinkCreate() { + public function testStaticTokenLinkCreate() { - // create field + // Create field. $name = $this->randomName(); $settings = array( 'instance[settings][title]' => 'value', - 'instance[settings][title_value]' => $name .' [node:content-type:machine-name]'); + 'instance[settings][title_value]' => $name . ' [node:content-type:machine-name]', + ); $field_name = $this->createLinkField('page', $settings); - // create page form + // Create page form. $this->drupalGet('node/add/page'); $this->assertField($field_name . '[und][0][url]', 'URL found'); $input = array( - 'href' => 'http://example.com/' . $this->randomName() + 'href' => 'http://example.com/' . $this->randomName(), ); - //$this->drupalLogin($account); + // $this->drupalLogin($this->web_user);. $this->drupalGet('node/add/page'); $edit = array( @@ -103,7 +105,7 @@ class LinkTokenTest extends LinkBaseTestClass { $url = $this->getUrl(); - // change to anonymous user + // Change to anonymous user. $this->drupalLogout(); $this->drupalGet($url); @@ -112,30 +114,32 @@ class LinkTokenTest extends LinkBaseTestClass { /** * Creates a link field with a static title and an admin-entered token. + * * Creates a node with a link and checks the title value. * * Basically, I want to make sure the [title-raw] token works, because it's a * token that changes from node to node, where [type]'s always going to be the * same. */ - function testStaticTokenLinkCreate2() { + public function testStaticTokenLinkCreate2() { - // create field + // Create field. $name = $this->randomName(); $settings = array( 'instance[settings][title]' => 'value', - 'instance[settings][title_value]' => $name .' [node:title]'); + 'instance[settings][title_value]' => $name . ' [node:title]', + ); $field_name = $this->createLinkField('page', $settings); - // create page form + // Create page form. $this->drupalGet('node/add/page'); $this->assertField($field_name . '[und][0][url]', 'URL found'); $input = array( - 'href' => 'http://example.com/' . $this->randomName() + 'href' => 'http://example.com/' . $this->randomName(), ); - //$this->drupalLogin($account); + // $this->drupalLogin($this->web_user);. $this->drupalGet('node/add/page'); $edit = array( @@ -146,27 +150,32 @@ class LinkTokenTest extends LinkBaseTestClass { $url = $this->getUrl(); - // change to anonymous user + // Change to anonymous user. $this->drupalLogout(); $this->drupalGet($url); - $this->assertRaw(l($name .' '. $name, $input['href'])); + $this->assertRaw(l($name . ' ' . $name, $input['href'])); } - // This test doesn't seem to actually work, due to lack of 'title' in url. - function _test_Link_With_Title_Attribute_token_url_form() { - /* $this->loginWithPermissions($this->permissions); + /** + * This test doesn't seem to actually work, due to lack of 'title' in url. + * + * @codingStandardsIgnoreStart + */ + public function _test_Link_With_Title_Attribute_token_url_form() { + // @codingStandardsIgnoreEnd + /* $this->loginWithPermissions($this->permissions); $this->acquireContentTypes(1); $field_settings = array( - 'type' => 'link', - 'widget_type' => 'link', - 'type_name' => $this->content_types[0]->name, - 'attributes' => array( - 'class' => '', - 'target' => 'default', - 'rel' => 'nofollow', - 'title' => '', - ), + 'type' => 'link', + 'widget_type' => 'link', + 'type_name' => $this->content_types[0]->name, + 'attributes' => array( + 'class' => '', + 'target' => 'default', + 'rel' => 'nofollow', + 'title' => '', + ), ); $field = $this->createField($field_settings, 0); @@ -176,10 +185,10 @@ class LinkTokenTest extends LinkBaseTestClass { $url_type = str_replace('_', '-', $this->content_types[0]->type); $edit = array('attributes[title]' => '['. $field_name .'-url]', - 'enable_tokens' => TRUE); - + 'enable_tokens' => TRUE); + // @codingStandardsIgnoreLine $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'], - $edit, t('Save field settings')); + $edit, t('Save field settings')); $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));*/ $name = $this->randomName(); $settings = array( @@ -189,40 +198,42 @@ class LinkTokenTest extends LinkBaseTestClass { $field_name = $this->createLinkField('page', $settings); // So, having saved this field_name, let's see if it works... - //$this->acquireNodes(1); - - //$node = node_load($this->nodes[0]->nid); - - //$this->drupalGet('node/'. $this->nodes[0]->nid); - + // $this->acquireNodes(1); + // $node = node_load($this->nodes[0]->nid); + // $this->drupalGet('node/'. $this->nodes[0]->nid);. $edit = array(); $test_link_url = 'http://www.example.com/test'; - $edit[$field_name .'[und][0][url]'] = $test_link_url; - $title = 'title_'. $this->randomName(20); - $edit[$field_name .'[und][0][title]'] = $title; + $edit[$field_name . '[und][0][url]'] = $test_link_url; + $title = 'title_' . $this->randomName(20); + $edit[$field_name . '[und][0][title]'] = $title; $edit['title'] = $name; $this->drupalGet('node/add/page'); $this->drupalPost(NULL, $edit, t('Save')); // Make sure we get a new version! - //$node = node_load($this->nodes[0]->nid, NULL, TRUE); + // $node = node_load($this->nodes[0]->nid, NULL, TRUE);. $this->assertText(t('Basic page @title has been updated.', - array('@title' => $name))); + array('@title' => $name))); - //$this->drupalGet('node/'. $node->nid); + // $this->drupalGet('node/'. $node->nid);. $this->assertText($title, 'Make sure the link title/text shows'); - $this->assertRaw(' title="'. $test_link_url .'"', "Do we show the link url as the title attribute?"); - $this->assertNoRaw(' title="['. $field_name .'-url]"'); + $this->assertRaw(' title="' . $test_link_url . '"', "Do we show the link url as the title attribute?"); + $this->assertNoRaw(' title="[' . $field_name . '-url]"'); $this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.')); - //$this->fail($this->content); + // $this->fail($this->content);. } /** + * Link With Title Attribute token title form. + * * If the title of the link is set to the title attribute, then the title * attribute isn't supposed to show. + * + * @codingStandardsIgnoreStart */ - function _test_Link_With_Title_Attribute_token_title_form() { + public function _test_Link_With_Title_Attribute_token_title_form() { + // @codingStandardsIgnoreEnd $this->loginWithPermissions($this->permissions); $this->acquireContentTypes(1); $field_settings = array( @@ -239,51 +250,61 @@ class LinkTokenTest extends LinkBaseTestClass { $field = $this->createField($field_settings, 0); $field_name = $field['field_name']; - $field_db_info = content_database_info($field); $url_type = str_replace('_', '-', $this->content_types[0]->type); - $edit = array('attributes[title]' => '['. $field_name .'-title]', - 'enable_tokens' => TRUE); + $edit = array( + 'attributes[title]' => '[' . $field_name . '-title]', + 'enable_tokens' => TRUE, + ); - $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'], - $edit, t('Save field settings')); + $this->drupalPost('admin/content/node-type/' . $url_type . '/fields/' . $field['field_name'], + $edit, t('Save field settings')); $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name']))); // So, having saved this field_name, let's see if it works... $this->acquireNodes(1); - $node = node_load($this->nodes[0]->nid); - - $this->drupalGet('node/'. $this->nodes[0]->nid); + $this->drupalGet('node/' . $this->nodes[0]->nid); $edit = array(); - $edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test'; - $title = 'title_'. $this->randomName(20); - $edit[$field['field_name'] .'[0][title]'] = $title; + $edit[$field['field_name'] . '[0][url]'] = 'http://www.example.com/test'; + $title = 'title_' . $this->randomName(20); + $edit[$field['field_name'] . '[0][title]'] = $title; - $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save')); + $this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save')); // Make sure we get a new version! $node = node_load($this->nodes[0]->nid, NULL, TRUE); $this->assertText(t('@type @title has been updated.', - array('@title' => $node->title, - '@type' => $this->content_types[0]->name))); + array( + '@title' => $node->title, + '@type' => $this->content_types[0]->name, + ))); - $this->drupalGet('node/'. $node->nid); + $this->drupalGet('node/' . $node->nid); $this->assertText($title, 'Make sure the link title/text shows'); - $this->assertNoRaw(' title="'. $title .'"', "We should not show the link title as the title attribute?"); - $this->assertNoRaw(' title="['. $field_name .'-title]"'); - //$this->fail($this->content); + $this->assertNoRaw(' title="' . $title . '"', "We should not show the link title as the title attribute?"); + $this->assertNoRaw(' title="[' . $field_name . '-title]"'); + // $this->fail($this->content);. } /** - * Trying to set the url to contain a token. + * Trying to set the url to contain a token. + * + * @codingStandardsIgnoreStart */ - function _testUserTokenLinkCreateInURL() { - $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); - $this->drupalLogin($account); + public function _testUserTokenLinkCreateInURL() { + //@codingStandardsIgnoreEnd - // create field + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'access content', + 'create page content', + )); + $this->drupalLogin($this->web_user); + + // Create field. $name = strtolower($this->randomName()); $edit = array( '_add_new_field[label]' => $name, @@ -294,23 +315,24 @@ class LinkTokenTest extends LinkBaseTestClass { $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); $this->drupalPost(NULL, array( 'title' => 'required', - 'enable_tokens' => 1), t('Save field settings')); + 'enable_tokens' => 1, + ), t('Save field settings')); // Is field created? $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); - // create page form + // Create page form. $this->drupalGet('node/add/page'); $field_name = 'field_' . $name; $this->assertField($field_name . '[0][title]', 'Title found'); $this->assertField($field_name . '[0][url]', 'URL found'); $input = array( - 'href' => 'http://example.com/' . $this->randomName(), - 'label' => $this->randomName(), + 'href' => 'http://example.com/' . $this->randomName(), + 'label' => $this->randomName(), ); - $this->drupalLogin($account); + $this->drupalLogin($this->web_user); $this->drupalGet('node/add/page'); $edit = array( @@ -321,22 +343,31 @@ class LinkTokenTest extends LinkBaseTestClass { $this->drupalPost(NULL, $edit, t('Save')); $url = $this->getUrl(); - // change to anonymous user + // Change to anonymous user. $this->drupalLogout(); $this->drupalGet($url); - $this->assertRaw(l($input['label'], $input['href'] .'/page')); - //$this->fail($this->content); + $this->assertRaw(l($input['label'], $input['href'] . '/page')); + // $this->fail($this->content);. } /** - * Trying to set the url to contain a token. + * Trying to set the url to contain a token. + * + * @codingStandardsIgnoreStart */ - function _testUserTokenLinkCreateInURL2() { - $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); - $this->drupalLogin($account); + public function _testUserTokenLinkCreateInURL2() { + // @codingStandardsIgnoreEnd - // create field + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'access content', + 'create page content', + )); + $this->drupalLogin($this->web_user); + + // Create field. $name = strtolower($this->randomName()); $edit = array( '_add_new_field[label]' => $name, @@ -347,23 +378,24 @@ class LinkTokenTest extends LinkBaseTestClass { $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); $this->drupalPost(NULL, array( 'title' => 'required', - 'enable_tokens' => 1), t('Save field settings')); + 'enable_tokens' => 1, + ), t('Save field settings')); // Is field created? $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); - // create page form + // Create page form. $this->drupalGet('node/add/page'); $field_name = 'field_' . $name; $this->assertField($field_name . '[0][title]', 'Title found'); $this->assertField($field_name . '[0][url]', 'URL found'); $input = array( - 'href' => 'http://example.com/' . $this->randomName(), - 'label' => $this->randomName(), + 'href' => 'http://example.com/' . $this->randomName(), + 'label' => $this->randomName(), ); - $this->drupalLogin($account); + $this->drupalLogin($this->web_user); $this->drupalGet('node/add/page'); $edit = array( @@ -374,10 +406,75 @@ class LinkTokenTest extends LinkBaseTestClass { $this->drupalPost(NULL, $edit, t('Save')); $url = $this->getUrl(); - // change to anonymous user + // Change to anonymous user. $this->drupalLogout(); $this->drupalGet($url); - $this->assertRaw(l($input['label'], $input['href'] .'/'. $account->uid)); + $this->assertRaw(l($input['label'], $input['href'] . '/' . $this->web_user->uid)); } + + /** + * CRUD Title Only Title No Link. + * + * Test that if you have a title and no url on a field which does not have + * tokens enabled, that the title is sanitized once. + * + * @codingStandardsIgnoreStart + */ + public function testCRUDTitleOnlyTitleNoLink2() { + //@codingStandardsIgnoreEnd + + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'access content', + 'create page content', + )); + + $this->drupalLogin($this->web_user); + + // Create field. + $name = strtolower($this->randomName()); + $field_name = 'field_' . $name; + $edit = array( + 'fields[_add_new_field][label]' => $name, + 'fields[_add_new_field][field_name]' => $name, + 'fields[_add_new_field][type]' => 'link_field', + 'fields[_add_new_field][widget_type]' => 'link_field', + ); + $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save')); + $this->drupalPost(NULL, array(), t('Save field settings')); + $this->drupalPost(NULL, array( + 'instance[settings][url]' => 1, + 'instance[settings][enable_tokens]' => 0, + ), t('Save settings')); + + // Is field created? + $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added'); + + // Create page form. + $this->drupalGet('node/add/page'); + $this->assertField($field_name . '[und][0][url]', 'URL found'); + + $input = array( + 'title' => 'This & That', + 'href' => '', + ); + + $edit = array( + 'title' => $name, + $field_name . '[und][0][title]' => $input['title'], + $field_name . '[und][0][url]' => $input['href'], + ); + $this->drupalPost(NULL, $edit, t('Save')); + + $url = $this->getUrl(); + + // Change to anonymous user. + $this->drupalLogout(); + $this->drupalGet($url); + + $this->assertRaw('This & That'); + } + } diff --git a/sites/all/modules/link/tests/link.validate.test b/sites/all/modules/link/tests/link.validate.test index affa7e9..addd7d3 100644 --- a/sites/all/modules/link/tests/link.validate.test +++ b/sites/all/modules/link/tests/link.validate.test @@ -5,13 +5,15 @@ * Tests that exercise the validation functions in the link module. */ +/** + * Validate Test Case. + */ class LinkValidateTestCase extends LinkBaseTestClass { - function setUp($modules = array()) { - parent::setUp($modules); - } - - function createLink($url, $title, $attributes = array()) { + /** + * Create Link. + */ + protected function createLink($url, $title, $attributes = array()) { return array( 'url' => $url, 'title' => $title, @@ -21,35 +23,44 @@ class LinkValidateTestCase extends LinkBaseTestClass { /** * Takes a url, and sees if it can validate that the url is valid. + * + * @codingStandardsIgnoreStart */ - public function link_test_validate_url($url) { + protected function link_test_validate_url($url) { + // @codingStandardsIgnoreEnd $field_name = $this->createLinkField(); - $permission = 'create page content'; - $this->checkPermissions(array($permission), TRUE); - - $this->drupalGet('node/add/page'); - $label = $this->randomName(); - $edit = array( + $settings = array( 'title' => $label, - $field_name . '[und][0][title]' => $label, - $field_name . '[und][0][url]' => $url, + $field_name => array( + LANGUAGE_NONE => array( + array( + 'title' => $label, + 'url' => $url, + ), + ), + ), ); - $this->drupalPost(NULL, $edit, t('Save')); - $this->assertRaw(t(' has been created.'), 'Node created'); - $nid = 1; //$matches[1]; + $node = $this->drupalCreateNode($settings); - $node = node_load($nid); + $this->assertNotNull($node, ' has been created.', 'Node created'); - $this->assertEqual($url, $node->{$field_name}['und'][0]['url']); + $this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']); } + } +/** + * Class for Validate Test. + */ class LinkValidateTest extends LinkValidateTestCase { + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link Validation Tests', @@ -58,23 +69,35 @@ class LinkValidateTest extends LinkValidateTestCase { ); } - function test_link_validate_basic_url() { + /** + * Validate basic URL. + * + * @codingStandardsIgnoreStart + */ + public function test_link_validate_basic_url() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('http://www.example.com'); } /** * Test if we're stopped from posting a bad url on default validation. + * + * @codingStandardsIgnoreStart */ - function test_link_validate_bad_url_validate_default() { - $account = $this->drupalCreateUser(array('administer content types', - 'administer nodes', - 'administer filters', - 'access content', - 'create page content', - 'access administration pages')); - $this->drupalLogin($account); + public function test_link_validate_bad_url_validate_default() { + // @codingStandardsIgnoreEnd + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'administer nodes', + 'administer filters', + 'access content', + 'create page content', + 'access administration pages', + )); + $this->drupalLogin($this->web_user); - // create field + // Create field. $name = strtolower($this->randomName()); $edit = array( 'fields[_add_new_field][label]' => $name, @@ -91,35 +114,43 @@ class LinkValidateTest extends LinkValidateTestCase { node_types_rebuild(); menu_rebuild(); - // create page form + // Create page form. $this->drupalGet('node/add/page'); $field_name = 'field_' . $name; - $this->assertField('edit-field-'. $name .'-und-0-title', 'Title found'); - $this->assertField('edit-field-'. $name .'-und-0-url', 'URL found'); - + $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found'); + $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found'); $edit = array( 'title' => 'Simple Title', - $field_name .'[und][0][url]' => 'edik:naw', + $field_name . '[und][0][url]' => 'edik:naw', ); $this->drupalPost(NULL, $edit, t('Save')); - $this->assertText(t('Not a valid URL.')); + $this->assertText(t('The value @value provided for @field is not a valid URL.', array( + '@value' => 'edik:naw', + '@field' => $name, + ))); } /** * Test if we're stopped from posting a bad url with validation on. + * + * @codingStandardsIgnoreStart */ - function test_link_validate_bad_url_validate_on() { - $account = $this->drupalCreateUser(array('administer content types', - 'administer nodes', - 'administer filters', - 'access content', - 'create page content', - 'access administration pages')); - $this->drupalLogin($account); + public function test_link_validate_bad_url_validate_on() { + // @codingStandardsIgnoreEnd + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'administer nodes', + 'administer filters', + 'access content', + 'create page content', + 'access administration pages', + )); + $this->drupalLogin($this->web_user); - // create field + // Create field. $name = strtolower($this->randomName()); $edit = array( 'fields[_add_new_field][label]' => $name, @@ -136,36 +167,44 @@ class LinkValidateTest extends LinkValidateTestCase { node_types_rebuild(); menu_rebuild(); - // create page form + // Create page form. $this->drupalGet('node/add/page'); $field_name = 'field_' . $name; - $this->assertField('edit-field-'. $name .'-und-0-title', 'Title found'); - $this->assertField('edit-field-'. $name .'-und-0-url', 'URL found'); - + $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found'); + $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found'); $edit = array( 'title' => 'Simple Title', - $field_name .'[und][0][url]' => 'edik:naw', + $field_name . '[und][0][url]' => 'edik:naw', ); $this->drupalPost(NULL, $edit, t('Save')); - $this->assertText(t('Not a valid URL.')); + $this->assertText(t('The value @value provided for @field is not a valid URL.', array( + '@field' => $name, + '@value' => 'edik:naw', + ))); } /** * Test if we can post a bad url if the validation is expressly turned off. + * + * @codingStandardsIgnoreStart */ - function test_link_validate_bad_url_validate_off() { - $account = $this->drupalCreateUser(array('administer content types', - 'administer nodes', - 'administer filters', - 'access content', - 'create page content', - 'access administration pages')); - $this->drupalLogin($account); + public function test_link_validate_bad_url_validate_off() { + // @codingStandardsIgnoreEnd + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'administer nodes', + 'administer filters', + 'access content', + 'create page content', + 'access administration pages', + )); + $this->drupalLogin($this->web_user); - // create field + // Create field. $name = strtolower($this->randomName()); $edit = array( 'fields[_add_new_field][label]' => $name, @@ -177,6 +216,7 @@ class LinkValidateTest extends LinkValidateTestCase { $this->drupalPost(NULL, array(), t('Save field settings')); $this->drupalPost(NULL, array('instance[settings][validate_url]' => FALSE), t('Save settings')); + // @codingStandardsIgnoreLine /*$instance_details = db_query("SELECT * FROM {field_config_instance} WHERE field_name = :field_name AND bundle = 'page'", array(':field_name' => 'field_'. $name))->fetchObject(); $this->fail(''. print_r($instance_details, TRUE) .''); $this->fail(''. print_r(unserialize($instance_details->data), TRUE) .'');*/ @@ -186,113 +226,167 @@ class LinkValidateTest extends LinkValidateTestCase { node_types_rebuild(); menu_rebuild(); - // create page form + // Create page form. $this->drupalGet('node/add/page'); $field_name = 'field_' . $name; - $this->assertField('edit-field-'. $name .'-und-0-title', 'Title found'); - $this->assertField('edit-field-'. $name .'-und-0-url', 'URL found'); - + $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found'); + $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found'); $edit = array( 'title' => 'Simple Title', - $field_name .'[und][0][url]' => 'edik:naw', + $field_name . '[und][0][url]' => 'edik:naw', ); $this->drupalPost(NULL, $edit, t('Save')); - $this->assertNoText(t('Not a valid URL.')); - + $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array( + '%field' => $name, + '%value' => 'edik:naw', + ))); } /** - * Test if a bad url can sneak through un-filtered if we play with the validation... + * Validate switching between validation status. + * + * Test if a bad url can sneak through un-filtered if we play with the + * validation... + * + * @codingStandardsIgnoreStart */ - function x_test_link_validate_switching_between_validation_status() { + public function x_test_link_validate_switching_between_validation_status() { + // @codingStandardsIgnoreEnd $this->acquireContentTypes(1); - $account = $this->drupalCreateUser(array('administer content types', - 'administer nodes', - 'access administration pages', - 'access content', - 'create '. $this->content_types[0]->type .' content', - 'edit any '. $this->content_types[0]->type .' content')); - $this->drupalLogin($account); - variable_set('node_options_'. $this->content_types[0]->name, array('status', 'promote')); + $this->web_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer fields', + 'administer nodes', + 'access administration pages', + 'access content', + 'create ' . $this->content_types[0]->type . ' content', + 'edit any ' . $this->content_types[0]->type . ' content', + )); + $this->drupalLogin($this->web_user); + variable_set('node_options_' . $this->content_types[0]->name, array( + 'status', + 'promote', + )); $field_settings = array( 'type' => 'link', 'widget_type' => 'link', 'type_name' => $this->content_types[0]->name, - 'attributes' => array(), // <-- This is needed or we have an error + // <-- This is needed or we have an error. + 'attributes' => array(), 'validate_url' => 0, ); $field = $this->createField($field_settings, 0); - //$this->fail(''. print_r($field, TRUE) .''); - $field_db_info = content_database_info($field); $this->acquireNodes(2); - $node = node_load($this->nodes[0]->nid); - - $this->drupalGet('node/'. $this->nodes[0]->nid); + $this->drupalGet('node/' . $this->nodes[0]->nid); $edit = array(); $title = $this->randomName(); $url = 'javascript:alert("http://example.com/' . $this->randomName() . '")'; - $edit[$field['field_name'] .'[0][url]'] = $url; - $edit[$field['field_name'] .'[0][title]'] = $title; + $edit[$field['field_name'] . '[0][url]'] = $url; + $edit[$field['field_name'] . '[0][title]'] = $title; - $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save')); - //$this->pass($this->content); - $this->assertNoText(t('Not a valid URL.')); + $this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save')); + // $this->pass($this->content);. + // @codingStandardsIgnoreLine + $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array( + '%field' => $name, + '%value' => trim($url), + ))); // Make sure we get a new version! $node = node_load($this->nodes[0]->nid, NULL, TRUE); $this->assertEqual($url, $node->{$field['field_name']}[0]['url']); - $this->drupalGet('node/'. $node->nid); + $this->drupalGet('node/' . $node->nid); $this->assertNoRaw($url, 'Make sure Javascript does not display.'); // Turn the array validation back _on_. $edit = array('validate_url' => TRUE); $node_type_link = str_replace('_', '-', $node->type); - //$this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']); - //$this->fail($this->content); - $this->drupalPost('admin/content/node-type/'. $node_type_link .'/fields/'. $field['field_name'], $edit, t('Save field settings')); + // @codingStandardsIgnoreLine + // $this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']); + // $this->fail($this->content);. + $this->drupalPost('admin/content/node-type/' . $node_type_link . '/fields/' . $field['field_name'], $edit, t('Save field settings')); - $this->drupalGet('node/'. $node->nid); + $this->drupalGet('node/' . $node->nid); // This actually works because the display_url goes through the core // url() function. But we should have a test that makes sure it continues // to work. $this->assertNoRaw($url, 'Make sure Javascript does not display.'); - //$this->fail($this->content); - + // $this->fail($this->content);. } - // Validate that '' is a valid url. - function test_link_front_url() { + /** + * Validate that ' ' is a valid url. + * + * @codingStandardsIgnoreStart + */ + public function test_link_front_url() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url(' '); } - // Validate that an internal url would be accepted. - function test_link_internal_url() { - $this->link_test_validate_url('node/32'); + /** + * Validate that an internal url would be accepted. + * + * @codingStandardsIgnoreStart + */ + public function test_link_internal_url() { + // @codingStandardsIgnoreEnd + // Create the content first. + $node = $this->drupalCreateNode(); + + $link = 'node/' . $node->nid; + $this->link_test_validate_url($link); + $type = link_url_type($link); + $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.'); } - // Validate a simple mailto. - function test_link_mailto() { + /** + * Validate a simple mailto. + * + * @codingStandardsIgnoreStart + */ + public function test_link_mailto() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('mailto:jcfiala@gmail.com'); } - function test_link_external_https() { + /** + * Check link external https. + * + * @codingStandardsIgnoreStart + */ + public function test_link_external_https() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('https://www.example.com/'); } - function test_link_ftp() { + /** + * Check link FTP. + * + * @codingStandardsIgnoreStart + */ + public function test_link_ftp() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('ftp://www.example.com/'); } + } +/** + * Validate Test News. + */ class LinkValidateTestNews extends LinkValidateTestCase { + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link News Validation Tests', @@ -301,18 +395,36 @@ class LinkValidateTestNews extends LinkValidateTestCase { ); } - // Validate a news link to a message group - function test_link_news() { + /** + * Validate a news link to a message group. + * + * @codingStandardsIgnoreStart + */ + public function test_link_news() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('news:comp.infosystems.www.misc'); } - // Validate a news link to a message id. Said ID copied off of google groups. - function test_link_news_message() { + /** + * Validate a news link to a message id. Said ID copied off of google groups. + * + * @codingStandardsIgnoreStart + */ + public function test_link_news_message() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('news:hj0db8$vrm$1@news.eternal-september.org'); } + } +/** + * Validate Specific URL. + */ class LinkValidateSpecificURL extends LinkValidateTestCase { + + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link Specific URL Validation Tests', @@ -321,33 +433,65 @@ class LinkValidateSpecificURL extends LinkValidateTestCase { ); } - // Lets throw in a lot of umlouts for testing! - function test_umlout_url() { + /** + * Lets throw in a lot of umlouts for testing! + * + * @codingStandardsIgnoreStart + */ + public function test_umlout_url() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('http://üÜü.exämple.com/nöde'); } - function test_umlout_mailto() { + /** + * Check umlout mailto. + * + * @codingStandardsIgnoreStart + */ + public function test_umlout_mailto() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('mailto:Üser@exÅmple.com'); } - function test_german_b_url() { + /** + * Check german b in url. + * + * @codingStandardsIgnoreStart + */ + public function test_german_b_url() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('http://www.test.com/ßstuff'); } - function test_special_n_url() { + /** + * Check Special in url. + * + * @codingStandardsIgnoreStart + */ + public function test_special_n_url() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('http://www.testÑñ.com/'); } - function test_curly_brackets_in_query() { + /** + * Curly Brackets in query. + * + * @codingStandardsIgnoreStart + */ + public function test_curly_brackets_in_query() { + // @codingStandardsIgnoreEnd $this->link_test_validate_url('http://www.healthyteennetwork.org/index.asp?Type=B_PR&SEC={2AE1D600-4FC6-4B4D-8822-F1D5F072ED7B}&DE={235FD1E7-208D-4363-9854-4E6775EB8A4C}'); } /** * Here, we're testing that a very long url is stored properly in the db. * - * Basicly, trying to test http://drupal.org/node/376818 + * Basically, trying to test http://drupal.org/node/376818 + * + * @codingStandardsIgnoreStart */ - function testLinkURLFieldIsBig() { + public function testLinkURLFieldIsBig() { + // @codingStandardsIgnoreEnd $long_url = 'http://th.wikipedia.org/wiki/%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%8D%E0%B8%88%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%B9%E0%B8%97%E0%B8%B4%E0%B8%A8_%E0%B8%99%E0%B8%84%E0%B8%A3%E0%B8%A8%E0%B8%A3%E0%B8%B5%E0%B8%98%E0%B8%A3%E0%B8%A3%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A'; $this->link_test_validate_url($long_url); } @@ -355,17 +499,18 @@ class LinkValidateSpecificURL extends LinkValidateTestCase { } /** - * A series of tests of links, only going against the link_validate_url function in link.module. + * Validate Url Light. + * + * A series of tests of links, only going against the link_validate_url function + * in link.module. * * Validation is guided by the rules in http://tools.ietf.org/html/rfc1738 ! */ class LinkValidateUrlLight extends DrupalWebTestCase { - //function setUp() { - // do we need to include something here? - //module_load_include('inc', 'link'); - //} - + /** + * Get Info. + */ public static function getInfo() { return array( 'name' => 'Link Light Validation Tests', @@ -375,74 +520,117 @@ class LinkValidateUrlLight extends DrupalWebTestCase { } /** - * Translates the LINK type constants to english for display and debugging of tests + * Setup. */ - function name_Link_Type($type) { + public function setUp() { + parent::setUp('link'); + } + + /** + * Name Link Type. + * + * Translates the LINK type constants to english for display and debugging of + * tests. + * + * @codingStandardsIgnoreStart + */ + public function name_Link_Type($type) { + // @codingStandardsIgnoreEnd switch ($type) { case LINK_FRONT: return "Front"; + case LINK_EMAIL: return "Email"; + case LINK_NEWS: return "Newsgroup"; + case LINK_INTERNAL: return "Internal Link"; + case LINK_EXTERNAL: return "External Link"; + case FALSE: return "Invalid Link"; + default: - return "Bad Value:". $type; + return "Bad Value:" . $type; } } - // Make sure that a link labelled works. - function testValidateFrontLink() { + /** + * Make sure that a link labeled works. + */ + public function testValidateFrontLink() { $valid = link_validate_url(' '); - $this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verfied and identified'); + $this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verified and identified'); } - function testValidateEmailLink() { + /** + * Validate Email Link. + */ + public function testValidateEmailLink() { $valid = link_validate_url('mailto:bob@example.com'); $this->assertEqual(LINK_EMAIL, $valid, "Make sure a basic mailto is verified and identified"); } - function testValidateEmailLinkBad() { + /** + * Validate Email Link Bad. + */ + public function testValidateEmailLinkBad() { $valid = link_validate_url(':bob@example.com'); $this->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed'); } - function testValidateNewsgroupLink() { + /** + * Validate Newsgroup Link. + */ + public function testValidateNewsgroupLink() { $valid = link_validate_url('news:comp.infosystems.www.misc'); $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to newsgroup validates as news.'); } - function testValidateNewsArticleLink() { + /** + * Validate News Article Link. + */ + public function testValidateNewsArticleLink() { $valid = link_validate_url('news:hj0db8$vrm$1@news.eternal-september.org'); - $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article valiates as news.'); + $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article validates as news.'); } - function testValidateBadNewsgroupLink() { + /** + * Validate Bad Newsgroup Link. + */ + public function testValidateBadNewsgroupLink() { $valid = link_validate_url('news:comp.bad_name.misc'); $this->assertEqual(FALSE, $valid, 'newsgroup names can\'t contain underscores, so it should come back as invalid.'); } - function testValidateInternalLink() { - $valid = link_validate_url('node/5'); - $this->assertEqual(LINK_INTERNAL, $valid, 'Test normal internal link.'); + /** + * Validate Internal Links. + */ + public function testValidateInternalLinks() { + $tempfile = drupal_tempnam('public://files', 'test'); + $links = array( + 'rss.xml', + file_uri_target($tempfile), + drupal_realpath($tempfile), + ); + + foreach ($links as $link) { + $type = link_url_type($link); + $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.'); + $valid = link_validate_url($link); + $this->assertTrue($valid, 'Test ' . $link . ' is valid internal link.'); + } } - function testValidateInternalLinkWithDot() { - $valid = link_validate_url('rss.xml'); - $this->assertEqual(LINK_INTERNAL, $valid, 'Test rss.xml internal link.'); - } - - function testValidateInternalLinkToFile() { - $valid = link_validate_url('files/test.jpg'); - $this->assertEqual(LINK_INTERNAL, $valid, 'Test files/test.jpg internal link.'); - } - - function testValidateExternalLinks() { + /** + * Validate External Links. + */ + public function testValidateExternalLinks() { $links = array( 'http://localhost:8080/', 'www.example.com', @@ -457,9 +645,8 @@ class LinkValidateUrlLight extends DrupalWebTestCase { 'http://255.255.255.255:4823/', 'www.test-site.com', 'http://example.com/index.php?q=node/123', - 'http://example.com/index.php?page=this\that', 'http://example.com/?first_name=Joe Bob&last_name=Smith', - // Anchors + // Anchors. 'http://www.example.com/index.php#test', 'http://www.example.com/index.php#this@that.', 'http://www.example.com/index.php#', @@ -467,34 +654,60 @@ class LinkValidateUrlLight extends DrupalWebTestCase { 'http://www.archive.org/stream/aesopsfables00aesorich#page/n7/mode/2up', 'http://www.example.com/blah/#this@that?', ); + // Test all of the protocols. - $allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal')); + $allowed_protocols = variable_get('filter_allowed_protocols', array( + 'http', + 'https', + 'ftp', + 'news', + 'nntp', + 'telnet', + 'mailto', + 'irc', + 'ssh', + 'sftp', + 'webcal', + )); + foreach ($allowed_protocols as $protocol) { if ($protocol !== 'news' && $protocol !== 'mailto') { - $links[] = $protocol .'://www.example.com'; + $links[] = $protocol . '://www.example.com'; } } foreach ($links as $link) { + $type = link_url_type($link); + $this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.'); $valid = link_validate_url($link); - $this->assertEqual(LINK_EXTERNAL, $valid, 'Testing that '. $link .' is a valid external link.'); - // The following two lines are commented out and only used for comparisons. - //$valid2 = valid_url($link, TRUE); - //$this->assertEqual(TRUE, $valid2, "Using valid_url() on $link."); + $this->assertTrue($valid, 'Test ' . $link . ' is valid external link.'); + // The following two lines are commented out and only used for + // comparisons. + // $valid2 = valid_url($link, TRUE); + // $this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");. } } - function testInvalidExternalLinks() { + /** + * Check Invalid External Links. + */ + public function testInvalidExternalLinks() { $links = array( 'http://www.ex ample.com/', - '//www.example.com/', - 'http://25.0.0/', // bad ip! + // Bad ip! + 'http://25.0.0/', 'http://4827.0.0.2/', - 'http://www.testß.com/', // ß not allowed in domain names! - //'http://www.-fudge.com/', // domains can't have sections starting with a dash. + // ß not allowed in domain names! + 'http://www.testß.com/', + // Bad TLD. + 'http://.www.foo.bar./', + // Domains can't have sections starting with a dash. + // 'http://www.-fudge.com/', + 'http://example.com/index.php?page=this\that', + 'example@example.com', ); foreach ($links as $link) { $valid = link_validate_url($link); - $this->assertEqual(FALSE, $valid, 'Testing that '. $link .' is not a valid link.'); + $this->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.'); } } diff --git a/sites/all/modules/link/views/link.views.inc b/sites/all/modules/link/views/link.views.inc index 27d5182..8c080ad 100644 --- a/sites/all/modules/link/views/link.views.inc +++ b/sites/all/modules/link/views/link.views.inc @@ -1,4 +1,7 @@ default_actions(); $form['title'] = array( @@ -52,7 +58,7 @@ class link_views_handler_argument_target extends views_handler_argument { $form['wildcard'] = array( '#prefix' => ' ', - // prefix and no suffix means these two items will be grouped together. + // Prefix and no suffix means these two items will be grouped together. '#type' => 'textfield', '#title' => t('Wildcard'), '#size' => 20, @@ -93,7 +99,7 @@ class link_views_handler_argument_target extends views_handler_argument { '#default_value' => $this->options['validate_type'], ); - $validate_types = array('none' => t('', ); - $form['#theme'] = 'module_filter_system_modules'; + if (variable_get('module_filter_tabs', 1)) { + $form['module_filter']['#attached']['css'][] = drupal_get_path('module', 'module_filter') . '/css/module_filter_tab.css'; + $form['module_filter']['#attached']['library'][] = array('system', 'jquery.bbq'); + $form['module_filter']['#attached']['js'][drupal_get_path('module', 'module_filter') . '/js/module_filter_tab.js'] = array('weight' => 2); + + if (!module_exists('page_actions') && variable_get('module_filter_dynamic_save_position', 1)) { + $form['module_filter']['#attached']['css'][] = drupal_get_path('module', 'module_filter') . '/css/dynamic_position.css'; + $form['module_filter']['#attached']['js'][drupal_get_path('module', 'module_filter') . '/js/dynamic_position.js'] = array('weight' => 3); + } + + $form['#attached']['css'][] = drupal_get_path('module', 'module_filter') . '/css/modules.css'; + + $form['#theme'] = 'module_filter_system_modules_tabs'; + } + $form['#submit'][] = 'module_filter_system_modules_submit_redirect'; if (variable_get('module_filter_track_recent_modules', 1)) { @@ -114,7 +128,7 @@ function module_filter_element_info() { '#process' => array('form_process_module_filter', 'ajax_process_form'), '#weight' => -1, '#tree' => TRUE, - '#theme' => 'module_filter' + '#theme' => 'module_filter', ); return $types; } @@ -128,10 +142,6 @@ function module_filter_theme() { 'render element' => 'element', 'file' => 'module_filter.theme.inc', ), - 'module_filter_system_modules' => array( - 'render element' => 'form', - 'file' => 'module_filter.theme.inc', - ), 'module_filter_system_modules_tabs' => array( 'render element' => 'form', 'file' => 'module_filter.theme.inc', @@ -143,6 +153,18 @@ function module_filter_theme() { ); } +/** + * Create and add new textfield element. + * + * @param $element + * An associative array containing the properties and children of the + * form actions container. + * @param $form_state + * The $form_state array for the form this element belongs to. + * + * @return + * The processed element. + */ function form_process_module_filter($element, &$form_state) { $element['name'] = array( '#type' => 'textfield', @@ -153,9 +175,10 @@ function form_process_module_filter($element, &$form_state) { '#attributes' => ((isset($element['#attributes'])) ? $element['#attributes'] : array()) + array('autocomplete' => 'off'), '#attached' => array( 'css' => array( - drupal_get_path('module', 'module_filter') . '/css/module_filter.css' + drupal_get_path('module', 'module_filter') . '/css/module_filter.css', ), 'js' => array( + 'misc/jquery.cookie.js', drupal_get_path('module', 'module_filter') . '/js/module_filter.js', array( 'data' => array( @@ -169,32 +192,34 @@ function form_process_module_filter($element, &$form_state) { 'useURLFragment' => variable_get('module_filter_use_url_fragment', 1), 'useSwitch' => variable_get('module_filter_use_switch', 1), 'trackRecent' => variable_get('module_filter_track_recent_modules', 1), + 'rememberActiveTab' => variable_get('module_filter_remember_active_tab', 1), 'rememberUpdateState' => variable_get('module_filter_remember_update_state', 0), - ) + 'expandedDescription' => variable_get('module_filter_expanded_description', 0), + ), ), - 'type' => 'setting' - ) - ) - ) + 'type' => 'setting', + ), + ), + ), ); if (isset($element['#description'])) { $element['name']['#description'] = $element['#description']; } - if (variable_get('module_filter_remember_update_state', 0)) { - $element['name']['#attached']['js'][] = 'misc/jquery.cookie.js'; - } return $element; } +/** + * Form submission handler to filters module list. + */ function module_filter_system_modules_submit_redirect($form, &$form_state) { $query = array(); if (!empty($form_state['values']['module_filter']['name'])) { $query['filter'] = $form_state['values']['module_filter']['name']; } - $query['enabled'] = (int)(!empty($form_state['values']['module_filter']['show']['enabled'])); - $query['disabled'] = (int)(!empty($form_state['values']['module_filter']['show']['disabled'])); - $query['required'] = (int)(!empty($form_state['values']['module_filter']['show']['required'])); - $query['unavailable'] = (int)(!empty($form_state['values']['module_filter']['show']['unavailable'])); + $query['enabled'] = (int) (!empty($form_state['values']['module_filter']['show']['enabled'])); + $query['disabled'] = (int) (!empty($form_state['values']['module_filter']['show']['disabled'])); + $query['required'] = (int) (!empty($form_state['values']['module_filter']['show']['required'])); + $query['unavailable'] = (int) (!empty($form_state['values']['module_filter']['show']['unavailable'])); $form_state['redirect'] = array( 'admin/modules', @@ -202,6 +227,9 @@ function module_filter_system_modules_submit_redirect($form, &$form_state) { ); } +/** + * Form submission handler to track recently enabled/disabled modules + */ function module_filter_system_modules_submit_recent($form, &$form_state) { $recent_modules = variable_get('module_filter_recent_modules', array()); @@ -216,6 +244,11 @@ function module_filter_system_modules_submit_recent($form, &$form_state) { variable_set('module_filter_recent_modules', $recent_modules); } +/** + * Create list of newly added modules (within a week) + * @return + * An array of newly added modules. + */ function module_filter_new_modules() { // Get current list of modules. $files = system_rebuild_module_data(); @@ -240,12 +273,24 @@ function module_filter_new_modules() { return $new_modules; } +/** + * Function to replace special characters with hyphen. + * @param string $text + * @return + * String + */ function module_filter_get_id($text) { $id = strtolower($text); $id = preg_replace('/([^a-z0-9]+)/', '-', $id); return trim($id, '-'); } +/** + * Function to return true/false depending on module changed time and a week timestamp + * @param integer $var + * @return + * Boolean indicating + */ function module_filter_recent_filter($var) { - return (!($var < REQUEST_TIME - 60*60*24*7)); + return (!($var < REQUEST_TIME - 60 * 60 * 24 * 7)); } diff --git a/sites/all/modules/module_filter/module_filter.pages.inc b/sites/all/modules/module_filter/module_filter.pages.inc index a4c2349..a18fbc5 100644 --- a/sites/all/modules/module_filter/module_filter.pages.inc +++ b/sites/all/modules/module_filter/module_filter.pages.inc @@ -1,5 +1,9 @@ drupal_get_form('module_filter_update_status_form'), 'update_report' => array( - '#markup' => $update_report - ) + '#markup' => $update_report, + ), ); } +/** + * Form builder for the module filter form. + */ function module_filter_update_status_form($form, &$form_state) { $form['module_filter'] = array( '#type' => 'module_filter', '#attached' => array( 'css' => array( - drupal_get_path('module', 'module_filter') . '/css/update_status.css' + drupal_get_path('module', 'module_filter') . '/css/update_status.css', ), 'js' => array( - drupal_get_path('module', 'module_filter') . '/js/update_status.js' + drupal_get_path('module', 'module_filter') . '/js/update_status.js', ), ), ); @@ -34,7 +41,7 @@ function module_filter_update_status_form($form, &$form_state) { '#default_value' => (isset($_GET['show']) && in_array($_GET['show'], array('all', 'updates', 'security', 'unknown'))) ? $_GET['show'] : 'all', '#options' => array('all' => t('All'), 'updates' => t('Update available'), 'security' => t('Security update'), 'unknown' => t('Unknown')), '#prefix' => '')); + $validate_types = array('none' => t('- Basic validation -')); $plugins = views_fetch_plugin_data('argument validator'); foreach ($plugins as $id => $info) { $valid = TRUE; @@ -125,8 +131,8 @@ class link_views_handler_argument_target extends views_handler_argument { asort($validate_types); $form['validate_type']['#options'] = $validate_types; - // Show this gadget if *anything* but 'none' is selected + // Show this gadget if *anything* but 'none' is selected. $form['validate_fail'] = array( '#type' => 'select', '#title' => t('Action to take if argument does not validate'), @@ -140,10 +146,11 @@ class link_views_handler_argument_target extends views_handler_argument { * * The argument sent may be found at $this->argument. */ - function query() { + public function query($group_by = FALSE) { $this->ensure_my_table(); // Because attributes are stored serialized, our only option is to also // serialize the data we're searching for and use LIKE to find similar data. - $this->query->add_where(0, $this->table_alias .'.'. $this->real_field ." LIKE '%%%s%'", serialize(array('target' => $this->argument))); + $this->query->add_where(0, $this->table_alias . ' . ' . $this->real_field . " LIKE '%%%s%'", serialize(array('target' => $this->argument))); } + } diff --git a/sites/all/modules/link/views/link_views_handler_filter_protocol.inc b/sites/all/modules/link/views/link_views_handler_filter_protocol.inc index f43e345..ae00c17 100644 --- a/sites/all/modules/link/views/link_views_handler_filter_protocol.inc +++ b/sites/all/modules/link/views/link_views_handler_filter_protocol.inc @@ -7,22 +7,30 @@ /** * Filter handler for limiting a view to URLs of a certain protocol. + * + * @codingStandardsIgnoreStart */ class link_views_handler_filter_protocol extends views_handler_filter_string { + /** * Set defaults for the filter options. + * + * @codingStandardsIgnoreEnd */ - function options(&$options) { - parent::options($options); + function option_definition() { + $options = parent::option_definition(); + $options['operator'] = 'OR'; $options['value'] = 'http'; $options['case'] = 0; + + return $options; } /** * Define the operators supported for protocols. */ - function operators() { + public function operators() { $operators = array( 'OR' => array( 'title' => t('Is one of'), @@ -35,7 +43,13 @@ class link_views_handler_filter_protocol extends views_handler_filter_string { return $operators; } - function options_form(&$form, &$form_state) { + /** + * Options form. + * + * @codingStandardsIgnoreStart + */ + public function options_form(&$form, &$form_state) { + //@codingStandardsIgnoreEnd parent::options_form($form, $form_state); $form['case'] = array( '#type' => 'value', @@ -45,8 +59,11 @@ class link_views_handler_filter_protocol extends views_handler_filter_string { /** * Provide a select list to choose the desired protocols. + * + * @codingStandardsIgnoreStart */ - function value_form(&$form, &$form_state) { + public function value_form(&$form, &$form_state) { + // @codingStandardsIgnoreEnd // We have to make some choices when creating this as an exposed // filter form. For example, if the operator is locked and thus // not rendered, we can't render dependencies; instead we only @@ -61,7 +78,19 @@ class link_views_handler_filter_protocol extends views_handler_filter_string { '#type' => 'select', '#title' => t('Protocol'), '#default_value' => $this->value, - '#options' => drupal_map_assoc(variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'))), + '#options' => drupal_map_assoc(variable_get('filter_allowed_protocols', array( + 'http', + 'https', + 'ftp', + 'news', + 'nntp', + 'telnet', + 'mailto', + 'irc', + 'ssh', + 'sftp', + 'webcal', + ))), '#multiple' => 1, '#size' => 4, '#description' => t('The protocols displayed here are those globally available. You may add more protocols by modifying the filter_allowed_protocols variable in your installation.'), @@ -71,8 +100,11 @@ class link_views_handler_filter_protocol extends views_handler_filter_string { /** * Filter down the query to include only the selected protocols. + * + * @codingStandardsIgnoreStart */ - function op_protocol($field, $upper) { + public function op_protocol($field, $upper) { + // @codingStandardsIgnoreEnd $db_type = db_driver(); $protocols = $this->value; @@ -80,27 +112,34 @@ class link_views_handler_filter_protocol extends views_handler_filter_string { $where_conditions = array(); foreach ($protocols as $protocol) { // Simple case, the URL begins with the specified protocol. - $condition = $field .' LIKE \''. $protocol .'%\''; + $condition = $field . ' LIKE \'' . $protocol . '%\''; - // More complex case, no protocol specified but is automatically cleaned up - // by link_cleanup_url(). RegEx is required for this search operation. + // More complex case, no protocol specified but is automatically cleaned + // up by link_cleanup_url(). RegEx is required for this search operation. if ($protocol == 'http') { + $link_domains = _link_domains(); if ($db_type == 'pgsql') { - // PostGreSQL code has NOT been tested. Please report any problems to the link issue queue. - // pgSQL requires all slashes to be double escaped in regular expressions. + // PostGreSQL code has NOT been tested. Please report any problems to + // the link issue queue. + // pgSQL requires all slashes to be double escaped in regular + // expressions. + // @codingStandardsIgnoreLine // See http://www.postgresql.org/docs/8.1/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP - $condition .= ' OR '. $field .' ~* \''.'^(([a-z0-9]([a-z0-9\\-_]*\\.)+)('. LINK_DOMAINS .'|[a-z][a-z]))'.'\''; + $condition .= ' OR ' . $field . ' ~* \'' . '^(([a-z0-9]([a-z0-9\\-_]*\\.)+)(' . $link_domains . '|[a-z][a-z]))' . '\''; } else { - // mySQL requires backslashes to be double (triple?) escaped within character classes. + // mySQL requires backslashes to be double (triple?) escaped within + // character classes. + // @codingStandardsIgnoreLine // See http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_regexp - $condition .= ' OR '. $field .' REGEXP \''.'^(([a-z0-9]([a-z0-9\\\-_]*\.)+)('. LINK_DOMAINS .'|[a-z][a-z]))'.'\''; + $condition .= ' OR ' . $field . ' REGEXP \'' . '^(([a-z0-9]([a-z0-9\\\-_]*\.)+)(' . $link_domains . '|[a-z][a-z]))' . '\''; } } $where_conditions[] = $condition; } - $this->query->add_where($this->options['group'], implode(' '. $this->operator .' ', $where_conditions)); + $this->query->add_where($this->options['group'], implode(' ' . $this->operator . ' ', $where_conditions)); } + } diff --git a/sites/all/modules/module_filter/CHANGELOG.txt b/sites/all/modules/module_filter/CHANGELOG.txt index 04f9247..5513831 100644 --- a/sites/all/modules/module_filter/CHANGELOG.txt +++ b/sites/all/modules/module_filter/CHANGELOG.txt @@ -1,23 +1,58 @@ -Module Filter 7.x-2.x, 2013-01-04 +Module Filter 7.x-2.1, 2017-06-09 --------------------------------- +Issue #2437439 by mikhail.krainiuk, greenSkin, jayhawkfan75: Module Filter does + not care about anchors in permission links. +Issue #2866236 by Munavijayalakshmi, dhruveshdtripathi: Typo error in + README.TXT file. +Issue #2452067 by Madis: Option to show description expanded as default + not working. +Issue #2580791 by makbul_khan8: Coding standards and few function without + help comments. +Issue #2153697 by annya: Disabling option "Number of enabled modules" breaks + tabs functionality. +Issue #1710230 by willvincent: On | Off buttons does not change state with + jquery_update module active. +Added option to show description as expanded by default. +Improved description field so when it is open, interacting with it's contents + does not make it collapse. +Placed collapsed/expanded images inside of module for easier, more reliable + access. +Added option to place version in own column. +Issue #2113191 by joelpittet: Category tabs not working. + + +Module Filter 7.x-2.0, 2015-02-22 +--------------------------------- +Simplifying the table rows by hiding version and requirements until a + particular description is clicked. +#2235553 by greenSkin: Fixed latest jquery_update breaks module filter. +#2304687 by mpdonadio: Fixed Remove hardcoded operations. +#2293029 by topsitemakers: Fixed Take header offset into account when selecting + a tab. +#2290213 by topsitemakers: Minor typo in description - "has no affect" -> "has + no effect". +#2141743, #2141743 by greenSkin: Fixed issues related to the new dynamically + positioned tabs and using the dynamically positioned save button. +by greenSkin: Tabs now should always be visible while scrolling large lists of + modules. +#1854348 by alexweber, greenSkin: Make filter textfield wider on modules page + when viewing as tabs. +by greenSkin: Fixed what was suppose to be a call to variable_set(). +#1370492 by greenSkin: Remember selected tab after modules form submit. +by greenSkin: Changed the title for the 'module_filter_dynamic_save_position' + checkbox to make it clearer what it does. +#1166414 by greenSkin: Fixed broken submit when tabs are disabled. We no longer + reroute the theme of the system modules page unless tabs are enabled. +by greenSkin: Fixed issue on Available updates page where the update state + would not be remembered. +by greenSkin: Fixed 7200 update to rebuild the theme registry at the same time + as rebuilding the menu. by greenSkin: Fixed issue relating to row coloring when enabling/disabling modules via switch due to recent fix for jQuery Update module. - - -Module Filter 7.x-2.x, 2012-11-27 ---------------------------------- by greenSkin: Added functionality to show recently enabled/disabled modules. #1710230 by littlekoala, greenSkin: Fixed On | Off buttons does not change state with jquery_update() module active. - - -Module Filter 7.x-2.x, 2012-11-26 ---------------------------------- by greenSkin: Added description to filter textfield on permissions page. - - -Module Filter 7.x-2.x, 2012-11-04 ---------------------------------- by greenSkin: Added filter to user permissions page. by greenSkin: Fixed styling when JavaScript is disabled. by greenSkin: Fixed compatiblility with page_actions. @@ -32,10 +67,6 @@ by greenSkin: Added ability for tabs to be disabled. Direct use case is when the "New" tab contains zero new modules. by greenSkin: Added title to "New" tab link that helps to describe the criteria of a "new" module. - - -Module Filter 7.x-2.x, 2012-07-04 ---------------------------------- #1320796 by greenSkin: Added some validation checks before trying to select a tab in case the tab does not actually exist. #1429248 by klonos, greenSkin: Fixed Modules page table header overlaps @@ -51,24 +82,12 @@ by greenSkin: Clicking on module name now affects the toggle switch. by greenSkin: Do not render the switch for incompatible modules. #1033012 by greenSkin: Hide incompatible module rows when the 'Unavailable' checkbox is unchecked. - - -Module Filter 7.x-2.x, 2012-02-24 ---------------------------------- by greenSkin: Performance tweak to counting the number of enabled modules. - - -Module Filter 7.x-2.x, 2012-02-01 ---------------------------------- by greenSkin: Base new modules on the filectime of their .info file. #1424034 by greenSkin: Now adds the jquery.cookie.js file when needed. by greenSkin: Removed tweaks to the save configuration button in favor http://drupal.org/project/page_actions. by greenSkin: Updated hook_uninstall to del all Module Filter variables. - - -Module Filter 7.x-2.x, 2012-01-30 ---------------------------------- by greenSkin: No longer including machine name in the tab summary of modules to enable/disable. by greenSkin: Made switches honor disabled checkboxes. A disabled switch can @@ -79,36 +98,20 @@ by greenSkin: Centered enable switch. by greenSkin: Moved couple styles to be applied via JavaScript instead of CSS so they get applied once the initial loading has finished. by greenSkin: Implemented a "switch" look instead of checkboxes. - - -Module Filter 7.x-2.x, 2012-01-30 ---------------------------------- by greenSkin: Remember last selected state on "Available updates" page. by greenSkin: Switched to using filectime() rather than filemtime() for determining new modules. #1354134 by klonos, greenSkin: Module list now formats correctly in core "Garland" theme. - - -Module Filter 7.x-2.x, 2011-12-12 ---------------------------------- #1354134 by klonos, greenSkin: Module list now formats correctly in core "Garland" theme. #1124218 by jyee, greenSkin: Suppress form submission when hitting the enter key while the filter input is focused. - - -Module Filter 7.x-2.x, 2011-11-23 ---------------------------------- by greenSkin: Simplified filter rules for updates page. Instead of checkboxes, now using radios. by greenSkin: Fixed "All" tab to be selected by default when the page is first loaded. #1350124 by greenSkin: Fixed filtering on package tab. - - -Module Filter 7.x-2.x, 2011-11-21 ---------------------------------- by greenSkin: Added the "All" tab back. Added a "New" tab that lists modules installed within the last week. by greenSkin: Fixed "No Results" not showing within selected tabs. @@ -123,10 +126,6 @@ by greenSkin: Filter now uses OR instead of AND when filtering multiply #1170388 by greenSkin: Fixed confict with Overlay module. Added class "overlay-exclude" to tab links. Added setting to toggle the use of a URL fragment when selecting tabs. - - -Module Filter 7.x-2.x, 2011-10-11 ---------------------------------- by greenSkin: Added README.txt. by greenSkin: Fixed table row striping. by greenSkin: Fixed regular expression to not require an operator be at the @@ -138,10 +137,6 @@ by greenSkin: Added operator support to filter. Added "requires:" and "requiredBy:" operators. by greenSkin: Filter now processes multiple queries separated by spaces. Use quotes for a single query that includes space(s). - - -Module Filter 7.x-2.x, 2011-09-19 ---------------------------------- by greenSkin: Fixed not updating the index when a module is enabled/disabled. by greenSkin: Fixed visual aid for enabling/disabling modules. Previously had failed to remove +/- from tab summary. @@ -150,10 +145,6 @@ by Kiphaas7, greenSkin: Tabs can now be configured to hide when they contain by Kiphaas7, greenSkin: Added result info to tabs. When a filter is performed, a count per tab is displayed of the number of visible results for that tab. by greenSkin: Now more descriptive of what modules are being enabled/disabled. - - -Module Filter 7.x-2.x, 2011-09-15 ---------------------------------- by greenSkin: Moved module operation links to below "Requires" and "Required by" section. by greenSkin: Added a suggest class to tabs when their module is hovered. @@ -165,10 +156,6 @@ by greenSkin: Added update to force a menu rebuild. This is needed to let filter on its page. #1254140 by greenSkin: No longer return anything in hook_update_7100. #1257860 by greenSkin: Added filter to update status report. - - -Module Filter 7.x-2.x, 2011-09-14 ---------------------------------- by greenSkin: Moved hiding of the inputs wrapper to css rather than a style attribute. by greenSkin: Added missing semi-colons in JavaScript. diff --git a/sites/all/modules/module_filter/README.txt b/sites/all/modules/module_filter/README.txt index 0bc967a..b03d970 100644 --- a/sites/all/modules/module_filter/README.txt +++ b/sites/all/modules/module_filter/README.txt @@ -17,8 +17,8 @@ visibility of modules that are disabled and depend on module(s) that are missing. The update status report filter also contains four checkboxes: Up-to-Date, -Update availabe, Security update, and Unknown. These directly affect the -visibilty of each project; whether it is up-to-date, there is an update +Update available, Security update, and Unknown. These directly affect the +visibility of each project; whether it is up-to-date, there is an update available, a security update is available, or the status is unknown. Installation diff --git a/sites/all/modules/module_filter/css/dynamic_position.css b/sites/all/modules/module_filter/css/dynamic_position.css index 763e05d..bc3b3e7 100644 --- a/sites/all/modules/module_filter/css/dynamic_position.css +++ b/sites/all/modules/module_filter/css/dynamic_position.css @@ -1,6 +1,4 @@ html.js #module-filter-submit { - float: left; - clear: both; background-color: #F6F6F6; width: 239px; border: 1px solid #ccc; diff --git a/sites/all/modules/module_filter/css/module_filter.css b/sites/all/modules/module_filter/css/module_filter.css index 19d113f..b03bbb7 100644 --- a/sites/all/modules/module_filter/css/module_filter.css +++ b/sites/all/modules/module_filter/css/module_filter.css @@ -18,3 +18,9 @@ text-transform: uppercase; color: #888; } +#module-filter-modules { + position: relative; +} +#module-filter-modules table { + position: absolute; +} diff --git a/sites/all/modules/module_filter/css/module_filter_tab.css b/sites/all/modules/module_filter/css/module_filter_tab.css index 95b4b61..fd7d0f0 100644 --- a/sites/all/modules/module_filter/css/module_filter_tab.css +++ b/sites/all/modules/module_filter/css/module_filter_tab.css @@ -3,6 +3,9 @@ } #module-filter-tabs { + float: left; +} +#module-filter-tabs ul { width: 239px; list-style: none; list-style-image: none; @@ -11,7 +14,6 @@ border-top: none; margin: 0; padding: 0; - float: left; line-height: 1; } #module-filter-tabs li { @@ -107,6 +109,9 @@ html.js .module-filter-inputs-wrapper .form-item { html.js .module-filter-inputs-wrapper label { display: inline; } +html.js .module-filter-inputs-wrapper input[name="module_filter[name]"] { + width: 80%; +} html.js #module-filter-show-wrapper { margin-bottom: 1em; } @@ -162,9 +167,6 @@ html.js #module-filter-modules table td { .admin-version { white-space: nowrap; } -.admin-operations { - float: right; -} .admin-operations a.module-link { display: inline; } @@ -246,3 +248,12 @@ html.js .toggle-enable div:after { html.js .toggle-enable.off div { left: 24px; } + +#module-filter-tabs.top-fixed { + position: fixed; + top: 0; +} +#module-filter-tabs.bottom-fixed { + position: fixed; + bottom: 0; +} diff --git a/sites/all/modules/module_filter/css/modules.css b/sites/all/modules/module_filter/css/modules.css new file mode 100644 index 0000000..0659825 --- /dev/null +++ b/sites/all/modules/module_filter/css/modules.css @@ -0,0 +1,53 @@ +#system-modules table { + table-layout: fixed; +} +#system-modules th.checkbox { + width: 8%; +} +#system-modules th.name { + width: 25%; +} +#system-modules th.version { + width: 10%; +} +#system-modules th.links { + width: 15%; +} +#system-modules td { + vertical-align: top; +} +#system-modules .expand.inner { + background: transparent url(../images/collapsed.png) left 0.6em no-repeat; + margin-left: -12px; + padding-left: 12px; +} +#system-modules .expanded.expand.inner { + background: transparent url(../images/expanded.png) left 0.6em no-repeat; +} +#system-modules .description { + cursor: pointer; +} +#system-modules .description .inner { + overflow: hidden; /* truncates descriptions if too long */ + text-overflow: ellipsis; + white-space: nowrap; +} +#system-modules .description .inner.expanded > * { + cursor: auto; +} +#system-modules .description .requirements, +#system-modules .description .links { + display: none; +} +#system-modules .description .expanded.inner { + overflow: visible; + white-space: normal; +} +#system-modules .description .expanded .requirements, +#system-modules .description .expanded .links { + display: block; +} +#system-modules .requirements { + padding: 5px 0; + max-width: 490px; +} diff --git a/sites/all/modules/module_filter/images/collapsed.png b/sites/all/modules/module_filter/images/collapsed.png new file mode 100644 index 0000000..91f3fd4 Binary files /dev/null and b/sites/all/modules/module_filter/images/collapsed.png differ diff --git a/sites/all/modules/module_filter/images/expanded.png b/sites/all/modules/module_filter/images/expanded.png new file mode 100644 index 0000000..46f39ec Binary files /dev/null and b/sites/all/modules/module_filter/images/expanded.png differ diff --git a/sites/all/modules/module_filter/js/dynamic_position.js b/sites/all/modules/module_filter/js/dynamic_position.js index 96e316f..41c5731 100644 --- a/sites/all/modules/module_filter/js/dynamic_position.js +++ b/sites/all/modules/module_filter/js/dynamic_position.js @@ -6,35 +6,24 @@ Drupal.behaviors.moduleFilterDynamicPosition = { $('#module-filter-wrapper', context).once('dynamic-position', function() { // Move the submit button just below the tabs. - $('#module-filter-modules'). before($('#module-filter-submit')); - if (Drupal.settings.moduleFilter.hideEmptyTabs) { - // Trigger window scroll. When the save buttons dynamic position is enabled - // we need this to ensure the save button's position updates with the new - // height of the tabs. - $window.trigger('scroll'); - } + $('#module-filter-tabs').append($('#module-filter-submit')); - // Control the positioning. - $window.scroll(function() { + var positionSubmit = function() { var $tabs = $('#module-filter-tabs'); - var $submit = $('#module-filter-submit'); + var $submit = $('#module-filter-submit', $tabs); // Vertical movement. - var top = $tabs.offset().top; - var bottom = top + $tabs.height(); - var windowHeight = $window.height(); - var topOffset = Drupal.settings.tableHeaderOffset ? eval(Drupal.settings.tableHeaderOffset + '()') : 0; - if (((bottom - windowHeight) > ($window.scrollTop() - $submit.height())) && $window.scrollTop() + windowHeight - $submit.height() - $('li:first', $tabs).height() > top) { - $submit.css('margin-top', 0); - $submit.removeClass('fixed-top').addClass('fixed fixed-bottom'); + var bottom = $tabs.offset().top + $tabs.outerHeight(); + if ($submit.hasClass('fixed-bottom')) { + bottom += $submit.height(); } - else if (bottom < ($window.scrollTop() + topOffset)) { - $submit.css('margin-top', topOffset); - $submit.removeClass('fixed-bottom').addClass('fixed fixed-top'); + if (bottom >= $window.height() + $window.scrollTop()) { + $submit.addClass('fixed fixed-bottom'); + $tabs.css('padding-bottom', $submit.height()); } else { - $submit.css('margin-top', 0); - $submit.removeClass('fixed fixed-bottom fixed-top'); + $submit.removeClass('fixed fixed-bottom'); + $tabs.css('padding-bottom', 0); } // Horizontal movement. @@ -44,11 +33,14 @@ Drupal.behaviors.moduleFilterDynamicPosition = { $submit.css('left', left); } } - }); - $window.trigger('scroll'); - $window.resize(function() { - $window.trigger('scroll'); - }); + }; + + // Control the positioning. + $window.scroll(positionSubmit); + $window.resize(positionSubmit); + var moduleFilter = $('input[name="module_filter[name]"]').data('moduleFilter'); + moduleFilter.element.bind('moduleFilter:adjustHeight', positionSubmit); + moduleFilter.adjustHeight(); }); } }; diff --git a/sites/all/modules/module_filter/js/module_filter.js b/sites/all/modules/module_filter/js/module_filter.js index 4301e7e..4fcf6e6 100644 --- a/sites/all/modules/module_filter/js/module_filter.js +++ b/sites/all/modules/module_filter/js/module_filter.js @@ -40,13 +40,11 @@ Drupal.ModuleFilter.setState = function(key, value) { var existing = Drupal.ModuleFilter.getState(key); if (existing != value) { Drupal.ModuleFilter.state[key] = value; - if (Drupal.settings.moduleFilter.rememberUpdateState) { - var query = []; - for (var i in Drupal.ModuleFilter.state) { - query.push(i + '=' + Drupal.ModuleFilter.state[i]); - } - $.cookie('DrupalModuleFilter', query.join('&'), { expires: 7, path: '/' }); + var query = []; + for (var i in Drupal.ModuleFilter.state) { + query.push(i + '=' + Drupal.ModuleFilter.state[i]); } + $.cookie('DrupalModuleFilter', query.join('&'), { expires: 7, path: '/' }); } }; @@ -267,6 +265,9 @@ $.fn.moduleFilter = function(selector, options) { if (Drupal.settings.moduleFilter.setFocus) { filterInput.focus(); } + if (Drupal.settings.moduleFilter.expandedDescription) { + $('#system-modules td.description .inner.expand').addClass('expanded'); + } filterInput.data('moduleFilter', new Drupal.ModuleFilter.Filter(this, selector, options)); }; diff --git a/sites/all/modules/module_filter/js/module_filter_tab.js b/sites/all/modules/module_filter/js/module_filter_tab.js index b14e842..c62b9ef 100644 --- a/sites/all/modules/module_filter/js/module_filter_tab.js +++ b/sites/all/modules/module_filter/js/module_filter_tab.js @@ -43,6 +43,7 @@ Drupal.behaviors.moduleFilterTabs = { attach: function(context) { if (Drupal.settings.moduleFilter.tabs) { $('#module-filter-wrapper table:not(.sticky-header)', context).once('module-filter-tabs', function() { + var $modules = $('#module-filter-modules'); var moduleFilter = $('input[name="module_filter[name]"]').data('moduleFilter'); var table = $(this); @@ -51,10 +52,12 @@ Drupal.behaviors.moduleFilterTabs = { // Remove package header rows. $('tr.admin-package-header', table).remove(); + var $tabsWrapper = $(''); + // Build tabs from package title rows. - var tabs = ' '; + var tabs = '
'; for (var i in Drupal.settings.moduleFilter.packageIDs) { - var id = Drupal.settings.moduleFilter.packageIDs[i]; + var id = Drupal.checkPlain(Drupal.settings.moduleFilter.packageIDs[i]); var name = id; var tabClass = 'project-tab'; @@ -81,9 +84,9 @@ Drupal.behaviors.moduleFilterTabs = { summary += '' + Drupal.t('No modules were enabled or disabled within the last week.') + ''; } break; - default: - var $row = $('#' + id + '-package'); - name = $.trim($row.text()); + default: + var $row = $('#' + id + '-package', this); + name = Drupal.checkPlain($.trim($row.text())); $row.remove(); break; } @@ -91,7 +94,8 @@ Drupal.behaviors.moduleFilterTabs = { tabs += '
'; - $('#module-filter-modules').before(tabs); + $tabsWrapper.append(tabs); + $modules.before($tabsWrapper); // Index tabs. $('#module-filter-tabs li').each(function() { @@ -100,7 +104,7 @@ Drupal.behaviors.moduleFilterTabs = { Drupal.ModuleFilter.tabs[id] = new Drupal.ModuleFilter.Tab($tab, id); }); - $('#module-filter-modules tbody td.checkbox input').change(function() { + $('tbody td.checkbox input', $modules).change(function() { var $checkbox = $(this); var key = $checkbox.parents('tr').data('indexKey'); @@ -127,7 +131,7 @@ Drupal.behaviors.moduleFilterTabs = { .filter(':odd').addClass('even').end() .filter(':even').addClass('odd'); - Drupal.ModuleFilter.adjustHeight(); + moduleFilter.adjustHeight(); moduleFilter.element.bind('moduleFilter:start', function() { moduleFilter.tabResults = { @@ -203,7 +207,6 @@ Drupal.behaviors.moduleFilterTabs = { Drupal.ModuleFilter.tabs[id].element.hide(); } } - Drupal.ModuleFilter.adjustHeight(); } } else { @@ -218,18 +221,20 @@ Drupal.behaviors.moduleFilterTabs = { // The current tab contains no results. moduleFilter.results = 0; } + + moduleFilter.adjustHeight(); }); if (Drupal.settings.moduleFilter.useURLFragment) { $(window).bind('hashchange.module-filter', $.proxy(Drupal.ModuleFilter, 'eventHandlerOperateByURLFragment')).triggerHandler('hashchange.module-filter'); } else { - Drupal.ModuleFilter.selectTab('all'); + Drupal.ModuleFilter.selectTab(); } if (Drupal.settings.moduleFilter.useSwitch) { - $('td.checkbox div.form-item').hide(); - $('td.checkbox').each(function(i) { + $('td.checkbox div.form-item', table).hide(); + $('td.checkbox', table).each(function(i) { var $cell = $(this); var $checkbox = $(':checkbox', $cell); var $switch = $('.toggle-enable', $cell); @@ -237,19 +242,115 @@ Drupal.behaviors.moduleFilterTabs = { if (!$(this).hasClass('disabled')) { if (Drupal.ModuleFilter.jQueryIsNewer()) { $checkbox.click(); + $switch.toggleClass('off'); } else { $checkbox.click().change(); + $switch.toggleClass('off'); } } }); - $checkbox.click(function() { - if (!$switch.hasClass('disabled')) { - $switch.toggleClass('off'); - } - }); }); } + + var $tabs = $('#module-filter-tabs'); + + function getParentTopOffset($obj, offset) { + var $parent = $obj.offsetParent(); + if ($obj[0] != $parent[0]) { + offset += $parent.position().top; + return getParentTopOffset($parent, offset); + } + return offset; + } + + var tabsTopOffset = null; + function getParentsTopOffset() { + if (tabsTopOffset === null) { + tabsTopOffset = getParentTopOffset($tabs.parent(), 0); + } + return tabsTopOffset; + } + + function viewportTop() { + var top = $(window).scrollTop(); + return top; + } + + function viewportBottom() { + var top = $(window).scrollTop(); + var bottom = top + $(window).height(); + + bottom -= $('#page-actions').height(); + + return bottom; + } + + function fixToTop(top) { + if ($tabs.hasClass('bottom-fixed')) { + $tabs.css({ + 'position': 'absolute', + 'top': $tabs.position().top - getParentsTopOffset(), + 'bottom': 'auto' + }); + $tabs.removeClass('bottom-fixed'); + } + + if (($tabs.css('position') == 'absolute' && $tabs.offset().top - top >= 0) || ($tabs.css('position') != 'absolute' && $tabs.offset().top - top <= 0)) { + $tabs.addClass('top-fixed'); + $tabs.attr('style', ''); + } + } + + function fixToBottom(bottom) { + if ($tabs.hasClass('top-fixed')) { + $tabs.css({ + 'position': 'absolute', + 'top': $tabs.position().top - getParentsTopOffset(), + 'bottom': 'auto' + }); + $tabs.removeClass('top-fixed'); + } + + if ($tabs.offset().top + $tabs.height() - bottom <= 0) { + $tabs.addClass('bottom-fixed'); + var style = ''; + var pageActionsHeight = $('#page-actions').height(); + if (pageActionsHeight > 0) { + style = 'bottom: ' + pageActionsHeight + 'px'; + } + else if (Drupal.settings.moduleFilter.dynamicPosition) { + // style = 'bottom: ' + $('#module-filter-submit', $tabs).height() + 'px'; + } + $tabs.attr('style', style); + } + } + + var lastTop = 0; + $(window).scroll(function() { + var top = viewportTop(); + var bottom = viewportBottom(); + + if ($modules.offset().top >= top) { + $tabs.removeClass('top-fixed').attr('style', ''); + } + else { + if (top > lastTop) { // Downward scroll. + if ($tabs.height() > bottom - top) { + fixToBottom(bottom); + } + else { + fixToTop(top); + } + } + else { // Upward scroll. + fixToTop(top); + } + } + lastTop = top; + }); + + moduleFilter.adjustHeight(); }); } } @@ -288,7 +389,16 @@ Drupal.ModuleFilter.Tab = function(element, id) { Drupal.ModuleFilter.selectTab = function(hash) { if (!hash || Drupal.ModuleFilter.tabs[hash + '-tab'] == undefined || Drupal.settings.moduleFilter.enabledCounts[hash].total == 0) { - hash = 'all'; + if (Drupal.settings.moduleFilter.rememberActiveTab) { + var activeTab = Drupal.ModuleFilter.getState('activeTab'); + if (activeTab && Drupal.ModuleFilter.tabs[activeTab + '-tab'] != undefined) { + hash = activeTab; + } + } + + if (!hash) { + hash = 'all'; + } } if (Drupal.ModuleFilter.activeTab != undefined) { @@ -299,7 +409,24 @@ Drupal.ModuleFilter.selectTab = function(hash) { Drupal.ModuleFilter.activeTab.element.addClass('selected'); var moduleFilter = $('input[name="module_filter[name]"]').data('moduleFilter'); - moduleFilter.applyFilter(); + var filter = moduleFilter.applyFilter(); + + if (!Drupal.ModuleFilter.modulesTop) { + Drupal.ModuleFilter.modulesTop = $('#module-filter-modules').offset().top; + } + else { + // Calculate header offset; this is important in case the site is using + // admin_menu module which has fixed positioning and is on top of everything + // else. + var headerOffset = Drupal.settings.tableHeaderOffset ? eval(Drupal.settings.tableHeaderOffset + '()') : 0; + // Scroll back to top of #module-filter-modules. + $('html, body').animate({ + scrollTop: Drupal.ModuleFilter.modulesTop - headerOffset + }, 500); + // $('html, body').scrollTop(Drupal.ModuleFilter.modulesTop); + } + + Drupal.ModuleFilter.setState('activeTab', hash); }; Drupal.ModuleFilter.eventHandlerOperateByURLFragment = function(event) { @@ -390,7 +517,7 @@ Drupal.ModuleFilter.updateVisualAid = function(type, $row) { } var tab = Drupal.ModuleFilter.tabs[id]; - var name = $('td:nth(1) strong', $row).text(); + var name = Drupal.checkPlain($('td:nth(1) strong', $row).text()); switch (type) { case 'enable': if (Drupal.ModuleFilter.disabling[id + name] != undefined) { @@ -421,13 +548,12 @@ Drupal.ModuleFilter.updateVisualAid = function(type, $row) { tab.updateVisualAid(); }; -Drupal.ModuleFilter.adjustHeight = function() { +Drupal.ModuleFilter.Filter.prototype.adjustHeight = function() { // Hack for adjusting the height of the modules section. - var minHeight = $('#module-filter-tabs').height() + 10; - if (Drupal.settings.moduleFilter.dynamicPosition) { - minHeight += $('#module-filter-submit').height(); - } + var minHeight = $('#module-filter-tabs ul').height() + 10; + minHeight += $('#module-filter-tabs #module-filter-submit').height(); $('#module-filter-modules').css('min-height', minHeight); + this.element.trigger('moduleFilter:adjustHeight'); } })(jQuery); diff --git a/sites/all/modules/module_filter/js/modules.js b/sites/all/modules/module_filter/js/modules.js index 505c395..b0b4939 100644 --- a/sites/all/modules/module_filter/js/modules.js +++ b/sites/all/modules/module_filter/js/modules.js @@ -2,6 +2,17 @@ Drupal.behaviors.moduleFilter = { attach: function(context) { + $('#system-modules td.description').once('description', function() { + $(this).click(function() { + $('.inner.expand', $(this)).toggleClass('expanded'); + }); + $('.inner.expand', $(this)).children().click(function(e) { + if ($(this).parent().hasClass('expanded')) { + e.stopPropagation(); + } + }); + }); + $('.module-filter-inputs-wrapper', context).once('module-filter', function() { var filterInput = $('input[name="module_filter[name]"]', context); var selector = '#system-modules table tbody tr'; diff --git a/sites/all/modules/module_filter/module_filter.admin.inc b/sites/all/modules/module_filter/module_filter.admin.inc index 11a2f6b..cdb3f49 100644 --- a/sites/all/modules/module_filter/module_filter.admin.inc +++ b/sites/all/modules/module_filter/module_filter.admin.inc @@ -17,7 +17,7 @@ function module_filter_settings() { $form['module_filter_set_focus'] = array( '#type' => 'checkbox', '#title' => t('Set focus to filter field on page load'), - '#description' => t('Currently has no affect when using Overlay module.'), + '#description' => t('Currently has no effect when using Overlay module.'), '#default_value' => variable_get('module_filter_set_focus', 1), ); @@ -25,44 +25,44 @@ function module_filter_settings() { '#type' => 'checkbox', '#title' => t('Enhance the modules page with tabs'), '#description' => t('Alternate tabbed theme that restructures packages into tabs.'), - '#default_value' => variable_get('module_filter_tabs', 1) + '#default_value' => variable_get('module_filter_tabs', 1), ); $form['tabs'] = array( '#type' => 'fieldset', '#title' => t('Tabs'), '#description' => t('Settings used with the tabs view of the modules page.'), '#collapsible' => TRUE, - '#collapsed' => FALSE + '#collapsed' => FALSE, ); $form['tabs']['module_filter_count_enabled'] = array( '#type' => 'checkbox', '#title' => t('Number of enabled modules'), '#description' => t('Display the number of enabled modules in the active tab along with the total number of modules.'), - '#default_value' => variable_get('module_filter_count_enabled', 1) + '#default_value' => variable_get('module_filter_count_enabled', 1), ); $form['tabs']['module_filter_visual_aid'] = array( '#type' => 'checkbox', '#title' => t('Visual aids'), '#description' => t('When enabling/disabling modules, the module name will display in the tab summary.- ' + name + '' + summary + '
'; } tabs += '
When filtering, a count of results for each tab will be presented.'), - '#default_value' => variable_get('module_filter_visual_aid', 1) + '#default_value' => variable_get('module_filter_visual_aid', 1), ); $form['tabs']['module_filter_hide_empty_tabs'] = array( '#type' => 'checkbox', '#title' => t('Hide tabs with no results'), '#description' => t('When a filter returns no results for a tab, the tab is hidden. This is dependent on visual aids being enabled.'), - '#default_value' => variable_get('module_filter_hide_empty_tabs', 0) + '#default_value' => variable_get('module_filter_hide_empty_tabs', 0), ); $form['tabs']['module_filter_dynamic_save_position'] = array( '#type' => 'checkbox', - '#title' => t('Dynamic Save position'), + '#title' => t('Dynamically position Save button'), '#description' => t("For sites with lots of tabs, enable to help keep the 'Save configuration' button more accessible."), - '#default_value' => variable_get('module_filter_dynamic_save_position', 1) + '#default_value' => variable_get('module_filter_dynamic_save_position', 1), ); $form['tabs']['module_filter_use_url_fragment'] = array( '#type' => 'checkbox', '#title' => t('Use URL fragment'), '#description' => t('Use URL fragment when navigating between tabs. This lets you use the browsers back/forward buttons to navigate through the tabs you selected.') . '
' . t('When the Overlay module is enabled this functionality will not be used since overlay relies on the URL fragment.'), - '#default_value' => variable_get('module_filter_use_url_fragment', 1) + '#default_value' => variable_get('module_filter_use_url_fragment', 1), ); $form['tabs']['module_filter_use_switch'] = array( '#type' => 'checkbox', @@ -76,6 +76,24 @@ function module_filter_settings() { '#description' => t('Adds a "Recent" tab that displays modules that have been enabled or disabled with the last week.'), '#default_value' => variable_get('module_filter_track_recent_modules', 1), ); + $form['tabs']['module_filter_remember_active_tab'] = array( + '#type' => 'checkbox', + '#title' => t('Remember active tab.'), + '#description' => t('When enabled, the active tab will be remembered.'), + '#default_value' => variable_get('module_filter_remember_active_tab', 1), + ); + $form['tabs']['module_filter_version_column'] = array( + '#type' => 'checkbox', + '#title' => t('Place version in own column'), + '#description' => t("Moves the version out of the description and into it's own column"), + '#default_value' => variable_get('module_filter_version_column', 0), + ); + $form['tabs']['module_filter_expanded_description'] = array( + '#type' => 'checkbox', + '#title' => t('Expand description by default'), + '#description' => t('When enabled, the description will be expanded by default.'), + '#default_value' => variable_get('module_filter_expanded_description', 0), + ); $form['update'] = array( '#type' => 'fieldset', diff --git a/sites/all/modules/module_filter/module_filter.info b/sites/all/modules/module_filter/module_filter.info index 9702652..e21267d 100644 --- a/sites/all/modules/module_filter/module_filter.info +++ b/sites/all/modules/module_filter/module_filter.info @@ -4,7 +4,6 @@ core = 7.x package = Administration files[] = module_filter.install -files[] = module_filter.js files[] = module_filter.module files[] = module_filter.admin.inc files[] = module_filter.theme.inc @@ -17,9 +16,8 @@ files[] = js/module_filter_tab.js configure = admin/config/user-interface/modulefilter -; Information added by drupal.org packaging script on 2013-01-05 -version = "7.x-2.x-dev" +; Information added by Drupal.org packaging script on 2019-03-27 +version = "7.x-2.2" core = "7.x" project = "module_filter" -datestamp = "1357349173" - +datestamp = "1553698385" diff --git a/sites/all/modules/module_filter/module_filter.install b/sites/all/modules/module_filter/module_filter.install index 6aa3dcf..529d836 100644 --- a/sites/all/modules/module_filter/module_filter.install +++ b/sites/all/modules/module_filter/module_filter.install @@ -17,7 +17,10 @@ function module_filter_uninstall() { variable_del('module_filter_use_url_fragment'); variable_del('module_filter_use_switch'); variable_del('module_filter_track_recent_modules'); + variable_del('module_filter_remember_active_tab'); variable_del('module_filter_remember_update_state'); + variable_del('module_filter_version_column'); + variable_del('module_filter_expanded_description'); } /** @@ -28,10 +31,12 @@ function module_filter_update_7100() { } /** - * Rebuild the menu. + * Rebuild the menu and theme registry. */ function module_filter_update_7200() { menu_rebuild(); + system_rebuild_theme_data(); + drupal_theme_rebuild(); } /** diff --git a/sites/all/modules/module_filter/module_filter.module b/sites/all/modules/module_filter/module_filter.module index 39ca0e7..17059ec 100644 --- a/sites/all/modules/module_filter/module_filter.module +++ b/sites/all/modules/module_filter/module_filter.module @@ -18,8 +18,8 @@ function module_filter_permission() { return array( 'administer module filter' => array( 'title' => t('Administer Module Filter'), - 'description' => t('Configure how Module Filter performs.') - ) + 'description' => t('Configure how Module Filter performs.'), + ), ); } @@ -33,7 +33,7 @@ function module_filter_menu() { 'access arguments' => array('administer module filter'), 'page callback' => 'drupal_get_form', 'page arguments' => array('module_filter_settings'), - 'file' => 'module_filter.admin.inc' + 'file' => 'module_filter.admin.inc', ); return $items; } @@ -63,25 +63,39 @@ function module_filter_form_system_modules_alter(&$form, &$form_state, $form_id) '#type' => 'module_filter', '#attached' => array( 'js' => array( - drupal_get_path('module', 'module_filter') . '/js/modules.js' - ) - ) + drupal_get_path('module', 'module_filter') . '/js/modules.js' => array('weight' => 1), + ), + ), ); $checkbox_defaults = array( ((isset($_GET['enabled'])) ? $_GET['enabled'] : 1) ? 'enabled' : '', ((isset($_GET['disabled'])) ? $_GET['disabled'] : 1) ? 'disabled' : '', ((isset($_GET['required'])) ? $_GET['required'] : 1) ? 'required' : '', - ((isset($_GET['unavailable'])) ? $_GET['unavailable'] : 1) ? 'unavailable' : '' + ((isset($_GET['unavailable'])) ? $_GET['unavailable'] : 1) ? 'unavailable' : '', ); $form['module_filter']['show'] = array( '#type' => 'checkboxes', '#default_value' => array_filter($checkbox_defaults), '#options' => array('enabled' => t('Enabled'), 'disabled' => t('Disabled'), 'required' => t('Required'), 'unavailable' => t('Unavailable')), '#prefix' => '', - '#suffix' => '' + '#suffix' => '', - '#suffix' => '' + '#suffix' => '
' . t('The following tokens are available. If you would like to have the characters \'[\' and \']\' please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.' . '
'); + $output = '' + . t("The following tokens are available. If you would like to have the characters '[' and ']' please use the html entity codes '%5B' or '%5D' or they will get replaced with empty space.") + . '
'; foreach (array_keys($options) as $type) { if (!empty($options[$type])) { $items = array(); @@ -61,7 +79,7 @@ class views_handler_area_text extends views_handler_area { $output .= theme('item_list', array( 'items' => $items, - 'type' => $type + 'type' => $type, )); } } @@ -82,13 +100,19 @@ class views_handler_area_text extends views_handler_area { } } - function options_submit(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_submit(&$form, &$form_state) { $form_state['values']['options']['format'] = $form_state['values']['options']['content']['format']; $form_state['values']['options']['content'] = $form_state['values']['options']['content']['value']; parent::options_submit($form, $form_state); } - function render($empty = FALSE) { + /** + * {@inheritdoc} + */ + public function render($empty = FALSE) { $format = isset($this->options['format']) ? $this->options['format'] : filter_default_format(); if (!$empty || !empty($this->options['empty'])) { return $this->render_textarea($this->options['content'], $format); @@ -99,7 +123,7 @@ class views_handler_area_text extends views_handler_area { /** * Render a text area, using the proper format. */ - function render_textarea($value, $format) { + public function render_textarea($value, $format) { if ($value) { if ($this->options['tokenize']) { $value = $this->view->style_plugin->tokenize_value($value, 0); @@ -107,4 +131,5 @@ class views_handler_area_text extends views_handler_area { return check_markup($value, $format, '', FALSE); } } + } diff --git a/sites/all/modules/views/handlers/views_handler_area_text_custom.inc b/sites/all/modules/views/handlers/views_handler_area_text_custom.inc index 3627f0c..89577bc 100644 --- a/sites/all/modules/views/handlers/views_handler_area_text_custom.inc +++ b/sites/all/modules/views/handlers/views_handler_area_text_custom.inc @@ -12,13 +12,19 @@ */ class views_handler_area_text_custom extends views_handler_area_text { - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); unset($options['format']); return $options; } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); // Alter the form element, to be a regular text area. @@ -26,14 +32,20 @@ class views_handler_area_text_custom extends views_handler_area_text { unset($form['content']['#format']); unset($form['content']['#wysiwyg']); - // @TODO: Use the token refactored base class. + // @todo Use the token refactored base class. } - // Empty, so we don't inherit options_submit from the parent. - function options_submit(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_submit(&$form, &$form_state) { + // Empty, so we don't inherit options_submit from the parent. } - function render($empty = FALSE) { + /** + * {@inheritdoc} + */ + public function render($empty = FALSE) { if (!$empty || !empty($this->options['empty'])) { return $this->render_textarea_custom($this->options['content']); } @@ -43,8 +55,14 @@ class views_handler_area_text_custom extends views_handler_area_text { /** * Render a text area with filter_xss_admin. + * + * @param string $value + * The text area string to process. + * + * @return string + * The string after it has been sanitized, optionally tokenized too. */ - function render_textarea_custom($value) { + public function render_textarea_custom($value) { if ($value) { if ($this->options['tokenize']) { $value = $this->view->style_plugin->tokenize_value($value, 0); diff --git a/sites/all/modules/views/handlers/views_handler_area_view.inc b/sites/all/modules/views/handlers/views_handler_area_view.inc index 3b72bf6..2e93135 100644 --- a/sites/all/modules/views/handlers/views_handler_area_view.inc +++ b/sites/all/modules/views/handlers/views_handler_area_view.inc @@ -12,7 +12,10 @@ */ class views_handler_area_view extends views_handler_area { - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['view_to_insert'] = array('default' => ''); @@ -21,10 +24,9 @@ class views_handler_area_view extends views_handler_area { } /** - * Default options form that provides the label widget that all fields - * should have. + * Default options form; provides the label widget all fields should have. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $view_display = $this->view->name . ':' . $this->view->current_display; @@ -48,9 +50,9 @@ class views_handler_area_view extends views_handler_area { } /** - * Render the area + * Render the area. */ - function render($empty = FALSE) { + public function render($empty = FALSE) { if ($view = $this->loadView()) { if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) { return $view->preview(NULL, $this->view->args); diff --git a/sites/all/modules/views/handlers/views_handler_argument.inc b/sites/all/modules/views/handlers/views_handler_argument.inc index 86c4a0d..ced42a1 100644 --- a/sites/all/modules/views/handlers/views_handler_argument.inc +++ b/sites/all/modules/views/handlers/views_handler_argument.inc @@ -2,7 +2,7 @@ /** * @file - * @todo. + * Definition of views_handler_argument. */ /** @@ -14,50 +14,63 @@ /** * Base class for arguments. * - * The basic argument works for very simple arguments such as nid and uid + * The basic argument works for very simple arguments such as nid and uid. * * Definition terms for this handler: * - name field: The field to use for the name to use in the summary, which is - * the displayed output. For example, for the node: nid argument, - * the argument itself is the nid, but node.title is displayed. + * the displayed output. For example, for the node: nid argument, the argument + * itself is the nid, but node.title is displayed. * - name table: The table to use for the name, should it not be in the same - * table as the argument. + * table as the argument. * - empty field name: For arguments that can have no value, such as taxonomy - * which can have "no term", this is the string which - * will be displayed for this lack of value. Be sure to use - * t(). + * which can have "no term", this is the string which will be displayed for + * this lack of value. Be sure to use t(). * - validate type: A little used string to allow an argument to restrict - * which validator is available to just one. Use the - * validator ID. This probably should not be used at all, - * and may disappear or change. + * which validator is available to just one. Use the validator ID. This + * probably should not be used at all, and may disappear or change. * - numeric: If set to TRUE this field is numeric and will use %d instead of - * %s in queries. + * %s in queries. * * @ingroup views_argument_handlers */ class views_handler_argument extends views_handler { - var $validator = NULL; - var $argument = NULL; - var $value = NULL; /** - * The table to use for the name, should it not be in the same table as the argument. + * @var object + */ + public $validator = NULL; + + /** + * @var mixed + */ + public $argument = NULL; + + /** + * @var mixed + */ + public $value = NULL; + + /** + * The table to use for the name, if not the same table as the argument. + * * @var string */ - var $name_table; + public $name_table; /** - * The field to use for the name to use in the summary, which is - * the displayed output. For example, for the node: nid argument, - * the argument itself is the nid, but node.title is displayed. + * The field to use for the name to use in the summary. + * + * Used as the displayed output. For example, for the node: nid argument, the + * argument itself is the nid, but node.title is displayed. + * * @var string */ - var $name_field; + public $name_field; /** - * Constructor + * {@inheritdoc} */ - function construct() { + public function construct() { parent::construct(); if (!empty($this->definition['name field'])) { @@ -68,7 +81,10 @@ class views_handler_argument extends views_handler { } } - function init(&$view, &$options) { + /** + * {@inheritdoc} + */ + public function init(&$view, &$options) { parent::init($view, $options); // Compatibility: The new UI changed several settings. @@ -132,31 +148,43 @@ class views_handler_argument extends views_handler { /** * Give an argument the opportunity to modify the breadcrumb, if it wants. - * This only gets called on displays where a breadcrumb is actually used. + * + * Only gets called on displays where a breadcrumb is actually used. * * The breadcrumb will be in the form of an array, with the keys being * the path and the value being the already sanitized title of the path. */ - function set_breadcrumb(&$breadcrumb) { } + public function set_breadcrumb(&$breadcrumb) { + } /** - * Determine if the argument can generate a breadcrumb + * Determine if the argument can generate a breadcrumb. * - * @return TRUE/FALSE + * @return bool + * Indicates whether the argument can generate a breadcrumb. */ - function uses_breadcrumb() { + public function uses_breadcrumb() { $info = $this->default_actions($this->options['default_action']); return !empty($info['breadcrumb']); } - function is_exception($arg = NULL) { + /** + * {@inheritdoc} + */ + public function is_exception($arg = NULL) { if (!isset($arg)) { $arg = isset($this->argument) ? $this->argument : NULL; } - return !empty($this->options['exception']['value']) && $this->options['exception']['value'] === $arg; + return !empty($this->options['exception']['value']) && ($this->options['exception']['value'] === $arg); } - function exception_title() { + /** + * Work out which title to use. + * + * @return string + * The title string to use. + */ + public function exception_title() { // If title overriding is off for the exception, return the normal title. if (empty($this->options['exception']['title_enable'])) { return $this->get_title(); @@ -167,15 +195,19 @@ class views_handler_argument extends views_handler { /** * Determine if the argument needs a style plugin. * - * @return TRUE/FALSE + * @return bool + * the argument needs a plugin style. */ - function needs_style_plugin() { + public function needs_style_plugin() { $info = $this->default_actions($this->options['default_action']); $validate_info = $this->default_actions($this->options['validate']['fail']); return !empty($info['style plugin']) || !empty($validate_info['style plugin']); } - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['default_action'] = array('default' => 'ignore'); @@ -213,7 +245,10 @@ class views_handler_argument extends views_handler { return $options; } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $argument_text = $this->view->display_handler->get_argument_text(); @@ -380,8 +415,9 @@ class views_handler_argument extends views_handler { '#prefix' => '<?php -if (empty($form_state['view']->exposed_input[$identifier])) . - { $form_state['input'][$identifier] = $default_value; } +if (empty($form_state['view']->exposed_input[$identifier])) { + $form_state['input'][$identifier] = $default_value; +} ?>@@ -18,10 +19,10 @@ To do this, I used the following function, where geoip_redirect_get_tid() loads
<?php function MODULENAME_form_views_exposed_form_alter(&$form, $form_state) { - if(strpos($form['#id'], 'volunteer-directory') !== FALSE) { + if (strpos($form['#id'], 'volunteer-directory') !== FALSE) { $city_tid = geoip_redirect_get_tid(); - if(is_numeric($city_tid) && $city_tid != 7660) { - if (empty($form_state['view']->exposed_input['tid'])) { + if (is_numeric($city_tid) && $city_tid != 7660) { + if (empty($form_state['view']->exposed_input['tid'])) { $form_state['input']['tid'] = $city_tid; } } diff --git a/sites/all/modules/views/help/api-example.html b/sites/all/modules/views/help/api-example.html index 682fe87..819d65f 100644 --- a/sites/all/modules/views/help/api-example.html +++ b/sites/all/modules/views/help/api-example.html @@ -40,7 +40,7 @@ Below is the contents of a simple node_example.views.inc file that allows you to * @endcode */ -function node_example_views_data() { +function node_example_views_data() { // Basic table information. // ---------------------------------------------------------------- diff --git a/sites/all/modules/views/help/api-tables.html b/sites/all/modules/views/help/api-tables.html index cafbbab..c80d29a 100644 --- a/sites/all/modules/views/help/api-tables.html +++ b/sites/all/modules/views/help/api-tables.html @@ -169,8 +169,10 @@ Each field is described in the view data with an array, keyed to the database na$data['node']['nid'] = array( + // The item it appears as on the UI, 'title' => t('Nid'), - 'help' => t('The node ID of the node.'), // The help that appears on the UI, + // The help that appears on the UI, + 'help' => t('The node ID of the node.'), // Information for displaying the nid 'field' => array( 'handler' => 'views_handler_field_node', @@ -179,7 +181,8 @@ $data['node']['nid'] = array( // Information for accepting a nid as an argument 'argument' => array( 'handler' => 'views_handler_argument_node_nid', - 'name field' => 'title', // the field to display in the summary. + // The field to display in the summary. + 'name field' => 'title', 'numeric' => TRUE, 'validate type' => 'nid', ), diff --git a/sites/all/modules/views/help/api-upgrading.html b/sites/all/modules/views/help/api-upgrading.html index 158f809..2ff6bb4 100644 --- a/sites/all/modules/views/help/api-upgrading.html +++ b/sites/all/modules/views/help/api-upgrading.html @@ -113,9 +113,9 @@ The views_handler class got two new functions: /** * Get the value that's supposed to be rendered. * - * @param $values + * @param object $values * An object containing all retrieved values. - * @param $field + * @param string $field * Optional name of the field where the value is stored. */ function get_value($values, $field = NULL) { @@ -128,9 +128,9 @@ function get_value($values, $field = NULL) { /** * Sanitize the value for output. * - * @param $value + * @param string $value * The value being rendered. - * @param $type + * @param string $type * The type of sanitization needed. If not provided, check_plain() is used. */ function sanitize_value($value, $type = NULL) { @@ -138,9 +138,11 @@ function sanitize_value($value, $type = NULL) { case 'xss': $value = filter_xss($value); break; + case 'url': $value = check_url($value); break; + default: $value = check_plain($value); break; diff --git a/sites/all/modules/views/help/embed.html b/sites/all/modules/views/help/embed.html index e39fbf5..156b1dc 100644 --- a/sites/all/modules/views/help/embed.html +++ b/sites/all/modules/views/help/embed.html @@ -10,9 +10,9 @@ easiest way is to use the function views_embed_view(): * solution and doesn't really offer a lot of options, but breaking the function * apart is pretty easy, and this provides a worthwhile guide to doing so. * - * @param $name + * @param string $name * The name of the view to embed. - * @param $display_id + * @param string $display_id * The display id to embed. If unsure, use 'default', as it will always be * valid. But things like 'page' or 'block' should work here. * @param ... diff --git a/sites/all/modules/views/help/ui-crashes.html b/sites/all/modules/views/help/ui-crashes.html index 4e8a389..6c20794 100644 --- a/sites/all/modules/views/help/ui-crashes.html +++ b/sites/all/modules/views/help/ui-crashes.html @@ -1,10 +1,10 @@Troubleshooting UI crashes
-There are a number of reasons why the Views UI may crash; the most common state or result of a crash is either a white screen (everyone's favorite WSOD), or a screen of what looks like garbage text. This is generally a javascript crash of some fashion. +There are a number of reasons why the Views UI may crash; the most common state or result of a crash is either a white screen (everyone's favorite WSOD), or a screen of what looks like garbage text. This is generally JavaScript crash of some fashion. To get the most timely and accurate help in the issue queue, please try to gather this information: -Check your javascript console. In Firefox, you can hit ctrl-shift-j or use firebug. Copy this information into the issue, or attach it as a text file. Really - this is the single biggest thing you can do to help figure out where the crash is coming from. +Check your JavaScript console. In Firefox, you can hit ctrl-shift-j or use firebug. Copy this information into the issue, or attach it as a text file. Really - this is the single biggest thing you can do to help figure out where the crash is coming from.JSON prepends data with jQuery, causing editing and preview problems.
@@ -13,7 +13,7 @@ This section originally stems from this Some modules may add PHP improperly, disrupting normal jQuery operation. Errors may look like- session_module_name("files"); ?>{ "default": "default" } +{ "default": "default" }
This can also be a server configuration issue. In one case, this was solved by commenting out diff --git a/sites/all/modules/views/includes/admin.inc b/sites/all/modules/views/includes/admin.inc index 6098b23..810c70f 100644 --- a/sites/all/modules/views/includes/admin.inc +++ b/sites/all/modules/views/includes/admin.inc @@ -8,10 +8,11 @@ /** * Create an array of Views admin CSS for adding or attaching. * - * This returns an array of arrays. Each array represents a single - * file. The array format is: - * - file: The fully qualified name of the file to send to drupal_add_css - * - options: An array of options to pass to drupal_add_css. + * @return array + * An array of arrays. Each array represents a single file. The array format + * is: + * - file: The fully qualified name of the file to send to drupal_add_css + * - options: An array of options to pass to drupal_add_css. */ function views_ui_get_admin_css() { $module_path = drupal_get_path('module', 'views_ui'); @@ -21,27 +22,28 @@ function views_ui_get_admin_css() { $list[$module_path . '/css/ie/views-admin.ie7.css'] = array( 'browsers' => array( 'IE' => 'lte IE 7', - '!IE' => FALSE + '!IE' => FALSE, ), 'preprocess' => FALSE, ); $list[$module_path . '/css/views-admin.theme.css'] = array(); - // Add in any theme specific CSS files we have + // Add in any theme specific CSS files we have. $themes = list_themes(); $theme_key = $GLOBALS['theme']; while ($theme_key) { // Try to find the admin css file for non-core themes. if (!in_array($theme_key, array('garland', 'seven', 'bartik'))) { $theme_path = drupal_get_path('theme', $theme_key); - // First search in the css directory, then in the root folder of the theme. + // First search in the css directory, then in the root folder of the + // theme. if (file_exists($theme_path . "/css/views-admin.$theme_key.css")) { $list[$theme_path . "/css/views-admin.$theme_key.css"] = array( 'group' => CSS_THEME, ); } - else if (file_exists($theme_path . "/views-admin.$theme_key.css")) { + elseif (file_exists($theme_path . "/views-admin.$theme_key.css")) { $list[$theme_path . "/views-admin.$theme_key.css"] = array( 'group' => CSS_THEME, ); @@ -54,7 +56,7 @@ function views_ui_get_admin_css() { } $theme_key = isset($themes[$theme_key]->base_theme) ? $themes[$theme_key]->base_theme : ''; } - // Views contains style overrides for the following modules + // Views contains style overrides for the following modules. $module_list = array('contextual', 'advanced_help', 'ctools'); foreach ($module_list as $module) { if (module_exists($module)) { @@ -62,7 +64,6 @@ function views_ui_get_admin_css() { } } - return $list; } @@ -76,11 +77,12 @@ function views_ui_add_admin_css() { } /** - * Check to see if the advanced help module is installed, and if not put up - * a message. + * Check to see if the advanced help module is installed. * - * Only call this function if the user is already in a position for this to - * be useful. + * If not display a message. + * + * Only call this function if the user is already in a position for this to be + * useful. */ function views_ui_check_advanced_help() { if (!variable_get('views_ui_show_advanced_help_warning', TRUE)) { @@ -91,10 +93,18 @@ function views_ui_check_advanced_help() { $filename = db_query_range("SELECT filename FROM {system} WHERE type = 'module' AND name = 'advanced_help'", 0, 1) ->fetchField(); if ($filename && file_exists($filename)) { - drupal_set_message(t('If you enable the advanced help module, Views will provide more and better help. You can disable this message at the Views settings page.', array('@modules' => url('admin/modules'),'@hide' => url('admin/structure/views/settings')))); + drupal_set_message(t('If you enable the advanced help module, Views will provide more and better help. You can disable this message at the Views settings page.', + array( + '@modules' => url('admin/modules'), + '@hide' => url('admin/structure/views/settings'), + ))); } else { - drupal_set_message(t('If you install the advanced help module from !href, Views will provide more and better help. You can disable this message at the Views settings page.', array('!href' => l('http://drupal.org/project/advanced_help', 'http://drupal.org/project/advanced_help'), '@hide' => url('admin/structure/views/settings')))); + drupal_set_message(t('If you install the advanced help module from !href, Views will provide more and better help. You can disable this message at the Views settings page.', + array( + '!href' => l('http://drupal.org/project/advanced_help', 'http://drupal.org/project/advanced_help'), + '@hide' => url('admin/structure/views/settings'), + ))); } } } @@ -133,10 +143,10 @@ function views_ui_preview($view, $display_id, $args = array()) { $view->live_preview = TRUE; $view->views_ui_context = TRUE; - // AJAX happens via $_POST but everything expects exposed data to - // be in GET. Copy stuff but remove ajax-framework specific keys. - // If we're clicking on links in a preview, though, we could actually - // still have some in $_GET, so we use $_REQUEST to ensure we get it all. + // AJAX happens via $_POST but everything expects exposed data to be in + // GET. Copy stuff but remove ajax-framework specific keys. If we're + // clicking on links in a preview, though, we could actually still have + // some in $_GET, so we use $_REQUEST to ensure we get it all. $exposed_input = $_REQUEST; foreach (array('view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', 'ajax_html_ids', 'ajax_page_state', 'form_id', 'form_build_id', 'form_token') as $key) { if (isset($exposed_input[$key])) { @@ -146,14 +156,13 @@ function views_ui_preview($view, $display_id, $args = array()) { $view->set_exposed_input($exposed_input); - if (!$view->set_display($display_id)) { return t('Invalid display id @display', array('@display' => $display_id)); } $view->set_arguments($args); - // Store the current view URL for later use: + // Store the current view URL for later use. if ($view->display_handler->get_option('path')) { $path = $view->get_url(); } @@ -187,7 +196,7 @@ function views_ui_preview($view, $display_id, $args = array()) { if (!empty($view->build_info['query'])) { if ($show_query) { $query = $view->build_info['query']; - // Only the sql default class has a method getArguments. + // Only the SQL default class has a method getArguments. $quoted = array(); if (get_class($view->query) == 'views_plugin_query_default') { @@ -401,8 +410,8 @@ function views_ui_add_form($form, &$form_state) { * Helper form element validator: integer. * * The problem with this is that the function is private so it's not guaranteed - * that it might not be renamed/changed. In the future field.module or something else - * should provide a public validate function. + * that it might not be renamed/changed. In the future field.module or something + * else should provide a public validate function. * * @see _element_validate_integer_positive() */ @@ -414,7 +423,7 @@ function views_element_validate_integer($element, &$form_state) { } /** - * Gets the current value of a #select element, from within a form constructor function. + * Gets the current value of a #select element, from within a form constructor. * * This function is intended for use in highly dynamic forms (in particular the * add view wizard) which are rebuilt in different ways depending on which @@ -434,9 +443,9 @@ function views_element_validate_integer($element, &$form_state) { * the results of this function for any other purpose besides deciding how to * build the next version of the form. * - * @param $form_state - * The standard associative array containing the current state of the form. - * @param $parents + * @param array $form_state + * The standard associative array containing the current state of the form. + * @param array $parents * An array of parent keys that point to the part of the submitted form * values that are expected to contain the element's value (in the case where * this form element was actually submitted). In a simple case (assuming @@ -444,14 +453,14 @@ function views_element_validate_integer($element, &$form_state) { * $form['wrapper']['select'], so that the submitted form values would * normally be found in $form_state['values']['wrapper']['select'], you would * pass array('wrapper', 'select') for this parameter. - * @param $default_value + * @param mixed $default_value * The default value to return if the #select element does not currently have * a proper value set based on the submitted input. - * @param $element + * @param array $element * An array representing the current version of the #select element within * the form. * - * @return + * @return array * The current value of the #select element. A common use for this is to feed * it back into $element['#default_value'] so that the form will be rendered * with the correct value selected. @@ -508,16 +517,16 @@ function views_ui_get_selected($form_state, $parents, $default_value, $element) * mean that the non-JavaScript fallback button does not appear in the correct * place in the form. * - * @param $wrapping_element + * @param array $wrapping_element * The element whose child will server as the AJAX trigger. For example, if * $form['some_wrapper']['triggering_element'] represents the element which * will trigger the AJAX behavior, you would pass $form['some_wrapper'] for * this parameter. - * @param $trigger_key + * @param string $trigger_key * The key within the wrapping element that identifies which of its children * serves as the AJAX trigger. In the above example, you would pass * 'triggering_element' for this parameter. - * @param $refresh_parents + * @param array $refresh_parents * An array of parent keys that point to the part of the form that will be * refreshed by AJAX. For example, if triggering the AJAX behavior should * cause $form['dynamic_content']['section'] to be refreshed, you would pass @@ -581,7 +590,7 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa $wrapping_element[$button_key]['#value'] = t('Update "@title" choice (@number)', array( '@title' => $button_title, '@number' => ++$seen_buttons[$button_title], - )); + )); } // Attach custom data to the triggering element and submit button, so we can @@ -600,7 +609,7 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa } /** - * Processes a non-JavaScript fallback submit button to limit its validation errors. + * Processes a non-JS fallback submit button to limit its validation errors. */ function views_ui_add_limited_validation($element, &$form_state) { // Retrieve the AJAX triggering element so we can determine its parents. (We @@ -634,11 +643,11 @@ function views_ui_add_limited_validation($element, &$form_state) { } /** - * After-build function that adds a wrapper to a form region (for AJAX refreshes). + * After-build function that adds a wrapper to a form region (AJAX refreshes). * * This function inserts a wrapper around the region of the form that needs to - * be refreshed by AJAX, based on information stored in the corresponding - * submit button form element. + * be refreshed by AJAX, based on information stored in the corresponding submit + * button form element. */ function views_ui_add_ajax_wrapper($element, &$form_state) { // Don't add the wrapperif the same one was already inserted on this @@ -682,7 +691,7 @@ function views_ui_ajax_update_form($form, $form_state) { } /** - * Non-Javascript fallback for updating the add view form. + * Non-JavaScript fallback for updating the add view form. */ function views_ui_nojs_submit($form, &$form_state) { $form_state['rebuild'] = TRUE; @@ -721,7 +730,8 @@ function views_ui_add_form_save_submit($form, &$form_state) { if ($display->handler->has_path()) { $one_path = $display->handler->get_option('path'); if (strpos($one_path, '%') === FALSE) { - $form_state['redirect'] = $one_path; // PATH TO THE VIEW IF IT HAS ONE + $form_state['redirect'] = $one_path; + // PATH TO THE VIEW IF IT HAS ONE. return; } } @@ -811,7 +821,7 @@ function views_ui_taxonomy_autocomplete_validate($element, &$form_state) { /** * Theme function; returns basic administrative information about a view. * - * TODO: template + preprocess + * TODO: template + preprocess. */ function theme_views_ui_view_info($variables) { $view = $variables['view']; @@ -832,13 +842,14 @@ function theme_views_ui_view_info($variables) { case t('Overridden'): $type = t('Database overriding code'); + break; } $output = ''; $output .= '' . check_plain($title) . "\n"; $output .= '' . $displays . "\n"; $output .= '' . $type . "\n"; - $output .= '' . t('Type') . ': ' . check_plain($variables['base']). "\n"; + $output .= '' . t('Type') . ': ' . check_plain($variables['base']) . "\n"; return $output; } @@ -876,7 +887,7 @@ function views_ui_break_lock_confirm_submit(&$form, &$form_state) { } /** - * Helper function to return the used display_id for the edit page + * Helper function to return the used display_id for the edit page. * * This function handles access to the display. */ @@ -927,6 +938,9 @@ function views_ui_edit_page($view, $display_id = NULL) { return $build; } +/** + * + */ function views_ui_build_preview($view, $display_id, $render = TRUE) { if (isset($_POST['ajax_html_ids'])) { unset($_POST['ajax_html_ids']); @@ -1000,7 +1014,7 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { $form['#attached']['library'][] = array('system', 'ui.dialog'); $form['#attached']['library'][] = array('system', 'drupal.ajax'); $form['#attached']['library'][] = array('system', 'jquery.form'); - // TODO: This should be getting added to the page when an ajax popup calls + // @todo This should be getting added to the page when an ajax popup calls // for it, instead of having to add it manually here. $form['#attached']['js'][] = 'misc/tabledrag.js'; @@ -1009,12 +1023,16 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { $form['#attached']['js'][] = $module_path . '/js/views-admin.js'; $form['#attached']['js'][] = array( - 'data' => array('views' => array('ajax' => array( - 'id' => '#views-ajax-body', - 'title' => '#views-ajax-title', - 'popup' => '#views-ajax-popup', - 'defaultForm' => views_ui_get_default_ajax_message(), - ))), + 'data' => array( + 'views' => array( + 'ajax' => array( + 'id' => '#views-ajax-body', + 'title' => '#views-ajax-title', + 'popup' => '#views-ajax-popup', + 'defaultForm' => views_ui_get_default_ajax_message(), + ), + ), + ), 'type' => 'setting', ); @@ -1030,7 +1048,9 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { if (isset($view->locked) && is_object($view->locked)) { $form['locked'] = array( '#theme_wrappers' => array('container'), - '#attributes' => array('class' => array('view-locked', 'messages', 'warning')), + '#attributes' => array( + 'class' => array('view-locked', 'messages', 'warning'), + ), '#markup' => t('This view is being edited by user !user, and is therefore locked from editing by others. This lock is !age old. Click here to break this lock.', array('!user' => theme('username', array('account' => user_load($view->locked->uid))), '!age' => format_interval(REQUEST_TIME - $view->locked->updated), '!break' => url('admin/structure/views/view/' . $view->name . '/break-lock'))), ); } @@ -1043,7 +1063,9 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { $form['changed'] = array( '#theme_wrappers' => array('container'), - '#attributes' => array('class' => array('view-changed', 'messages', 'warning')), + '#attributes' => array( + 'class' => array('view-changed', 'messages', 'warning'), + ), '#markup' => $message, ); if (empty($view->changed)) { @@ -1072,7 +1094,7 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { $form['actions']['save'] = array( '#type' => 'submit', '#value' => t('Save'), - // Taken from the "old" UI. @TODO: Review and rename. + // Taken from the "old" UI. @todo: Review and rename. '#validate' => array('views_ui_edit_view_form_validate'), '#submit' => array('views_ui_edit_view_form_submit'), ); @@ -1083,7 +1105,8 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { ); $form['displays'] = array( - '#prefix' => '' . t('Displays') . '
' . "\n" . '', + '#prefix' => '', '#tree' => TRUE, ); - $cache = $this->get_option('cache'); - $form['cache']['type'] = array( + $form['cache']['type'] = array( '#type' => 'radios', '#options' => views_fetch_plugin_names('cache', NULL, array($this->view->base_table)), '#default_value' => $cache['type'], ); - $cache_plugin = views_fetch_plugin_data('cache', $cache['type']); if (!empty($cache_plugin['uses options'])) { $form['markup'] = array( @@ -1664,6 +1739,7 @@ class views_plugin_display extends views_plugin { ); } break; + case 'cache_options': $cache = $this->get_option('cache'); $plugin = $this->get_plugin('cache'); @@ -1675,7 +1751,6 @@ class views_plugin_display extends views_plugin { if (!empty($plugin->definition['module'])) { $form['#help_module'] = $plugin->definition['module']; } - $form['cache_options'] = array( '#tree' => TRUE, ); @@ -1686,6 +1761,7 @@ class views_plugin_display extends views_plugin { $plugin->options_form($form['cache_options'], $form_state); } break; + case 'query': $query_options = $this->get_option('query'); $plugin_name = $query_options['type']; @@ -1699,7 +1775,6 @@ class views_plugin_display extends views_plugin { if (!empty($this->view->query->definition['module'])) { $form['#help_module'] = $this->view->query->definition['module']; } - $form['query'] = array( '#tree' => TRUE, 'type' => array( @@ -1710,10 +1785,10 @@ class views_plugin_display extends views_plugin { '#tree' => TRUE, ), ); - $this->view->query->options_form($form['query']['options'], $form_state); } break; + case 'field_language': $form['#title'] .= t('Field Language'); @@ -1756,10 +1831,11 @@ class views_plugin_display extends views_plugin { $form['field_language']['#markup'] = t("You don't have translatable entity types."); } break; + case 'style_plugin': $form['#title'] .= t('How should this view be styled'); $form['#help_topic'] = 'style'; - $form['style_plugin'] = array( + $form['style_plugin'] = array( '#type' => 'radios', '#options' => views_fetch_plugin_names('style', $this->get_style_type(), array($this->view->base_table)), '#default_value' => $this->get_option('style_plugin'), @@ -1772,8 +1848,8 @@ class views_plugin_display extends views_plugin { '#markup' => '' . t('Displays') . "
\n" + . '', '#suffix' => '', ); @@ -1093,8 +1116,8 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { if ($display_id) { $form_state['display_id'] = $display_id; - // The part of the page where editing will take place. - // This element is the ctools collapsible-div container for the display edit elements. + // The part of the page where editing will take place. This element is the + // CTools collapsible-div container for the display edit elements. $form['displays']['settings'] = array( '#theme_wrappers' => array('container'), '#attributes' => array( @@ -1107,7 +1130,8 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { '#id' => 'edit-display-settings', ); $display_title = views_ui_get_display_label($view, $display_id, FALSE); - // Add a handle for the ctools collapsible-div. The handle is the title of the display + // Add a handle for the ctools collapsible-div. The handle is the title of + // the display. $form['displays']['settings']['tab_title']['#markup'] = '' . t('@display_title details', array('@display_title' => ucwords($display_title))) . '
'; // Add a text that the display is disabled. if (!empty($view->display[$display_id]->handler)) { @@ -1116,8 +1140,8 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { $form['displays']['settings']['disabled']['#markup'] = t('This display is disabled.'); } } - // The ctools collapsible-div content - $form['displays']['settings']['settings_content']= array( + // The ctools collapsible-div content. + $form['displays']['settings']['settings_content'] = array( '#theme_wrappers' => array('container'), '#id' => 'edit-display-settings-content', '#attributes' => array( @@ -1126,7 +1150,7 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) { ), ), ); - // Add the edit display content + // Add the edit display content. $form['displays']['settings']['settings_content']['tab_content'] = views_ui_get_display_tab($view, $display_id); $form['displays']['settings']['settings_content']['tab_content']['#theme_wrappers'] = array('container'); $form['displays']['settings']['settings_content']['tab_content']['#attributes'] = array('class' => array('views-display-tab')); @@ -1172,7 +1196,7 @@ function views_ui_preview_form($form, &$form_state, $view, $display_id = 'defaul $form_state['no_cache'] = TRUE; $form_state['view'] = $view; - $form['#attributes'] = array('class' => array('clearfix',)); + $form['#attributes'] = array('class' => array('clearfix')); // Add a checkbox controlling whether or not this display auto-previews. $form['live_preview'] = array( @@ -1182,16 +1206,16 @@ function views_ui_preview_form($form, &$form_state, $view, $display_id = 'defaul '#default_value' => variable_get('views_ui_always_live_preview', TRUE), ); - // Add the arguments textfield + // Add the arguments textfield. $form['view_args'] = array( '#type' => 'textfield', '#title' => t('Preview with contextual filters:'), '#description' => t('Separate contextual filter values with a "/". For example, %example.', array('%example' => '40/12/10')), '#id' => 'preview-args', -// '#attributes' => array('class' => array('ctools-auto-submit')), + // '#attributes' => array('class' => array('ctools-auto-submit')), ); - // Add the preview button + // Add the preview button. $form['button'] = array( '#type' => 'submit', '#value' => t('Update preview'), @@ -1211,10 +1235,10 @@ function views_ui_preview_form($form, &$form_state, $view, $display_id = 'defaul // Make ENTER in arguments textfield (and other controls) submit the form // as this button, not the Save button. // @todo This only works for JS users. To make this work for nojs users, - // we may need to split Preview into a separate form. + // we may need to split Preview into a separate form. '#process' => array_merge(array('views_ui_default_button'), element_info_property('submit', '#process', array())), ); - $form['#action'] = url('admin/structure/views/view/' . $view->name .'/preview/' . $display_id); + $form['#action'] = url('admin/structure/views/view/' . $view->name . '/preview/' . $display_id); return $form; } @@ -1227,15 +1251,15 @@ function views_ui_render_display_top($view, $display_id) { $element['#attributes']['class'] = array('views-display-top', 'clearfix'); $element['#attributes']['id'] = array('views-display-top'); - // Extra actions for the display + // Extra actions for the display. $element['extra_actions'] = array( '#theme' => 'links__ctools_dropbutton', '#attributes' => array( - 'id' => 'views-display-extra-actions', - 'class' => array( - 'horizontal', 'right', 'links', 'actions', - ), + 'id' => 'views-display-extra-actions', + 'class' => array( + 'horizontal', 'right', 'links', 'actions', ), + ), '#links' => array( 'edit-details' => array( 'title' => t('edit view name/description'), @@ -1310,6 +1334,9 @@ function views_ui_render_display_top($view, $display_id) { return $element; } +/** + * + */ function views_ui_get_default_ajax_message() { return ' '; } @@ -1372,11 +1399,11 @@ function views_ui_edit_form_submit_delete_display($form, &$form_state) { * Submit handler to add a restore a removed display to a view. */ function views_ui_edit_form_submit_undo_delete_display($form, &$form_state) { - // Create the new display + // Create the new display. $id = $form_state['display_id']; $form_state['view']->display[$id]->deleted = FALSE; - // Store in cache + // Store in cache. views_ui_cache_set($form_state['view']); // Redirect to the top-level edit page. @@ -1388,10 +1415,10 @@ function views_ui_edit_form_submit_undo_delete_display($form, &$form_state) { */ function views_ui_edit_form_submit_enable_display($form, &$form_state) { $id = $form_state['display_id']; - // set_option doesn't work because this would might affect upper displays + // set_option doesn't work because this would might affect upper displays. $form_state['view']->display[$id]->handler->set_option('enabled', TRUE); - // Store in cache + // Store in cache. views_ui_cache_set($form_state['view']); // Redirect to the top-level edit page. @@ -1405,7 +1432,7 @@ function views_ui_edit_form_submit_disable_display($form, &$form_state) { $id = $form_state['display_id']; $form_state['view']->display[$id]->handler->set_option('enabled', FALSE); - // Store in cache + // Store in cache. views_ui_cache_set($form_state['view']); // Redirect to the top-level edit page. @@ -1459,10 +1486,10 @@ function views_ui_edit_form_submit_delay_destination($form, &$form_state) { * * @param view $view * The view which will be edited. - * @param $display_id + * @param string $display_id * The display_id which is edited on the current request. */ -function views_ui_edit_page_display_tabs($view, $display_id = NULL) { +function views_ui_edit_page_display_tabs(view $view, $display_id = NULL) { $tabs = array(); // Create a tab for each display. @@ -1483,7 +1510,8 @@ function views_ui_edit_page_display_tabs($view, $display_id = NULL) { } } - // If the default display isn't supposed to be shown, don't display its tab, unless it's the only display. + // If the default display isn't supposed to be shown, don't display its tab, + // unless it's the only display. if ((!views_ui_show_default_display($view) && $display_id != 'default') && count($tabs) > 1) { $tabs['default']['#access'] = FALSE; } @@ -1526,7 +1554,7 @@ function views_ui_get_display_tab($view, $display_id) { // page. if (empty($display->handler)) { $title = isset($display->display_title) ? $display->display_title : t('Invalid'); - // @TODO: Improved UX for the case where a plugin is missing. + // @todo: Improved UX for the case where a plugin is missing. $build['#markup'] = t("Error: Display @display refers to a plugin named '@plugin', but that plugin is not available.", array('@display' => $display->id, '@plugin' => $display->display_plugin)); } // Build the content of the edit page. @@ -1542,8 +1570,10 @@ function views_ui_get_display_tab($view, $display_id) { /** * Helper function to get the display details section of the edit UI. * - * @param $view - * @param $display + * @param view $view + * The full view object. + * @param object $display + * The display object to work with. * * @return array * A renderable page build array. @@ -1552,35 +1582,40 @@ function views_ui_get_display_tab_details($view, $display) { $display_title = views_ui_get_display_label($view, $display->id, FALSE); $build = array( '#theme_wrappers' => array('container'), - '#attributes' => array('id' => 'edit-display-settings-details',), + '#attributes' => array('id' => 'edit-display-settings-details'), ); $plugin = views_fetch_plugin_data('display', $view->display[$display->id]->display_plugin); - // The following is for display purposes only. We need to determine if there is more than one button and wrap - // the buttons in a .ctools-dropbutton class if more than one is present. Otherwise, we'll just wrap the - // actions in the .ctools-button class. - $isDisplayDeleted = !empty($display->deleted); - $isDeletable = empty($plugin['no remove']); + // The following is for display purposes only. We need to determine if there + // is more than one button and wrap the buttons in a .ctools-dropbutton class + // if more than one is present. Otherwise, we'll just wrap the actions in the + // .ctools-button class. + $is_display_deleted = !empty($display->deleted); + $is_deletable = empty($plugin['no remove']); // The master display cannot be cloned. - $isDefault = $display->id == 'default'; + $is_default = $display->id == 'default'; // @todo: Figure out why get_option doesn't work here. - $isEnabled = $display->handler->get_option('enabled'); + $is_enabled = $display->handler->get_option('enabled'); - if (!$isDisplayDeleted && $isDeletable && !$isDefault) { - $prefix = ' ', ); } - break; + case 'access_options': $access = $this->get_option('access'); $plugin = $this->get_plugin('access'); @@ -1629,7 +1706,6 @@ class views_plugin_display extends views_plugin { if (!empty($plugin->definition['module'])) { $form['#help_module'] = $plugin->definition['module']; } - $form['access_options'] = array( '#tree' => TRUE, ); @@ -1640,6 +1716,7 @@ class views_plugin_display extends views_plugin { $plugin->options_form($form['access_options'], $form_state); } break; + case 'cache': $form['#title'] .= t('Caching'); $form['cache'] = array( @@ -1647,14 +1724,12 @@ class views_plugin_display extends views_plugin { '#suffix' => '' . t('You may also adjust the !settings for the currently selected style.', array('!settings' => $this->option_link(t('settings'), 'style_options'))) . '', ); } - break; + case 'style_options': $form['#title'] .= t('Style options'); $style = TRUE; @@ -1784,7 +1860,7 @@ class views_plugin_display extends views_plugin { if (!isset($name)) { $name = $this->get_option('row_plugin'); } - // if row, $style will be empty. + // If row, $style will be empty. if (empty($style)) { $form['#title'] .= t('Row style options'); $type = 'row_plugin'; @@ -1803,10 +1879,11 @@ class views_plugin_display extends views_plugin { $plugin->options_form($form[$form_state['section']], $form_state); } break; + case 'row_plugin': $form['#title'] .= t('How should each row in this view be styled'); $form['#help_topic'] = 'style-row'; - $form['row_plugin'] = array( + $form['row_plugin'] = array( '#type' => 'radios', '#options' => views_fetch_plugin_names('row', $this->get_style_type(), array($this->view->base_table)), '#default_value' => $this->get_option('row_plugin'), @@ -1818,8 +1895,8 @@ class views_plugin_display extends views_plugin { '#markup' => '' . t('You may also adjust the !settings for the currently selected row style.', array('!settings' => $this->option_link(t('settings'), 'row_options'))) . '', ); } - break; + case 'link_display': $form['#title'] .= t('Which display to use for path'); foreach ($this->view->display as $display_id => $display) { @@ -1838,14 +1915,14 @@ class views_plugin_display extends views_plugin { } $options = array(); - $count = 0; // This lets us prepare the key as we want it printed. + // This lets us prepare the key as we want it printed. + $count = 0; foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) { $options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name())); $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name())); } - // Default text. - // We have some options, so make a list. + // Default text. We have some options, so make a list. $output = ''; if (!empty($options)) { $output = t('The following tokens are available for this link.
'); @@ -1858,7 +1935,7 @@ class views_plugin_display extends views_plugin { $output .= theme('item_list', array( 'items' => $items, - 'type' => $type + 'type' => $type, )); } } @@ -1872,6 +1949,7 @@ class views_plugin_display extends views_plugin { '#dependency' => array('radio:link_display' => array('custom_url')), ); break; + case 'analyze-theme': $form['#title'] .= t('Theming information'); $form['#help_topic'] = 'analyze-theme'; @@ -1902,7 +1980,7 @@ class views_plugin_display extends views_plugin { // The base themes should be initialized in the right order. $base_theme = array_reverse($base_theme); - // This code is copied directly from _drupal_theme_initialize() + // This code is copied directly from _drupal_theme_initialize(). $theme_engine = NULL; // Initialize the theme. @@ -1919,14 +1997,14 @@ class views_plugin_display extends views_plugin { } } else { - // include non-engine theme files + // Include non-engine theme files. foreach ($base_theme as $base) { // Include the theme file or the engine. if (!empty($base->owner)) { include_once DRUPAL_ROOT . '/' . $base->owner; } } - // and our theme gets one too. + // And our theme gets one too. if (!empty($theme->owner)) { include_once DRUPAL_ROOT . '/' . $theme->owner; } @@ -1934,8 +2012,8 @@ class views_plugin_display extends views_plugin { $this->theme_registry = _theme_load_registry($theme, $base_theme, $theme_engine); } - // If there's a theme engine involved, we also need to know its extension - // so we can give the proper filename. + // If there's a theme engine involved, we also need to know its + // extension so we can give the proper filename. $this->theme_extension = '.tpl.php'; if (isset($theme_engine)) { $extension_function = $theme_engine . '_extension'; @@ -1945,15 +2023,15 @@ class views_plugin_display extends views_plugin { } $funcs = array(); - // Get theme functions for the display. Note that some displays may - // not have themes. The 'feed' display, for example, completely - // delegates to the style. + // Get theme functions for the display. Note that some displays may not + // have themes. The 'feed' display, for example, completely delegates to + // the style. if (!empty($this->definition['theme'])) { - $funcs[] = $this->option_link(t('Display output'), 'analyze-theme-display') . ': ' . $this->format_themes($this->theme_functions()); + $funcs[] = $this->option_link(t('Display output'), 'analyze-theme-display') . ': ' . $this->format_themes($this->theme_functions()); $themes = $this->additional_theme_functions(); if ($themes) { foreach ($themes as $theme) { - $funcs[] = $this->option_link(t('Alternative display output'), 'analyze-theme-display') . ': ' . $this->format_themes($theme); + $funcs[] = $this->option_link(t('Alternative display output'), 'analyze-theme-display') . ': ' . $this->format_themes($theme); } } } @@ -1964,7 +2042,7 @@ class views_plugin_display extends views_plugin { $themes = $plugin->additional_theme_functions(); if ($themes) { foreach ($themes as $theme) { - $funcs[] = $this->option_link(t('Alternative style'), 'analyze-theme-style') . ': ' . $this->format_themes($theme); + $funcs[] = $this->option_link(t('Alternative style'), 'analyze-theme-style') . ': ' . $this->format_themes($theme); } } @@ -1975,7 +2053,7 @@ class views_plugin_display extends views_plugin { $themes = $row_plugin->additional_theme_functions(); if ($themes) { foreach ($themes as $theme) { - $funcs[] = $this->option_link(t('Alternative row style'), 'analyze-theme-row') . ': ' . $this->format_themes($theme); + $funcs[] = $this->option_link(t('Alternative row style'), 'analyze-theme-row') . ': ' . $this->format_themes($theme); } } } @@ -2042,6 +2120,7 @@ class views_plugin_display extends views_plugin { $form_state['ok_button'] = TRUE; break; + case 'analyze-theme-display': $form['#title'] .= t('Theming information (display)'); $output = '' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '
'; @@ -2067,6 +2146,7 @@ class views_plugin_display extends views_plugin { $form_state['ok_button'] = TRUE; break; + case 'analyze-theme-style': $form['#title'] .= t('Theming information (style)'); $output = '' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '
'; @@ -2094,6 +2174,7 @@ class views_plugin_display extends views_plugin { $form_state['ok_button'] = TRUE; break; + case 'analyze-theme-row': $form['#title'] .= t('Theming information (row style)'); $output = '' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '
'; @@ -2121,14 +2202,15 @@ class views_plugin_display extends views_plugin { $form_state['ok_button'] = TRUE; break; + case 'analyze-theme-field': $form['#title'] .= t('Theming information (row style)'); $output = '' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '
'; $output .= '' . t('This is the default theme template used for this row style.') . '
'; - // Field templates aren't registered the normal way...and they're always - // this one, anyhow. + // Field templates aren't registered the normal way... and they're + // always this one, anyhow. $output .= '' . check_plain(file_get_contents(drupal_get_path('module', 'views') . '/theme/views-view-field.tpl.php')) . ''; $form['analysis'] = array( @@ -2148,6 +2230,7 @@ class views_plugin_display extends views_plugin { '#default_value' => $this->get_option('exposed_block') ? 1 : 0, ); break; + case 'exposed_form': $form['#title'] .= t('Exposed Form'); $form['exposed_form'] = array( @@ -2157,7 +2240,7 @@ class views_plugin_display extends views_plugin { ); $exposed_form = $this->get_option('exposed_form'); - $form['exposed_form']['type'] = array( + $form['exposed_form']['type'] = array( '#type' => 'radios', '#options' => views_fetch_plugin_names('exposed_form', NULL, array($this->view->base_table)), '#default_value' => $exposed_form['type'], @@ -2172,6 +2255,7 @@ class views_plugin_display extends views_plugin { ); } break; + case 'exposed_form_options': $plugin = $this->get_plugin('exposed_form'); $form['#title'] .= t('Exposed form options'); @@ -2189,6 +2273,7 @@ class views_plugin_display extends views_plugin { $plugin->options_form($form['exposed_form_options'], $form_state); } break; + case 'pager': $form['#title'] .= t('Select which pager, if any, to use for this view'); $form['pager'] = array( @@ -2198,7 +2283,7 @@ class views_plugin_display extends views_plugin { ); $pager = $this->get_option('pager'); - $form['pager']['type'] = array( + $form['pager']['type'] = array( '#type' => 'radios', '#options' => views_fetch_plugin_names('pager', empty($this->definition['use pager']) ? 'basic' : NULL, array($this->view->base_table)), '#default_value' => $pager['type'], @@ -2212,8 +2297,8 @@ class views_plugin_display extends views_plugin { '#markup' => t('You may also adjust the !settings for the currently selected pager.', array('!settings' => $this->option_link(t('settings'), 'pager_options'))), ); } - break; + case 'pager_options': $plugin = $this->get_plugin('pager'); $form['#title'] .= t('Pager options'); @@ -2241,7 +2326,7 @@ class views_plugin_display extends views_plugin { /** * Format a list of theme templates for output by the theme info helper. */ - function format_themes($themes) { + public function format_themes($themes) { $registry = $this->theme_registry; $extension = $this->theme_extension; @@ -2253,7 +2338,7 @@ class views_plugin_display extends views_plugin { $template_path = isset($registry[$theme]['path']) ? $registry[$theme]['path'] . '/' : './'; if (file_exists($template_path . $template)) { $hint = t('File found in folder @template-path', array('@template-path' => $template_path)); - $template = '' . $template . ''; + $template = '' . $template . ''; } else { $template = '' . $template . ' ' . t('(File not found, in folder @template-path)', array('@template-path' => $template_path)) . ''; @@ -2263,25 +2348,27 @@ class views_plugin_display extends views_plugin { $fixed[] = $template; } - return implode(', ', array_reverse($fixed)); + return theme('item_list', array('items' => array_reverse($fixed))); } /** * Validate the options form. */ - function options_validate(&$form, &$form_state) { + public function options_validate(&$form, &$form_state) { switch ($form_state['section']) { case 'display_title': if (empty($form_state['values']['display_title'])) { form_error($form['display_title'], t('Display title may not be empty.')); } break; + case 'css_class': $css_class = $form_state['values']['css_class']; if (preg_match('/[^a-zA-Z0-9-_ ]/', $css_class)) { form_error($form['css_class'], t('CSS classes must be alphanumeric or dashes only.')); } - break; + break; + case 'display_id': if ($form_state['values']['display_id']) { if (preg_match('/[^a-z0-9_]/', $form_state['values']['display_id'])) { @@ -2295,38 +2382,44 @@ class views_plugin_display extends views_plugin { } } break; + case 'style_options': $style = TRUE; case 'row_options': - // if row, $style will be empty. + // If row, $style will be empty. $plugin = $this->get_plugin(empty($style) ? 'row' : 'style'); if ($plugin) { $plugin->options_validate($form[$form_state['section']], $form_state); } break; + case 'access_options': $plugin = $this->get_plugin('access'); if ($plugin) { $plugin->options_validate($form['access_options'], $form_state); } break; + case 'query': if ($this->view->query) { $this->view->query->options_validate($form['query'], $form_state); } break; + case 'cache_options': $plugin = $this->get_plugin('cache'); if ($plugin) { $plugin->options_validate($form['cache_options'], $form_state); } break; + case 'exposed_form_options': $plugin = $this->get_plugin('exposed_form'); if ($plugin) { $plugin->options_validate($form['exposed_form_options'], $form_state); } break; + case 'pager_options': $plugin = $this->get_plugin('pager'); if ($plugin) { @@ -2342,9 +2435,10 @@ class views_plugin_display extends views_plugin { /** * Perform any necessary changes to the form values prior to storage. + * * There is no need for this function to actually store the data. */ - function options_submit(&$form, &$form_state) { + public function options_submit(&$form, &$form_state) { // Not sure I like this being here, but it seems (?) like a logical place. $cache_plugin = $this->get_plugin('cache'); if ($cache_plugin) { @@ -2358,10 +2452,12 @@ class views_plugin_display extends views_plugin { $this->display->new_id = $form_state['values']['display_id']; } break; + case 'display_title': $this->display->display_title = $form_state['values']['display_title']; $this->set_option('display_description', $form_state['values']['display_description']); break; + case 'access': $access = $this->get_option('access'); if ($access['type'] != $form_state['values']['access']['type']) { @@ -2374,8 +2470,8 @@ class views_plugin_display extends views_plugin { } } } - break; + case 'access_options': $plugin = views_get_plugin('access', $form_state['values'][$section]['type']); if ($plugin) { @@ -2383,6 +2479,7 @@ class views_plugin_display extends views_plugin { $this->set_option('access', $form_state['values'][$section]); } break; + case 'cache': $cache = $this->get_option('cache'); if ($cache['type'] != $form_state['values']['cache']['type']) { @@ -2395,8 +2492,8 @@ class views_plugin_display extends views_plugin { } } } - break; + case 'cache_options': $plugin = views_get_plugin('cache', $form_state['values'][$section]['type']); if ($plugin) { @@ -2404,6 +2501,7 @@ class views_plugin_display extends views_plugin { $this->set_option('cache', $form_state['values'][$section]); } break; + case 'query': $plugin = $this->get_plugin('query'); if ($plugin) { @@ -2419,15 +2517,18 @@ class views_plugin_display extends views_plugin { case 'display_comment': $this->set_option($section, $form_state['values'][$section]); break; + case 'field_language': $this->set_option('field_language', $form_state['values']['field_language']); $this->set_option('field_language_add_to_query', $form_state['values']['field_language_add_to_query']); break; + case 'use_ajax': case 'hide_attachment_summary': case 'hide_admin_links': - $this->set_option($section, (bool)$form_state['values'][$section]); + $this->set_option($section, (bool) $form_state['values'][$section]); break; + case 'use_more': $this->set_option($section, intval($form_state['values'][$section])); $this->set_option('use_more_always', !intval($form_state['values']['use_more_always'])); @@ -2436,9 +2537,11 @@ class views_plugin_display extends views_plugin { case 'distinct': $this->set_option($section, $form_state['values'][$section]); break; + case 'group_by': $this->set_option($section, $form_state['values'][$section]); break; + case 'row_plugin': // This if prevents resetting options to default if they don't change // the plugin. @@ -2448,13 +2551,14 @@ class views_plugin_display extends views_plugin { $this->set_option($section, $form_state['values'][$section]); $this->set_option('row_options', array()); - // send ajax form to options page if we use it. + // Send ajax form to options page if we use it. if (!empty($plugin->definition['uses options'])) { views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('row_options')); } } } break; + case 'style_plugin': // This if prevents resetting options to default if they don't change // the plugin. @@ -2463,26 +2567,29 @@ class views_plugin_display extends views_plugin { if ($plugin) { $this->set_option($section, $form_state['values'][$section]); $this->set_option('style_options', array()); - // send ajax form to options page if we use it. + // Send ajax form to options page if we use it. if (!empty($plugin->definition['uses options'])) { views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('style_options')); } } } break; + case 'style_options': $style = TRUE; case 'row_options': - // if row, $style will be empty. + // If row, $style will be empty. $plugin = $this->get_plugin(empty($style) ? 'row' : 'style'); if ($plugin) { $plugin->options_submit($form['options'][$section], $form_state); } $this->set_option($section, $form_state['values'][$section]); break; + case 'exposed_block': $this->set_option($section, (bool) $form_state['values'][$section]); break; + case 'exposed_form': $exposed_form = $this->get_option('exposed_form'); if ($exposed_form['type'] != $form_state['values']['exposed_form']['type']) { @@ -2495,8 +2602,8 @@ class views_plugin_display extends views_plugin { } } } - break; + case 'exposed_form_options': $plugin = $this->get_plugin('exposed_form'); if ($plugin) { @@ -2506,6 +2613,7 @@ class views_plugin_display extends views_plugin { $this->set_option('exposed_form', $exposed_form); } break; + case 'pager': $pager = $this->get_option('pager'); if ($pager['type'] != $form_state['values']['pager']['type']) { @@ -2522,8 +2630,8 @@ class views_plugin_display extends views_plugin { } } } - break; + case 'pager_options': $plugin = $this->get_plugin('pager'); if ($plugin) { @@ -2543,7 +2651,7 @@ class views_plugin_display extends views_plugin { /** * If override/revert was clicked, perform the proper toggle. */ - function options_override($form, &$form_state) { + public function options_override($form, &$form_state) { $this->set_override($form_state['section']); } @@ -2554,10 +2662,10 @@ class views_plugin_display extends views_plugin { * Which option should be marked as overridden, for example "filters". * @param bool $new_state * Select the new state of the option. - * - TRUE: Revert to default. - * - FALSE: Mark it as overridden. + * - TRUE: Revert to default. + * - FALSE: Mark it as overridden. */ - function set_override($section, $new_state = NULL) { + public function set_override($section, $new_state = NULL) { $options = $this->defaultable_sections($section); if (!$options) { return; @@ -2575,7 +2683,7 @@ class views_plugin_display extends views_plugin { unset($this->display->display_options[$option]); } else { - // copy existing values into our display. + // Copy existing values into our display. $this->options[$option] = $this->get_option($option); $this->display->display_options[$option] = $this->options[$option]; } @@ -2587,28 +2695,29 @@ class views_plugin_display extends views_plugin { /** * Inject anything into the query that the display handler needs. */ - function query() { + public function query() { foreach ($this->extender as $extender) { $extender->query(); } } /** - * Not all display plugins will support filtering + * Not all display plugins will support filtering. */ - function render_filters() { } + public function render_filters() { + } /** * Not all display plugins will suppert pager rendering. */ - function render_pager() { + public function render_pager() { return TRUE; } /** - * Render the 'more' link + * Render the 'more' link. */ - function render_more_link() { + public function render_more_link() { if ($this->use_more() && ($this->use_more_always() || (!empty($this->view->query->pager) && $this->view->query->pager->has_more_records()))) { $path = $this->get_path(); @@ -2645,12 +2754,16 @@ class views_plugin_display extends views_plugin { $path = check_url(url($path, $url_options)); - return theme($theme, array('more_url' => $path, 'new_window' => $this->use_more_open_new_window(), 'link_text' => check_plain($this->use_more_text()), 'view' => $this->view)); + return theme($theme, array( + 'more_url' => $path, + 'new_window' => $this->use_more_open_new_window(), + 'link_text' => check_plain($this->use_more_text()), + 'view' => $this->view, + )); } } } - /** * Legacy functions. */ @@ -2658,7 +2771,7 @@ class views_plugin_display extends views_plugin { /** * Render the header of the view. */ - function render_header() { + public function render_header() { $empty = !empty($this->view->result); return $this->render_area('header', $empty); } @@ -2666,33 +2779,43 @@ class views_plugin_display extends views_plugin { /** * Render the footer of the view. */ - function render_footer() { + public function render_footer() { $empty = !empty($this->view->result); return $this->render_area('footer', $empty); } - function render_empty() { + /** + * + */ + public function render_empty() { return $this->render_area('empty'); } /** * If this display creates a block, implement one of these. */ - function hook_block_list($delta = 0, $edit = array()) { return array(); } + public function hook_block_list($delta = 0, $edit = array()) { + return array(); + } /** * If this display creates a page with a menu item, implement it here. */ - function hook_menu() { return array(); } + public function hook_menu() { + return array(); + } /** * Render this display. */ - function render() { + public function render() { return theme($this->theme_functions(), array('view' => $this->view)); } - function render_area($area, $empty = FALSE) { + /** + * + */ + public function render_area($area, $empty = FALSE) { $return = ''; foreach ($this->get_handlers($area) as $area) { $return .= $area->render($empty); @@ -2700,11 +2823,10 @@ class views_plugin_display extends views_plugin { return $return; } - /** * Determine if the user has access to this display of the view. */ - function access($account = NULL) { + public function access($account = NULL) { if (!isset($account)) { global $user; $account = $user; @@ -2720,16 +2842,17 @@ class views_plugin_display extends views_plugin { return $plugin->access($account); } - // fallback to all access if no plugin. + // Fallback to all access if no plugin. return TRUE; } /** - * Set up any variables on the view prior to execution. These are separated - * from execute because they are extremely common and unlikely to be - * overridden on an individual display. + * Set up any variables on the view prior to execution. + * + * These are separated from execute because they are extremely common and + * unlikely to be overridden on an individual display. */ - function pre_execute() { + public function pre_execute() { $this->view->set_use_ajax($this->use_ajax()); if ($this->use_more() && !$this->use_more_always()) { $this->view->get_total_rows = TRUE; @@ -2755,27 +2878,35 @@ class views_plugin_display extends views_plugin { * * The base class cannot be executed. */ - function execute() { } + public function execute() { + } /** - * Fully render the display for the purposes of a live preview or - * some other AJAXy reason. + * Fully render the display. + * + * Used for the purposes of a live preview or some other AJAXy reason. */ - function preview() { return $this->view->render(); } + public function preview() { + return $this->view->render(); + } /** - * Displays can require a certain type of style plugin. By default, they will - * be 'normal'. + * Displays can require a certain type of style plugin. + * + * By default, they will be 'normal'. */ - function get_style_type() { return 'normal'; } + public function get_style_type() { + return 'normal'; + } /** * Make sure the display and all associated handlers are valid. * * @return - * Empty array if the display is valid; an array of error strings if it is not. + * Empty array if the display is valid; an array of error strings if it is + * not. */ - function validate() { + public function validate() { $errors = array(); // Make sure displays that use fields HAVE fields. if ($this->uses_fields()) { @@ -2795,7 +2926,7 @@ class views_plugin_display extends views_plugin { $errors[] = t('Display "@display" uses a path but the path is undefined.', array('@display' => $this->display->display_title)); } - // Validate style plugin + // Validate style plugin. $style = $this->get_plugin(); if (empty($style)) { $errors[] = t('Display "@display" has an invalid style plugin.', array('@display' => $this->display->display_title)); @@ -2814,7 +2945,7 @@ class views_plugin_display extends views_plugin { $errors = array_merge($errors, $result); } - // Validate handlers + // Validate handlers. foreach (views_object_types() as $type => $info) { foreach ($this->get_handlers($type) as $handler) { $result = $handler->validate(); @@ -2837,9 +2968,8 @@ class views_plugin_display extends views_plugin { * * @return bool * Returns whether the identifier is unique on all handlers. - * */ - function is_identifier_unique($id, $identifier) { + public function is_identifier_unique($id, $identifier) { foreach (views_object_types() as $type => $info) { foreach ($this->get_handlers($type) as $key => $handler) { if ($handler->can_expose() && $handler->is_exposed()) { @@ -2862,7 +2992,7 @@ class views_plugin_display extends views_plugin { /** * Provide the block system with any exposed widget blocks for this display. */ - function get_special_blocks() { + public function get_special_blocks() { $blocks = array(); if ($this->uses_exposed_form_in_block()) { @@ -2881,9 +3011,9 @@ class views_plugin_display extends views_plugin { /** * Render any special blocks provided for this display. */ - function view_special_blocks($type) { + public function view_special_blocks($type) { if ($type == '-exp') { - // avoid interfering with the admin forms. + // Avoid interfering with the admin forms. if (arg(0) == 'admin' && arg(1) == 'structure' && arg(2) == 'views') { return; } @@ -2901,11 +3031,13 @@ class views_plugin_display extends views_plugin { /** * Override of export_option() * - * Because displays do not want to export options that are NOT overridden from the - * default display, we need some special handling during the export process. + * Because displays do not want to export options that are NOT overridden from + * the default display, we need some special handling during the export + * process. */ - function export_option($indent, $prefix, $storage, $option, $definition, $parents) { - // The $prefix is wrong because we store our actual options a little differently: + public function export_option($indent, $prefix, $storage, $option, $definition, $parents) { + // The $prefix is wrong because we store our actual options a little + // differently. $prefix = '$handler->display->display_options'; $output = ''; if (!$parents && !$this->is_default_display()) { @@ -2914,8 +3046,8 @@ class views_plugin_display extends views_plugin { return; } - // If this is not defaulted and is overrideable, flip the switch to say this - // is overridden. + // If this is not defaulted and is overrideable, flip the switch to say + // this is overridden. if ($this->defaultable_sections($option)) { $output .= $indent . $prefix . "['defaults']['$option'] = FALSE;\n"; } @@ -2928,16 +3060,16 @@ class views_plugin_display extends views_plugin { /** * Special method to export items that have handlers. * - * This method was specified in the option_definition() as the method to utilize to - * export fields, filters, sort criteria, relationships and arguments. This passes - * the export off to the individual handlers so that they can export themselves - * properly. + * This method was specified in the option_definition() as the method to + * utilize to export fields, filters, sort criteria, relationships and + * arguments. This passes the export off to the individual handlers so that + * they can export themselves properly. */ - function export_handler($indent, $prefix, $storage, $option, $definition, $parents) { + public function export_handler($indent, $prefix, $storage, $option, $definition, $parents) { $output = ''; - // cut the 's' off because the data is stored as the plural form but we need - // the singular form. Who designed that anyway? Oh yeah, I did. :( + // Cut the 's' off because the data is stored as the plural form but we need + // the singular form. if ($option != 'header' && $option != 'footer' && $option != 'empty') { $type = substr($option, 0, -1); } @@ -2952,9 +3084,9 @@ class views_plugin_display extends views_plugin { else { $handler_type = $type; } - // If aggregation is on, the group type might override the actual - // handler that is in use. This piece of code checks that and, - // if necessary, sets the override handler. + // If aggregation is on, the group type might override the actual handler + // that is in use. This piece of code checks that and, if necessary, sets + // the override handler. $override = NULL; if ($this->use_group_by() && !empty($info['group_type'])) { if (empty($this->view->query)) { @@ -2983,10 +3115,10 @@ class views_plugin_display extends views_plugin { * Special handling for the style export. * * Styles are stored as style_plugin and style_options or row_plugin and - * row_options accordingly. The options are told not to export, and the - * export for the plugin should export both. + * row_options accordingly. The options are told not to export, and the export + * for the plugin should export both. */ - function export_style($indent, $prefix, $storage, $option, $definition, $parents) { + public function export_style($indent, $prefix, $storage, $option, $definition, $parents) { $output = ''; $style_plugin = $this->get_plugin(); if ($option == 'style_plugin') { @@ -3018,14 +3150,14 @@ class views_plugin_display extends views_plugin { } /** - * Special handling for plugin export + * Special handling for plugin export. * * Plugins other than styles are stored in array with 'type' being the key * to the plugin. For modern plugins, the options are stored in the 'options' * array, but for legacy plugins (access and cache) options are stored as * siblings to the type. */ - function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) { + public function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) { $output = ''; $plugin_type = end($parents); $plugin = $this->get_plugin($plugin_type); @@ -3036,7 +3168,7 @@ class views_plugin_display extends views_plugin { $output .= $indent . $new_prefix . "['$option'] = '$value';\n"; - if ($plugin_type != 'access' && $plugin_type!= 'cache') { + if ($plugin_type != 'access' && $plugin_type != 'cache') { $new_prefix .= "['options']"; } @@ -3047,7 +3179,10 @@ class views_plugin_display extends views_plugin { return $output; } - function unpack_style($indent, $prefix, $storage, $option, $definition, $parents) { + /** + * + */ + public function unpack_style($indent, $prefix, $storage, $option, $definition, $parents) { $output = ''; $style_plugin = $this->get_plugin(); if ($option == 'style_plugin') { @@ -3074,7 +3209,7 @@ class views_plugin_display extends views_plugin { /** * Special handling for plugin unpacking. */ - function unpack_plugin(&$translatable, $storage, $option, $definition, $parents) { + public function unpack_plugin(&$translatable, $storage, $option, $definition, $parents) { $plugin_type = end($parents); $plugin = $this->get_plugin($plugin_type); if ($plugin) { @@ -3083,19 +3218,19 @@ class views_plugin_display extends views_plugin { } } - /** + /** * Special method to unpack items that have handlers. * - * This method was specified in the option_definition() as the method to utilize to - * export fields, filters, sort criteria, relationships and arguments. This passes - * the export off to the individual handlers so that they can export themselves - * properly. + * This method was specified in the option_definition() as the method to + * utilize to export fields, filters, sort criteria, relationships and + * arguments. This passes the export off to the individual handlers so that + * they can export themselves properly. */ - function unpack_handler(&$translatable, $storage, $option, $definition, $parents) { + public function unpack_handler(&$translatable, $storage, $option, $definition, $parents) { $output = ''; - // cut the 's' off because the data is stored as the plural form but we need - // the singular form. Who designed that anyway? Oh yeah, I did. :( + // Cut the 's' off because the data is stored as the plural form but we need + // the singular form. if ($option != 'header' && $option != 'footer' && $option != 'empty') { $type = substr($option, 0, -1); } @@ -3113,7 +3248,8 @@ class views_plugin_display extends views_plugin { $handler = views_get_handler($info['table'], $info['field'], $handler_type); if ($handler) { $handler->init($this->view, $info); - $handler->unpack_translatables($translatable, array_merge($parents, array($type, $info['table'], $info['id']))); + $items = array_merge($parents, array($type, $info['table'], $info['id'])); + $handler->unpack_translatables($translatable, $items); } // Prevent reference problems. @@ -3125,16 +3261,16 @@ class views_plugin_display extends views_plugin { /** * Provide some helpful text for the arguments. - * The result should contain of an array with - * - filter value present: The title of the fieldset in the argument - * where you can configure what should be done with a given argument. - * - filter value not present: The tiel of the fieldset in the argument - * where you can configure what should be done if the argument does not - * exist. - * - description: A description about how arguments comes to the display. - * For example blocks don't get it from url. + * + * The result should contain of an array with: + * - filter value present: The title of the fieldset in the argument where + * you can configure what should be done with a given argument. + * - filter value not present: The tiel of the fieldset in the argument where + * you can configure what should be done if the argument does not exist. + * - description: A description about how arguments comes to the display. For + * example blocks don't get it from url. */ - function get_argument_text() { + public function get_argument_text() { return array( 'filter value not present' => t('When the filter value is NOT available'), 'filter value present' => t('When the filter value IS available or a default is provided'), @@ -3145,17 +3281,18 @@ class views_plugin_display extends views_plugin { /** * Provide some helpful text for pagers. * - * The result should contain of an array within - * - items per page title + * The result should contain of an array with: + * - items per page title. + * - items per page description. */ - function get_pager_text() { + public function get_pager_text() { return array( 'items per page title' => t('Items to display'), - 'items per page description' => t('The number of items to display. Enter 0 for no limit.') + 'items per page description' => t('The number of items to display. Enter 0 for no limit.'), ); } -} +} /** * @} diff --git a/sites/all/modules/views/plugins/views_plugin_display_attachment.inc b/sites/all/modules/views/plugins/views_plugin_display_attachment.inc index 8608cfc..57bd090 100644 --- a/sites/all/modules/views/plugins/views_plugin_display_attachment.inc +++ b/sites/all/modules/views/plugins/views_plugin_display_attachment.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the attachment display plugin. + * Definition of views_plugin_display_attachment. */ /** @@ -15,9 +15,15 @@ * @ingroup views_display_plugins */ class views_plugin_display_attachment extends views_plugin_display { - function option_definition () { + + /** + * {@inheritdoc} + */ + public function option_definition () { $options = parent::option_definition(); + $options['show_title'] = array('default' => FALSE, 'bool' => TRUE); + $options['show_title_empty'] = array('default' => FALSE, 'bool' => TRUE); $options['displays'] = array('default' => array()); $options['attachment_position'] = array('default' => 'before'); $options['inherit_arguments'] = array('default' => TRUE, 'bool' => TRUE); @@ -28,11 +34,17 @@ class views_plugin_display_attachment extends views_plugin_display { return $options; } - function execute() { + /** + * {@inheritdoc} + */ + public function execute() { return $this->view->render($this->display->id); } - function attachment_positions($position = NULL) { + /** + * {@inheritdoc} + */ + public function attachment_positions($position = NULL) { $positions = array( 'before' => t('Before'), 'after' => t('After'), @@ -51,8 +63,8 @@ class views_plugin_display_attachment extends views_plugin_display { * * This output is returned as an array. */ - function options_summary(&$categories, &$options) { - // It is very important to call the parent function here: + public function options_summary(&$categories, &$options) { + // It is very important to call the parent function here. parent::options_summary($categories, $options); $categories['attachment'] = array( @@ -78,6 +90,18 @@ class views_plugin_display_attachment extends views_plugin_display { $attach_to = t('Not defined'); } + $options['show_title'] = array( + 'category' => 'title', + 'title' => t('Show title'), + 'value' => $this->get_option('show_title') ? t('Yes') : t('No'), + ); + + $options['show_title_empty'] = array( + 'category' => 'title', + 'title' => t('Show title even if view has no results'), + 'value' => $this->get_option('show_title_empty') ? t('Yes') : t('No'), + ); + $options['displays'] = array( 'category' => 'attachment', 'title' => t('Attach to'), @@ -119,11 +143,29 @@ class views_plugin_display_attachment extends views_plugin_display { /** * Provide the default form for setting options. */ - function options_form(&$form, &$form_state) { - // It is very important to call the parent function here: + public function options_form(&$form, &$form_state) { + // It is very important to call the parent function here. parent::options_form($form, $form_state); switch ($form_state['section']) { + case 'show_title': + $form['#title'] .= t('Title'); + $form['show_title'] = array( + '#type' => 'checkbox', + '#title' => t('Show title'), + '#description' => t('Do you want to show the title of the attachment?'), + '#default_value' => $this->get_option('show_title'), + ); + break; + case 'show_title_empty': + $form['#title'] .= t('Title'); + $form['show_title_empty'] = array( + '#type' => 'checkbox', + '#title' => t('Show title for empty view'), + '#description' => t('Do you want to show the title of the attachment even if the view has no results?'), + '#default_value' => $this->get_option('show_title_empty'), + ); + break; case 'inherit_arguments': $form['#title'] .= t('Inherit contextual filters'); $form['inherit_arguments'] = array( @@ -133,6 +175,7 @@ class views_plugin_display_attachment extends views_plugin_display { '#default_value' => $this->get_option('inherit_arguments'), ); break; + case 'inherit_exposed_filters': $form['#title'] .= t('Inherit exposed filters'); $form['inherit_exposed_filters'] = array( @@ -142,6 +185,7 @@ class views_plugin_display_attachment extends views_plugin_display { '#default_value' => $this->get_option('inherit_exposed_filters'), ); break; + case 'inherit_pager': $form['#title'] .= t('Inherit pager'); $form['inherit_pager'] = array( @@ -151,6 +195,7 @@ class views_plugin_display_attachment extends views_plugin_display { '#default_value' => $this->get_option('inherit_pager'), ); break; + case 'render_pager': $form['#title'] .= t('Render pager'); $form['render_pager'] = array( @@ -160,6 +205,7 @@ class views_plugin_display_attachment extends views_plugin_display { '#default_value' => $this->get_option('render_pager'), ); break; + case 'attachment_position': $form['#title'] .= t('Position'); $form['attachment_position'] = array( @@ -169,6 +215,7 @@ class views_plugin_display_attachment extends views_plugin_display { '#default_value' => $this->get_option('attachment_position'), ); break; + case 'displays': $form['#title'] .= t('Attach to'); $displays = array(); @@ -191,10 +238,12 @@ class views_plugin_display_attachment extends views_plugin_display { * Perform any necessary changes to the form values prior to storage. * There is no need for this function to actually store the data. */ - function options_submit(&$form, &$form_state) { - // It is very important to call the parent function here: + public function options_submit(&$form, &$form_state) { + // It is very important to call the parent function here. parent::options_submit($form, $form_state); switch ($form_state['section']) { + case 'show_title': + case 'show_title_empty': case 'inherit_arguments': case 'inherit_pager': case 'render_pager': @@ -209,7 +258,7 @@ class views_plugin_display_attachment extends views_plugin_display { /** * Attach to another view. */ - function attach_to($display_id) { + public function attach_to($display_id) { $displays = $this->get_option('displays'); if (empty($displays[$display_id])) { @@ -220,14 +269,14 @@ class views_plugin_display_attachment extends views_plugin_display { return; } - // Get a fresh view because our current one has a lot of stuff on it because it's - // already been executed. + // Get a fresh view because our current one has a lot of stuff on it + // because it's already been executed. $view = $this->view->clone_view(); $view->original_args = $view->args; $args = $this->get_option('inherit_arguments') ? $this->view->args : array(); $view->set_arguments($args); - $exposed_input = $this->get_option('inherit_exposed_filters') ? $this->view->exposed_input : array(); + $exposed_input = $this->get_option('inherit_exposed_filters') && isset($this->view->exposed_input) ? $this->view->exposed_input : array(); $view->set_exposed_input($exposed_input); $view->set_display($this->display->id); if ($this->get_option('inherit_pager')) { @@ -235,15 +284,30 @@ class views_plugin_display_attachment extends views_plugin_display { $view->display_handler->set_option('pager', $this->view->display[$display_id]->handler->get_option('pager')); } - $attachment = $view->execute_display($this->display->id, $args); + $attachment_output = $view->execute_display($this->display->id, $args); + + $attachment = ''; + if ($view->display_handler->get_option('show_title') && $view->display_handler->get_option('title')) { + if ($view->display_handler->get_option('show_title_empty') || !empty($view->result)) { + $attachment .= theme('html_tag', array( + 'element' => array( + '#tag' => 'h2', + '#value' => $view->display_handler->get_option('title'), + ), + )); + } + } + $attachment .= $attachment_output; switch ($this->get_option('attachment_position')) { case 'before': $this->view->attachment_before .= $attachment; break; + case 'after': $this->view->attachment_after .= $attachment; break; + case 'both': $this->view->attachment_before .= $attachment; $this->view->attachment_after .= $attachment; @@ -254,11 +318,10 @@ class views_plugin_display_attachment extends views_plugin_display { } /** - * Attachment displays only use exposed widgets if - * they are set to inherit the exposed filter settings - * of their parent display. + * Attachment displays only use exposed widgets if they are set to inherit + * the exposed filter settings of their parent display. */ - function uses_exposed() { + public function uses_exposed() { if (!empty($this->options['inherit_exposed_filters']) && parent::uses_exposed()) { return TRUE; } @@ -266,19 +329,26 @@ class views_plugin_display_attachment extends views_plugin_display { } /** - * If an attachment is set to inherit the exposed filter - * settings from its parent display, then don't render and - * display a second set of exposed filter widgets. + * If an attachment is set to inherit the exposed filter settings from its + * parent display, then don't render and display a second set of exposed + * filter widgets. */ - function displays_exposed() { + public function displays_exposed() { return $this->options['inherit_exposed_filters'] ? FALSE : TRUE; } - function use_pager() { + /** + * {@inheritdoc} + */ + public function use_pager() { return !empty($this->use_pager); } - function render_pager() { + /** + * {@inheritdoc} + */ + public function render_pager() { return !empty($this->use_pager) && $this->get_option('render_pager'); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_display_block.inc b/sites/all/modules/views/plugins/views_plugin_display_block.inc index 88d22d0..9fc0111 100644 --- a/sites/all/modules/views/plugins/views_plugin_display_block.inc +++ b/sites/all/modules/views/plugins/views_plugin_display_block.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the block display plugin. + * Definition of views_plugin_display_block. */ /** @@ -11,7 +11,11 @@ * @ingroup views_display_plugins */ class views_plugin_display_block extends views_plugin_display { - function option_definition() { + + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['block_description'] = array('default' => '', 'translatable' => TRUE); @@ -25,7 +29,7 @@ class views_plugin_display_block extends views_plugin_display { * but extended block handlers might be able to do interesting * stuff with it. */ - function execute_hook_block_list($delta = 0, $edit = array()) { + public function execute_hook_block_list($delta = 0, $edit = array()) { $delta = $this->view->name . '-' . $this->display->id; $desc = $this->get_option('block_description'); @@ -40,7 +44,7 @@ class views_plugin_display_block extends views_plugin_display { return array( $delta => array( 'info' => $desc, - 'cache' => $this->get_cache_type() + 'cache' => $this->get_cache_type(), ), ); } @@ -48,7 +52,7 @@ class views_plugin_display_block extends views_plugin_display { /** * The display block handler returns the structure necessary for a block. */ - function execute() { + public function execute() { // Prior to this being called, the $view should already be set to this // display, and arguments should be set on the view. $info['content'] = $this->view->render(); @@ -64,8 +68,8 @@ class views_plugin_display_block extends views_plugin_display { * * This output is returned as an array. */ - function options_summary(&$categories, &$options) { - // It is very important to call the parent function here: + public function options_summary(&$categories, &$options) { + // It is very important to call the parent function here. parent::options_summary($categories, $options); $categories['block'] = array( @@ -98,7 +102,7 @@ class views_plugin_display_block extends views_plugin_display { /** * Provide a list of core's block caching modes. */ - function block_caching_modes() { + public function block_caching_modes() { return array( DRUPAL_NO_CACHE => t('Do not cache'), DRUPAL_CACHE_GLOBAL => t('Cache once for everything (global)'), @@ -114,7 +118,7 @@ class views_plugin_display_block extends views_plugin_display { * Provide a single method to figure caching type, keeping a sensible default * for when it's unset. */ - function get_cache_type() { + public function get_cache_type() { $cache_type = $this->get_option('block_caching'); if (empty($cache_type)) { $cache_type = DRUPAL_NO_CACHE; @@ -125,8 +129,8 @@ class views_plugin_display_block extends views_plugin_display { /** * Provide the default form for setting options. */ - function options_form(&$form, &$form_state) { - // It is very important to call the parent function here: + public function options_form(&$form, &$form_state) { + // It is very important to call the parent function here. parent::options_form($form, $form_state); switch ($form_state['section']) { @@ -138,6 +142,7 @@ class views_plugin_display_block extends views_plugin_display { '#default_value' => $this->get_option('block_description'), ); break; + case 'block_caching': $form['#title'] .= t('Block caching type'); @@ -148,6 +153,7 @@ class views_plugin_display_block extends views_plugin_display { '#default_value' => $this->get_cache_type(), ); break; + case 'exposed_form_options': $this->view->init_handlers(); if (!$this->uses_exposed() && parent::uses_exposed()) { @@ -156,6 +162,7 @@ class views_plugin_display_block extends views_plugin_display { '#markup' => ' ', ); } + break; } } @@ -163,19 +170,21 @@ class views_plugin_display_block extends views_plugin_display { * Perform any necessary changes to the form values prior to storage. * There is no need for this function to actually store the data. */ - function options_submit(&$form, &$form_state) { - // It is very important to call the parent function here: + public function options_submit(&$form, &$form_state) { + // It is very important to call the parent function here. parent::options_submit($form, $form_state); switch ($form_state['section']) { case 'display_id': $this->update_block_bid($form_state['view']->name, $this->display->id, $this->display->new_id); break; + case 'block_description': $this->set_option('block_description', $form_state['values']['block_description']); break; + case 'block_caching': $this->set_option('block_caching', $form_state['values']['block_caching']); - $this->save_block_cache($form_state['view']->name . '-'. $form_state['display_id'], $form_state['values']['block_caching']); + $this->save_block_cache($form_state['view']->name . '-' . $form_state['display_id'], $form_state['values']['block_caching']); break; } } @@ -183,17 +192,17 @@ class views_plugin_display_block extends views_plugin_display { /** * Block views use exposed widgets only if AJAX is set. */ - function uses_exposed() { - if ($this->use_ajax()) { - return parent::uses_exposed(); - } - return FALSE; + public function uses_exposed() { + if ($this->use_ajax()) { + return parent::uses_exposed(); } + return FALSE; + } /** - * Update the block delta when you change the machine readable name of the display. + * Update the block delta when the machine name of the display changes. */ - function update_block_bid($name, $old_delta, $delta) { + public function update_block_bid($name, $old_delta, $delta) { $old_hashes = $hashes = variable_get('views_block_hashes', array()); $old_delta = $name . '-' . $old_delta; @@ -224,21 +233,22 @@ class views_plugin_display_block extends views_plugin_display { /** * Save the block cache setting in the blocks table if this block already - * exists in the blocks table. Dirty fix until http://drupal.org/node/235673 gets in. + * exists in the blocks table. Dirty fix until http://drupal.org/node/235673 + * gets in. */ - function save_block_cache($delta, $cache_setting) { + public function save_block_cache($delta, $cache_setting) { if (strlen($delta) >= 32) { $delta = md5($delta); } - if (db_table_exists('block') && $bid = db_query("SELECT bid FROM {block} WHERE module = 'views' AND delta = :delta", array( - ':delta' => $delta))->fetchField()) { + if (db_table_exists('block') && $bid = db_query("SELECT bid FROM {block} WHERE module = 'views' AND delta = :delta", array(':delta' => $delta))->fetchField()) { db_update('block') ->fields(array( - 'cache' => $cache_setting, + 'cache' => $cache_setting, )) - ->condition('module','views') + ->condition('module', 'views') ->condition('delta', $delta) ->execute(); } } + } diff --git a/sites/all/modules/views/plugins/views_plugin_display_default.inc b/sites/all/modules/views/plugins/views_plugin_display_default.inc index 4b1fc08..9531013 100644 --- a/sites/all/modules/views/plugins/views_plugin_display_default.inc +++ b/sites/all/modules/views/plugins/views_plugin_display_default.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the default display plugin. + * Definition of views_plugin_display_default. */ /** @@ -11,11 +11,14 @@ * @ingroup views_display_plugins */ class views_plugin_display_default extends views_plugin_display { + /** * Determine if this display is the 'default' display which contains - * fallback settings + * fallback settings. */ - function is_default_display() { return TRUE; } + public function is_default_display() { + return TRUE; + } /** * The default execute handler fully renders the view. @@ -26,32 +29,34 @@ class views_plugin_display_default extends views_plugin_display { * @endcode * * For more complex usages, a view can be partially built: + * * @code * $view->set_arguments($args); - * $view->build('default'); // Build the query + * $view->build('default'); // Build the query. * $view->pre_execute(); // Pre-execute the query. - * $view->execute(); // Run the query - * $output = $view->render(); // Render the view + * $view->execute(); // Run the query. + * $output = $view->render(); // Render the view. * @endcode * - * If short circuited at any point, look in $view->build_info for - * information about the query. After execute, look in $view->result - * for the array of objects returned from db_query. + * If short circuited at any point, look in $view->build_info for information + * about the query. After execute, look in $view->result for the array of + * objects returned from db_query. * * You can also do: + * * @code * $view->set_arguments($args); - * $output = $view->render('default'); // Render the view + * $output = $view->render('default'); // Render the view. * @endcode * - * This illustrates that render is smart enough to call build and execute - * if these items have not already been accomplished. + * This illustrates that render is smart enough to call build and execute if + * these items have not already been accomplished. * - * Note that execute also must accomplish other tasks, such - * as setting page titles, breadcrumbs, and generating exposed filter - * data if necessary. + * Note that execute also must accomplish other tasks, such as setting page + * titles, breadcrumbs, and generating exposed filter data if necessary. */ - function execute() { + public function execute() { return $this->view->render($this->display->id); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_display_embed.inc b/sites/all/modules/views/plugins/views_plugin_display_embed.inc index 8b25cf9..65cc6ca 100644 --- a/sites/all/modules/views/plugins/views_plugin_display_embed.inc +++ b/sites/all/modules/views/plugins/views_plugin_display_embed.inc @@ -1,7 +1,8 @@ view = $view; $this->display = $display; } + /** + * Provide a form to edit options for this plugin. + */ + public function options_definition_alter(&$options) { + } /** * Provide a form to edit options for this plugin. */ - function options_definition_alter(&$options) { } - - /** - * Provide a form to edit options for this plugin. - */ - function options_form(&$form, &$form_state) { } + public function options_form(&$form, &$form_state) { + } /** * Validate the options form. */ - function options_validate(&$form, &$form_state) { } + public function options_validate(&$form, &$form_state) { + } /** * Handle any special handling on the validate form. */ - function options_submit(&$form, &$form_state) { } + public function options_submit(&$form, &$form_state) { + } /** * Set up any variables on the view prior to execution. */ - function pre_execute() { } + public function pre_execute() { + } /** * Inject anything into the query that the display_extender handler needs. */ - function query() { } + public function query() { + } /** * Provide the default summary for options in the views UI. * * This output is returned as an array. */ - function options_summary(&$categories, &$options) { } + public function options_summary(&$categories, &$options) { + } /** * Static member function to list which sections are defaultable * and what items each section contains. */ - function defaultable_sections(&$sections, $section = NULL) { } + public function defaultable_sections(&$sections, $section = NULL) { + } + } diff --git a/sites/all/modules/views/plugins/views_plugin_display_feed.inc b/sites/all/modules/views/plugins/views_plugin_display_feed.inc index 5eb68e3..a3c2333 100644 --- a/sites/all/modules/views/plugins/views_plugin_display_feed.inc +++ b/sites/all/modules/views/plugins/views_plugin_display_feed.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the feed display plugin. + * Definition of views_plugin_display_feed. */ /** @@ -13,7 +13,11 @@ * @ingroup views_display_plugins */ class views_plugin_display_feed extends views_plugin_display_page { - function init(&$view, &$display, $options = NULL) { + + /** + * {@inheritdoc} + */ + public function init(&$view, &$display, $options = NULL) { parent::init($view, $display, $options); // Set the default row style. Ideally this would be part of the option @@ -26,23 +30,40 @@ class views_plugin_display_feed extends views_plugin_display_page { } } - function uses_breadcrumb() { return FALSE; } - function get_style_type() { return 'feed'; } + /** + * {@inheritdoc} + */ + public function uses_breadcrumb() { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function get_style_type() { + return 'feed'; + } /** * Feeds do not go through the normal page theming mechanism. Instead, they * go through their own little theme function and then return NULL so that * Drupal believes that the page has already rendered itself...which it has. */ - function execute() { + public function execute() { $output = $this->view->render(); + if (!empty($this->view->build_info['denied'])) { + return MENU_ACCESS_DENIED; + } if (empty($output)) { return MENU_NOT_FOUND; } print $output; } - function preview() { + /** + * {@inheritdoc} + */ + public function preview() { if (!empty($this->view->live_preview)) { return '' . check_plain($this->view->render()) . ''; } @@ -53,11 +74,14 @@ class views_plugin_display_feed extends views_plugin_display_page { * Instead of going through the standard views_view.tpl.php, delegate this * to the style handler. */ - function render() { + public function render() { return $this->view->style_plugin->render($this->view->result); } - function defaultable_sections($section = NULL) { + /** + * {@inheritdoc} + */ + public function defaultable_sections($section = NULL) { if (in_array($section, array('style_options', 'style_plugin', 'row_options', 'row_plugin',))) { return FALSE; } @@ -74,12 +98,15 @@ class views_plugin_display_feed extends views_plugin_display_page { return $sections; } - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['displays'] = array('default' => array()); - // Overrides for standard stuff: + // Overrides for standard stuff. $options['style_plugin']['default'] = 'rss'; $options['style_options']['default'] = array('description' => ''); $options['sitename_title']['default'] = FALSE; @@ -92,8 +119,11 @@ class views_plugin_display_feed extends views_plugin_display_page { return $options; } - function options_summary(&$categories, &$options) { - // It is very important to call the parent function here: + /** + * {@inheritdoc} + */ + public function options_summary(&$categories, &$options) { + // It is very important to call the parent function here. parent::options_summary($categories, $options); // Since we're childing off the 'page' type, we'll still *call* our @@ -138,7 +168,7 @@ class views_plugin_display_feed extends views_plugin_display_page { /** * Provide the default form for setting options. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { // It is very important to call the parent function here. parent::options_form($form, $form_state); @@ -155,6 +185,7 @@ class views_plugin_display_feed extends views_plugin_display_page { $form['title'] = $title; $form['title']['#dependency'] = array('edit-sitename-title' => array(FALSE)); break; + case 'displays': $form['#title'] .= t('Attach to'); $displays = array(); @@ -170,8 +201,10 @@ class views_plugin_display_feed extends views_plugin_display_page { '#default_value' => $this->get_option('displays'), ); break; + case 'path': $form['path']['#description'] = t('This view will be displayed by visiting this path on your site. It is recommended that the path be something like "path/%/%/feed" or "path/%/%/rss.xml", putting one % in the path for each contextual filter you have defined in the view.'); + break; } } @@ -179,13 +212,14 @@ class views_plugin_display_feed extends views_plugin_display_page { * Perform any necessary changes to the form values prior to storage. * There is no need for this function to actually store the data. */ - function options_submit(&$form, &$form_state) { - // It is very important to call the parent function here: + public function options_submit(&$form, &$form_state) { + // It is very important to call the parent function here. parent::options_submit($form, $form_state); switch ($form_state['section']) { case 'title': $this->set_option('sitename_title', $form_state['values']['sitename_title']); break; + case 'displays': $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]); break; @@ -195,7 +229,7 @@ class views_plugin_display_feed extends views_plugin_display_page { /** * Attach to another view. */ - function attach_to($display_id) { + public function attach_to($display_id) { $displays = $this->get_option('displays'); if (empty($displays[$display_id])) { return; @@ -216,7 +250,11 @@ class views_plugin_display_feed extends views_plugin_display_page { } } - function uses_link_display() { + /** + * {@inheritdoc} + */ + public function uses_link_display() { return TRUE; } + } diff --git a/sites/all/modules/views/plugins/views_plugin_display_page.inc b/sites/all/modules/views/plugins/views_plugin_display_page.inc index 913a5a9..9b9e900 100644 --- a/sites/all/modules/views/plugins/views_plugin_display_page.inc +++ b/sites/all/modules/views/plugins/views_plugin_display_page.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the page display plugin. + * Definition of views_plugin_display_page. */ /** @@ -11,13 +11,25 @@ * @ingroup views_display_plugins */ class views_plugin_display_page extends views_plugin_display { + /** * The page display has a path. */ - function has_path() { return TRUE; } - function uses_breadcrumb() { return TRUE; } + public function has_path() { + return TRUE; + } - function option_definition() { + /** + * {@inheritdoc} + */ + public function uses_breadcrumb() { + return TRUE; + } + + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['path'] = array('default' => ''); @@ -50,7 +62,7 @@ class views_plugin_display_page extends views_plugin_display { /** * Add this display's path information to Drupal's menu system. */ - function execute_hook_menu($callbacks) { + public function execute_hook_menu($callbacks) { $items = array(); // Replace % with the link to our standard views argument loader // views_arg_load -- which lives in views.module @@ -79,7 +91,8 @@ class views_plugin_display_page extends views_plugin_display { $access_plugin = views_get_plugin('access', 'none'); } - // Get access callback might return an array of the callback + the dynamic arguments. + // Get access callback might return an array of the callback + the dynamic + // arguments. $access_plugin_callback = $access_plugin->get_access_callback(); if (is_array($access_plugin_callback)) { @@ -140,17 +153,23 @@ class views_plugin_display_page extends views_plugin_display { default: $items[$path]['type'] = MENU_CALLBACK; break; + case 'normal': $items[$path]['type'] = MENU_NORMAL_ITEM; // Insert item into the proper menu $items[$path]['menu_name'] = $menu['name']; break; + case 'tab': $items[$path]['type'] = MENU_LOCAL_TASK; break; + case 'default tab': $items[$path]['type'] = MENU_DEFAULT_LOCAL_TASK; break; + case 'local action': + $items[$path]['type'] = MENU_LOCAL_ACTION; + break; } // Add context for contextual links. @@ -169,7 +188,7 @@ class views_plugin_display_page extends views_plugin_display { $bit = array_pop($bits); // we can't do this if they tried to make the last path bit variable. - // @todo: We can validate this. + // @todo We can validate this. if ($bit != '%views_arg' && !empty($bits)) { $default_path = implode('/', $bits); $items[$default_path] = array( @@ -192,6 +211,7 @@ class views_plugin_display_page extends views_plugin_display { case 'normal': $items[$default_path]['type'] = MENU_NORMAL_ITEM; break; + case 'tab': $items[$default_path]['type'] = MENU_LOCAL_TASK; break; @@ -212,7 +232,7 @@ class views_plugin_display_page extends views_plugin_display { * a drupal_set_title for the page, and does a views_set_page_view * on the view. */ - function execute() { + public function execute() { // Let the world know that this is the page view we're using. views_set_page_view($this->view); @@ -250,8 +270,8 @@ class views_plugin_display_page extends views_plugin_display { * * This output is returned as an array. */ - function options_summary(&$categories, &$options) { - // It is very important to call the parent function here: + public function options_summary(&$categories, &$options) { + // It is very important to call the parent function here. parent::options_summary($categories, $options); $categories['page'] = array( @@ -280,18 +300,22 @@ class views_plugin_display_page extends views_plugin_display { if (!is_array($menu)) { $menu = array('type' => 'none'); } - switch($menu['type']) { + switch ($menu['type']) { case 'none': default: $menu_str = t('No menu'); break; + case 'normal': $menu_str = t('Normal: @title', array('@title' => $menu['title'])); break; + case 'tab': case 'default tab': $menu_str = t('Tab: @title', array('@title' => $menu['title'])); break; + case 'local action': + $menu_str = t('Local action: @title', array('@title' => $menu['title'])); } $options['menu'] = array( @@ -300,7 +324,8 @@ class views_plugin_display_page extends views_plugin_display { 'value' => views_ui_truncate($menu_str, 24), ); - // This adds a 'Settings' link to the style_options setting if the style has options. + // This adds a 'Settings' link to the style_options setting if the style + // has options. if ($menu['type'] == 'default tab') { $options['menu']['setting'] = t('Parent menu item'); $options['menu']['links']['tab_options'] = t('Change settings for the parent menu'); @@ -310,8 +335,8 @@ class views_plugin_display_page extends views_plugin_display { /** * Provide the default form for setting options. */ - function options_form(&$form, &$form_state) { - // It is very important to call the parent function here: + public function options_form(&$form, &$form_state) { + // It is very important to call the parent function here. parent::options_form($form, $form_state); switch ($form_state['section']) { @@ -322,11 +347,13 @@ class views_plugin_display_page extends views_plugin_display { '#type' => 'textfield', '#description' => t('This view will be displayed by visiting this path on your site. You may use "%" in your URL to represent values that will be used for contextual filters: For example, "node/%/feed".'), '#default_value' => $this->get_option('path'), - '#field_prefix' => '' . url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), - '#field_suffix' => '', - '#attributes' => array('dir'=>'ltr'), + '#field_prefix' => '' . url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), + '#field_suffix' => '', + '#attributes' => array('dir'=>'ltr'), + '#maxlength' => 255, ); break; + case 'menu': $form['#title'] .= t('Menu item entry'); $form['#help_topic'] = 'menu'; @@ -339,6 +366,7 @@ class views_plugin_display_page extends views_plugin_display { if (empty($menu)) { $menu = array('type' => 'none', 'title' => '', 'weight' => 0); } + $menu_type_dependencies = array('normal', 'tab', 'default tab', 'local action'); $form['menu']['type'] = array( '#prefix' => '', '#suffix' => '', @@ -348,7 +376,8 @@ class views_plugin_display_page extends views_plugin_display { 'none' => t('No menu entry'), 'normal' => t('Normal menu entry'), 'tab' => t('Menu tab'), - 'default tab' => t('Default menu tab') + 'default tab' => t('Default menu tab'), + 'local action' => t('Local action'), ), '#default_value' => $menu['type'], ); @@ -358,14 +387,14 @@ class views_plugin_display_page extends views_plugin_display { '#type' => 'textfield', '#default_value' => $menu['title'], '#description' => t('If set to normal or tab, enter the text to use for the menu item.'), - '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')), + '#dependency' => array('radio:menu[type]' => $menu_type_dependencies), ); $form['menu']['description'] = array( '#title' => t('Description'), '#type' => 'textfield', '#default_value' => $menu['description'], '#description' => t("If set to normal or tab, enter the text to use for the menu item's description."), - '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')), + '#dependency' => array('radio:menu[type]' => $menu_type_dependencies), ); // Only display the menu selector if menu module is enabled. @@ -393,7 +422,7 @@ class views_plugin_display_page extends views_plugin_display { '#type' => 'textfield', '#default_value' => isset($menu['weight']) ? $menu['weight'] : 0, '#description' => t('The lower the weight the higher/further left it will appear.'), - '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')), + '#dependency' => array('radio:menu[type]' => $menu_type_dependencies), ); $form['menu']['context'] = array( '#title' => t('Context'), @@ -415,6 +444,7 @@ class views_plugin_display_page extends views_plugin_display { '#dependency_count' => 2, ); break; + case 'tab_options': $form['#title'] .= t('Default tab options'); $tab_options = $this->get_option('tab_options'); @@ -480,15 +510,18 @@ class views_plugin_display_page extends views_plugin_display { '#type' => 'textfield', '#default_value' => $tab_options['weight'], '#size' => 5, - '#description' => t('If the parent menu item is a tab, enter the weight of the tab. The lower the number, the more to the left it will be.'), - '#dependency' => array('radio:tab_options[type]' => array('tab')), + '#description' => t('Enter the weight of the item. The lower the number, the more to the left it will be.'), + '#dependency' => array('radio:tab_options[type]' => array('normal', 'tab')), ); break; } } - function options_validate(&$form, &$form_state) { - // It is very important to call the parent function here: + /** + * {@inheritdoc} + */ + public function options_validate(&$form, &$form_state) { + // It is very important to call the parent function here. parent::options_validate($form, $form_state); switch ($form_state['section']) { case 'path': @@ -500,9 +533,10 @@ class views_plugin_display_page extends views_plugin_display { form_error($form['path'], t('"%" may not be used for the first segment of a path.')); } - // automatically remove '/' and trailing whitespace from path. + // Automatically remove '/' and trailing whitespace from path. $form_state['values']['path'] = trim($form_state['values']['path'], '/ '); break; + case 'menu': $path = $this->get_option('path'); if ($form_state['values']['menu']['type'] == 'normal' && strpos($path, '%') !== FALSE) { @@ -524,27 +558,35 @@ class views_plugin_display_page extends views_plugin_display { } } - function options_submit(&$form, &$form_state) { - // It is very important to call the parent function here: + /** + * {@inheritdoc} + */ + public function options_submit(&$form, &$form_state) { + // It is very important to call the parent function here. parent::options_submit($form, $form_state); switch ($form_state['section']) { case 'path': $this->set_option('path', $form_state['values']['path']); break; + case 'menu': $this->set_option('menu', $form_state['values']['menu']); - // send ajax form to options page if we use it. + // Send ajax form to options page if we use it. if ($form_state['values']['menu']['type'] == 'default tab') { views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('tab_options')); } break; + case 'tab_options': $this->set_option('tab_options', $form_state['values']['tab_options']); break; } } - function validate() { + /** + * {@inheritdoc} + */ + public function validate() { $errors = parent::validate(); $menu = $this->get_option('menu'); @@ -562,7 +604,10 @@ class views_plugin_display_page extends views_plugin_display { return $errors; } - function get_argument_text() { + /** + * {@inheritdoc} + */ + public function get_argument_text() { return array( 'filter value not present' => t('When the filter value is NOT in the URL'), 'filter value present' => t('When the filter value IS in the URL or a default is provided'), @@ -570,10 +615,14 @@ class views_plugin_display_page extends views_plugin_display { ); } - function get_pager_text() { + /** + * {@inheritdoc} + */ + public function get_pager_text() { return array( 'items per page title' => t('Items per page'), - 'items per page description' => t('The number of items to display per page. Enter 0 for no limit.') + 'items per page description' => t('The number of items to display per page. Enter 0 for no limit.'), ); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_exposed_form.inc b/sites/all/modules/views/plugins/views_plugin_exposed_form.inc index 5d54600..5493be3 100644 --- a/sites/all/modules/views/plugins/views_plugin_exposed_form.inc +++ b/sites/all/modules/views/plugins/views_plugin_exposed_form.inc @@ -23,19 +23,24 @@ class views_plugin_exposed_form extends views_plugin { /** * Initialize the plugin. * - * @param $view + * @param object $view * The view object. - * @param $display + * @param object $display * The display handler. + * @param array $options + * Any additional options that are being added. */ - function init(&$view, &$display, $options = array()) { + public function init(&$view, &$display, $options = array()) { $this->view = &$view; $this->display = &$display; $this->unpack_options($this->options, $options); } - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['submit_button'] = array('default' => 'Apply', 'translatable' => TRUE); $options['reset_button'] = array('default' => FALSE, 'bool' => TRUE); @@ -49,7 +54,10 @@ class views_plugin_exposed_form extends views_plugin { return $options; } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['submit_button'] = array( '#type' => 'textfield', @@ -120,7 +128,7 @@ class views_plugin_exposed_form extends views_plugin { $form['autosubmit_hide'] = array( '#type' => 'checkbox', '#title' => t('Hide submit button'), - '#description' => t('Hide submit button if javascript is enabled.'), + '#description' => t('Hide submit button if JavaScript is enabled.'), '#default_value' => $this->options['autosubmit_hide'], '#dependency' => array( 'edit-exposed-form-options-autosubmit' => array(1), @@ -135,7 +143,7 @@ class views_plugin_exposed_form extends views_plugin { * also assign data to the appropriate handlers for use in building the * query. */ - function render_exposed_form($block = FALSE) { + public function render_exposed_form($block = FALSE) { // Deal with any exposed filters we may have, before building. $form_state = array( 'view' => &$this->view, @@ -169,7 +177,10 @@ class views_plugin_exposed_form extends views_plugin { } } - function query() { + /** + * {@inheritdoc} + */ + public function query() { $view = $this->view; $exposed_data = isset($view->exposed_data) ? $view->exposed_data : array(); $sort_by = isset($exposed_data['sort_by']) ? $exposed_data['sort_by'] : NULL; @@ -182,7 +193,7 @@ class views_plugin_exposed_form extends views_plugin { if (!$sort->is_exposed()) { $sort->query(); } - else if ($key == $sort_by) { + elseif ($key == $sort_by) { if (isset($exposed_data['sort_order']) && in_array($exposed_data['sort_order'], array('ASC', 'DESC'))) { $sort->options['order'] = $exposed_data['sort_order']; } @@ -194,15 +205,34 @@ class views_plugin_exposed_form extends views_plugin { } } - function pre_render($values) { } + /** + * {@inheritdoc} + */ + public function pre_render($values) { + } - function post_render(&$output) { } + /** + * {@inheritdoc} + */ + public function post_render(&$output) { + } - function pre_execute() { } + /** + * {@inheritdoc} + */ + public function pre_execute() { + } - function post_execute() { } + /** + * {@inheritdoc} + */ + public function post_execute() { + } - function exposed_form_alter(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function exposed_form_alter(&$form, &$form_state) { if (!empty($this->options['reset_button'])) { $form['reset'] = array( '#value' => $this->options['reset_button_label'], @@ -231,7 +261,8 @@ class views_plugin_exposed_form extends views_plugin { ); if (isset($form_state['input']['sort_by']) && isset($this->view->sort[$form_state['input']['sort_by']])) { $default_sort_order = $this->view->sort[$form_state['input']['sort_by']]->options['order']; - } else { + } + else { $first_sort = reset($this->view->sort); $default_sort_order = $first_sort->options['order']; } @@ -275,7 +306,10 @@ class views_plugin_exposed_form extends views_plugin { } } - function exposed_form_validate(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function exposed_form_validate(&$form, &$form_state) { if (isset($form_state['pager_plugin'])) { $form_state['pager_plugin']->exposed_form_validate($form, $form_state); } @@ -284,15 +318,14 @@ class views_plugin_exposed_form extends views_plugin { /** * This function is executed when exposed form is submited. * - * @param $form + * @param array $form * Nested array of form elements that comprise the form. - * @param $form_state + * @param array $form_state * A keyed array containing the current state of the form. - * @param $exclude - * Nested array of keys to exclude of insert into - * $view->exposed_raw_input + * @param array $exclude + * Nested array of keys to exclude of insert into $view->exposed_raw_input. */ - function exposed_form_submit(&$form, &$form_state, &$exclude) { + public function exposed_form_submit(&$form, &$form_state, &$exclude) { if (!empty($form_state['values']['op']) && $form_state['values']['op'] == $this->options['reset_button_label']) { $this->reset_form($form, $form_state); } @@ -302,7 +335,10 @@ class views_plugin_exposed_form extends views_plugin { } } - function reset_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function reset_form(&$form, &$form_state) { // _SESSION is not defined for users who are not logged in. // If filters are not overridden, store the 'remember' settings on the @@ -327,6 +363,7 @@ class views_plugin_exposed_form extends views_plugin { $form_state['redirect'] = current_path(); $form_state['values'] = array(); } + } /** diff --git a/sites/all/modules/views/plugins/views_plugin_exposed_form_basic.inc b/sites/all/modules/views/plugins/views_plugin_exposed_form_basic.inc index 73ae54a..2bf8162 100644 --- a/sites/all/modules/views/plugins/views_plugin_exposed_form_basic.inc +++ b/sites/all/modules/views/plugins/views_plugin_exposed_form_basic.inc @@ -10,4 +10,6 @@ * * @ingroup views_exposed_form_plugins */ -class views_plugin_exposed_form_basic extends views_plugin_exposed_form { } +class views_plugin_exposed_form_basic extends views_plugin_exposed_form { + // Nothing to see here. +} diff --git a/sites/all/modules/views/plugins/views_plugin_exposed_form_input_required.inc b/sites/all/modules/views/plugins/views_plugin_exposed_form_input_required.inc index ca97674..93a3bc3 100644 --- a/sites/all/modules/views/plugins/views_plugin_exposed_form_input_required.inc +++ b/sites/all/modules/views/plugins/views_plugin_exposed_form_input_required.inc @@ -12,7 +12,10 @@ */ class views_plugin_exposed_form_input_required extends views_plugin_exposed_form { - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['text_input_required'] = array('default' => 'Select any filter and click on Apply to see results', 'translatable' => TRUE); @@ -20,7 +23,10 @@ class views_plugin_exposed_form_input_required extends views_plugin_exposed_form return $options; } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['text_input_required'] = array( @@ -33,13 +39,19 @@ class views_plugin_exposed_form_input_required extends views_plugin_exposed_form ); } - function options_submit(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_submit(&$form, &$form_state) { $form_state['values']['exposed_form_options']['text_input_required_format'] = $form_state['values']['exposed_form_options']['text_input_required']['format']; $form_state['values']['exposed_form_options']['text_input_required'] = $form_state['values']['exposed_form_options']['text_input_required']['value']; parent::options_submit($form, $form_state); } - function exposed_filter_applied() { + /** + * {@inheritdoc} + */ + public function exposed_filter_applied() { static $cache = NULL; if (!isset($cache)) { $view = $this->view; @@ -60,7 +72,10 @@ class views_plugin_exposed_form_input_required extends views_plugin_exposed_form return $cache; } - function pre_render($values) { + /** + * {@inheritdoc} + */ + public function pre_render($values) { if (!$this->exposed_filter_applied()) { $options = array( 'id' => 'area', @@ -82,7 +97,10 @@ class views_plugin_exposed_form_input_required extends views_plugin_exposed_form } } - function query() { + /** + * {@inheritdoc} + */ + public function query() { if (!$this->exposed_filter_applied()) { // We return with no query; this will force the empty text. $this->view->built = TRUE; diff --git a/sites/all/modules/views/plugins/views_plugin_localization.inc b/sites/all/modules/views/plugins/views_plugin_localization.inc index 08caf9e..f572a8d 100644 --- a/sites/all/modules/views/plugins/views_plugin_localization.inc +++ b/sites/all/modules/views/plugins/views_plugin_localization.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the base class for views localization plugins. + * Definition of views_plugin_localization. */ /** @@ -17,22 +17,29 @@ * The base plugin to handle localization of Views strings. */ class views_plugin_localization extends views_plugin { - // Store for exported strings - var $export_strings = array(); - var $translate = TRUE; + + /** + * Store for exported strings. + */ + public $export_strings = array(); + + /** + * + */ + public $translate = TRUE; /** * Initialize the plugin. * - * @param $view + * @param view $view * The view object. */ - function init(&$view) { + public function init(&$view) { $this->view = &$view; } /** - * Translate a string / text with format + * Translate a string / text with format. * * The $source parameter is an array with the following elements: * - value, source string @@ -40,14 +47,15 @@ class views_plugin_localization extends views_plugin { * - keys. An array of keys to identify the string. Generally constructed from * view name, display_id, and a property, e.g., 'header'. * - * @param $source + * @param string $source * Full data for the string to be translated. * * @return string - * Translated string / text + * Translated string / text. */ - function translate($source) { - // Allow other modules to make changes to the string before and after translation + public function translate($source) { + // Allow other modules to make changes to the string before and after + // translation. $source['pre_process'] = $this->invoke_translation_process($source, 'pre'); $source['translation'] = $this->translate_string($source['value'], $source['keys'], $source['format']); $source['post_process'] = $this->invoke_translation_process($source, 'post'); @@ -57,64 +65,67 @@ class views_plugin_localization extends views_plugin { /** * Translate a string. * - * @param $string + * @param string $string * The string to be translated. - * @param $keys + * @param array $keys * An array of keys to identify the string. Generally constructed from - * view name, display_id, and a property, e.g., 'header'. - * @param $format + * view name, display_id, and a property, e.g. 'header'. + * @param string $format * The input format of the string. This is optional. */ - function translate_string($string, $keys = array(), $format = '') {} + public function translate_string($string, $keys = array(), $format = '') {} /** * Save string source for translation. * - * @param $source + * @param string $source * Full data for the string to be translated. */ - function save($source) { - // Allow other modules to make changes to the string before saving + public function save($source) { + // Allow other modules to make changes to the string before saving. $source['pre_process'] = $this->invoke_translation_process($source, 'pre'); $this->save_string($source['value'], $source['keys'], isset($source['format']) ? $source['format'] : ''); } /** - * Save a string for translation + * Save a string for translation. * - * @param $string + * @param string $string * The string to be translated. - * @param $keys + * @param array $keys * An array of keys to identify the string. Generally constructed from * view name, display_id, and a property, e.g., 'header'. - * @param $format + * @param string $format * The input format of the string. This is optional. */ - function save_string($string, $keys = array(), $format = '') {} + public function save_string($string, $keys = array(), $format = '') {} /** * Delete a string. * - * @param $source + * @param string $source * Full data for the string to be translated. */ - function delete($source) { } + public function delete($source) { + } /** * Collect strings to be exported to code. * - * @param $source + * @param string $source * Full data for the string to be translated. */ - function export($source) { } + public function export($source) { + } /** * Render any collected exported strings to code. * - * @param $indent + * @param string $indent * An optional indentation for prettifying nested code. */ - function export_render($indent = ' ') { } + public function export_render($indent = ' ') { + } /** * Invoke hook_translation_pre_process() or hook_translation_post_process(). @@ -122,7 +133,7 @@ class views_plugin_localization extends views_plugin { * Like node_invoke_nodeapi(), this function is needed to enable both passing * by reference and fetching return values. */ - function invoke_translation_process(&$value, $op) { + public function invoke_translation_process(&$value, $op) { $return = array(); $hook = 'translation_' . $op . '_process'; foreach (module_implements($hook) as $module) { @@ -135,7 +146,10 @@ class views_plugin_localization extends views_plugin { return $return; } - function process_locale_strings($op) { + /** + * + */ + public function process_locale_strings($op) { $this->view->init_display(); foreach ($this->view->display as $display_id => $display) { @@ -154,9 +168,11 @@ class views_plugin_localization extends views_plugin { case 'save': $this->save($data); break; + case 'delete': $this->delete($data); break; + case 'export': $this->export($data); break; @@ -164,6 +180,7 @@ class views_plugin_localization extends views_plugin { } } } + } /** diff --git a/sites/all/modules/views/plugins/views_plugin_localization_core.inc b/sites/all/modules/views/plugins/views_plugin_localization_core.inc index 87443ca..92feb2d 100644 --- a/sites/all/modules/views/plugins/views_plugin_localization_core.inc +++ b/sites/all/modules/views/plugins/views_plugin_localization_core.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the Drupal core localization plugin. + * Definition of views_plugin_localization_core. */ /** @@ -15,35 +15,35 @@ class views_plugin_localization_core extends views_plugin_localization { /** * Translate a string. * - * @param $string + * @param string $string * The string to be translated. - * @param $keys + * @param array $keys * An array of keys to identify the string. Generally constructed from * view name, display_id, and a property, e.g., 'header'. - * @param $format + * @param string $format * The input format of the string. This is optional. */ - function translate_string($string, $keys = array(), $format = '') { + public function translate_string($string, $keys = array(), $format = '') { return t($string); } /** * Save a string for translation. * - * @param $string + * @param string $string * The string to be translated. - * @param $keys + * @param array $keys * An array of keys to identify the string. Generally constructed from * view name, display_id, and a property, e.g., 'header'. - * @param $format + * @param string $format * The input format of the string. This is optional. */ - function save_string($string, $keys = array(), $format = '') { + public function save_string($string, $keys = array(), $format = '') { global $language; // If the current language is 'en', we need to reset the language // in order to trigger an update. - // TODO: add test for number of languages. + // @todo add test for number of languages. if ($language->language == 'en') { $changed = TRUE; $languages = language_list(); @@ -67,22 +67,23 @@ class views_plugin_localization_core extends views_plugin_localization { * * Deletion is not supported. * - * @param $source + * @param mixed $source * Full data for the string to be translated. */ - function delete($source) { + public function delete($source) { return FALSE; } /** * Collect strings to be exported to code. * - * String identifiers are not supported so strings are anonymously in an array. + * String identifiers are not supported so strings are anonymously in an + * array. * - * @param $source + * @param array $source * Full data for the string to be translated. */ - function export($source) { + public function export($source) { if (!empty($source['value'])) { $this->export_strings[] = $source['value']; } @@ -91,10 +92,10 @@ class views_plugin_localization_core extends views_plugin_localization { /** * Render any collected exported strings to code. * - * @param $indent + * @param string $indent * An optional indentation for prettifying nested code. */ - function export_render($indent = ' ') { + public function export_render($indent = ' ') { $output = ''; if (!empty($this->export_strings)) { $this->export_strings = array_unique($this->export_strings); @@ -106,4 +107,5 @@ class views_plugin_localization_core extends views_plugin_localization { } return $output; } + } diff --git a/sites/all/modules/views/plugins/views_plugin_localization_none.inc b/sites/all/modules/views/plugins/views_plugin_localization_none.inc index 620352a..4a1a7d9 100644 --- a/sites/all/modules/views/plugins/views_plugin_localization_none.inc +++ b/sites/all/modules/views/plugins/views_plugin_localization_none.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the 'none' localization plugin. + * Definition of views_plugin_localization_none. */ /** @@ -11,26 +11,31 @@ * @ingroup views_localization_plugins */ class views_plugin_localization_none extends views_plugin_localization { - var $translate = FALSE; + + /** + * {@inheritdoc} + */ + public $translate = FALSE; /** * Translate a string; simply return the string. */ - function translate($source) { + public function translate($source) { return $source['value']; } /** * Save a string for translation; not supported. */ - function save($source) { + public function save($source) { return FALSE; } /** * Delete a string; not supported. */ - function delete($source) { + public function delete($source) { return FALSE; } + } diff --git a/sites/all/modules/views/plugins/views_plugin_pager.inc b/sites/all/modules/views/plugins/views_plugin_pager.inc index 312f54b..0217f4d 100644 --- a/sites/all/modules/views/plugins/views_plugin_pager.inc +++ b/sites/all/modules/views/plugins/views_plugin_pager.inc @@ -17,18 +17,26 @@ * The base plugin to handle pager. */ class views_plugin_pager extends views_plugin { - var $current_page = NULL; - var $total_items = 0; + + /** + * + */ + public $current_page = NULL; + + /** + * + */ + public $total_items = 0; /** * Initialize the plugin. * - * @param $view + * @param view $view * The view object. - * @param $display + * @param object $display * The display handler. */ - function init(&$view, &$display, $options = array()) { + public function init(&$view, &$display, $options = array()) { $this->view = &$view; $this->display = &$display; @@ -41,8 +49,8 @@ class views_plugin_pager extends views_plugin { * All but the leanest pagers should probably return a value here, so * most pagers will not need to override this method. */ - function get_items_per_page() { - return isset($this->options['items_per_page']) ? $this->options['items_per_page'] : 0; + public function get_items_per_page() { + return isset($this->options['items_per_page']) ? (int) $this->options['items_per_page'] : 0; } /** @@ -50,8 +58,8 @@ class views_plugin_pager extends views_plugin { * * This is mostly used for things that will override the value. */ - function set_items_per_page($items) { - $this->options['items_per_page'] = $items; + public function set_items_per_page($items) { + $this->options['items_per_page'] = (int) $items; } /** @@ -60,15 +68,15 @@ class views_plugin_pager extends views_plugin { * Even pagers that don't actually page can skip items at the beginning, * so few pagers will need to override this method. */ - function get_offset() { - return isset($this->options['offset']) ? $this->options['offset'] : 0; + public function get_offset() { + return isset($this->options['offset']) ? (int) $this->options['offset'] : 0; } /** * Set the page offset, or how many items to skip. */ - function set_offset($offset) { - $this->options['offset'] = $offset; + public function set_offset($offset) { + $this->options['offset'] = (int) $offset; } /** @@ -76,18 +84,18 @@ class views_plugin_pager extends views_plugin { * * If NULL, we do not know what the current page is. */ - function get_current_page() { + public function get_current_page() { return $this->current_page; } /** * Set the current page. * - * @param $number + * @param int $number * If provided, the page number will be set to this. If NOT provided, * the page number will be set from the global page array. */ - function set_current_page($number = NULL) { + public function set_current_page($number = NULL) { if (!is_numeric($number) || $number < 0) { $number = 0; } @@ -99,32 +107,34 @@ class views_plugin_pager extends views_plugin { * * If NULL, we do not yet know what the total number of items are. */ - function get_total_items() { + public function get_total_items() { return $this->total_items; } /** - * Get the pager id, if it exists + * Get the pager id, if it exists. */ - function get_pager_id() { + public function get_pager_id() { return !empty($this->options['id']) ? $this->options['id'] : 0; } /** - * Provide the default form form for validating options + * Provide the default form form for validating options. */ - function options_validate(&$form, &$form_state) { } + public function options_validate(&$form, &$form_state) { + } /** - * Provide the default form form for submitting options + * Provide the default form form for submitting options. */ - function options_submit(&$form, &$form_state) { } + public function options_submit(&$form, &$form_state) { + } /** * Return a string to display as the clickable title for the * pager plugin. */ - function summary_title() { + public function summary_title() { return t('Unknown'); } @@ -133,7 +143,7 @@ class views_plugin_pager extends views_plugin { * * Only a couple of very specific pagers will set this to false. */ - function use_pager() { + public function use_pager() { return TRUE; } @@ -142,7 +152,7 @@ class views_plugin_pager extends views_plugin { * * If a pager needs a count query, a simple query */ - function use_count_query() { + public function use_count_query() { return TRUE; } @@ -150,7 +160,7 @@ class views_plugin_pager extends views_plugin { * Execute the count query, which will be done just prior to the query * itself being executed. */ - function execute_count_query(&$count_query) { + public function execute_count_query(&$count_query) { $this->total_items = $count_query->execute()->fetchField(); if (!empty($this->options['offset'])) { $this->total_items -= $this->options['offset']; @@ -164,8 +174,7 @@ class views_plugin_pager extends views_plugin { * If there are pagers that need global values set, this method can * be used to set them. It will be called when the count query is run. */ - function update_page_info() { - + public function update_page_info() { } /** @@ -173,22 +182,26 @@ class views_plugin_pager extends views_plugin { * * This is called during the build phase and can directly modify the query. */ - function query() { } + public function query() { + } /** * Perform any needed actions just prior to the query executing. */ - function pre_execute(&$query) { } + public function pre_execute(&$query) { + } /** * Perform any needed actions just after the query executing. */ - function post_execute(&$result) { } + public function post_execute(&$result) { + } /** * Perform any needed actions just before rendering. */ - function pre_render(&$result) { } + public function pre_render(&$result) { + } /** * Render the pager. @@ -196,39 +209,62 @@ class views_plugin_pager extends views_plugin { * Called during the view render process, this will render the * pager. * - * @param $input + * @param array $input * Any extra GET parameters that should be retained, such as exposed * input. */ - function render($input) { } + public function render($input) { + } /** * Determine if there are more records available. * * This is primarily used to control the display of a more link. */ - function has_more_records() { + public function has_more_records() { return $this->get_items_per_page() && $this->total_items > (intval($this->current_page) + 1) * $this->get_items_per_page(); } - function exposed_form_alter(&$form, &$form_state) { } + /** + * {@inheritdoc} + */ + public function exposed_form_alter(&$form, &$form_state) { + } - function exposed_form_validate(&$form, &$form_state) { } + /** + * {@inheritdoc} + */ + public function exposed_form_validate(&$form, &$form_state) { + } - function exposed_form_submit(&$form, &$form_state, &$exclude) { } + /** + * {@inheritdoc} + */ + public function exposed_form_submit(&$form, &$form_state, &$exclude) { + } - function uses_exposed() { + /** + * {@inheritdoc} + */ + public function uses_exposed() { return FALSE; } - function items_per_page_exposed() { + /** + * {@inheritdoc} + */ + public function items_per_page_exposed() { return FALSE; } - function offset_exposed() { + /** + * {@inheritdoc} + */ + public function offset_exposed() { return FALSE; } + } /** diff --git a/sites/all/modules/views/plugins/views_plugin_pager_full.inc b/sites/all/modules/views/plugins/views_plugin_pager_full.inc index 084aa0a..578bebe 100644 --- a/sites/all/modules/views/plugins/views_plugin_pager_full.inc +++ b/sites/all/modules/views/plugins/views_plugin_pager_full.inc @@ -11,14 +11,21 @@ * @ingroup views_pager_plugins */ class views_plugin_pager_full extends views_plugin_pager { - function summary_title() { + + /** + * {@inheritdoc} + */ + public function summary_title() { if (!empty($this->options['offset'])) { return format_plural($this->options['items_per_page'], '@count item, skip @skip', 'Paged, @count items, skip @skip', array('@count' => $this->options['items_per_page'], '@skip' => $this->options['offset'])); } - return format_plural($this->options['items_per_page'], '@count item', 'Paged, @count items', array('@count' => $this->options['items_per_page'])); + return format_plural($this->options['items_per_page'], '@count item', 'Paged, @count items', array('@count' => $this->options['items_per_page'])); } - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['items_per_page'] = array('default' => 10); $options['offset'] = array('default' => 0); @@ -52,7 +59,7 @@ class views_plugin_pager_full extends views_plugin_pager { /** * Provide the default form for setting options. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $pager_text = $this->display->handler->get_pager_text(); $form['items_per_page'] = array( @@ -90,7 +97,7 @@ class views_plugin_pager_full extends views_plugin_pager { '#default_value' => $this->options['quantity'], ); - $form['tags'] = array ( + $form['tags'] = array( '#type' => 'fieldset', '#collapsible' => FALSE, '#collapsed' => FALSE, @@ -128,7 +135,7 @@ class views_plugin_pager_full extends views_plugin_pager { '#default_value' => $this->options['tags']['last'], ); - $form['expose'] = array ( + $form['expose'] = array( '#type' => 'fieldset', '#collapsible' => FALSE, '#collapsed' => FALSE, @@ -152,7 +159,7 @@ class views_plugin_pager_full extends views_plugin_pager { '#description' => t('Label to use in the exposed items per page form element.'), '#default_value' => $this->options['expose']['items_per_page_label'], '#dependency' => array( - 'edit-pager-options-expose-items-per-page' => array(1) + 'edit-pager-options-expose-items-per-page' => array(1), ), ); @@ -163,11 +170,10 @@ class views_plugin_pager_full extends views_plugin_pager { '#description' => t('Set between which values the user can choose when determining the items per page. Separated by comma.'), '#default_value' => $this->options['expose']['items_per_page_options'], '#dependency' => array( - 'edit-pager-options-expose-items-per-page' => array(1) + 'edit-pager-options-expose-items-per-page' => array(1), ), ); - $form['expose']['items_per_page_options_all'] = array( '#type' => 'checkbox', '#title' => t('Include all items option'), @@ -199,19 +205,22 @@ class views_plugin_pager_full extends views_plugin_pager { '#description' => t('Label to use in the exposed offset form element.'), '#default_value' => $this->options['expose']['offset_label'], '#dependency' => array( - 'edit-pager-options-expose-offset' => array(1) + 'edit-pager-options-expose-offset' => array(1), ), ); } - function options_validate(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_validate(&$form, &$form_state) { // Only accept integer values. $error = FALSE; $exposed_options = $form_state['values']['pager_options']['expose']['items_per_page_options']; if (strpos($exposed_options, '.') !== FALSE) { $error = TRUE; } - $options = explode(',',$exposed_options); + $options = explode(',', $exposed_options); if (!$error && is_array($options)) { foreach ($options as $option) { if (!is_numeric($option) || intval($option) == 0) { @@ -237,10 +246,13 @@ class views_plugin_pager_full extends views_plugin_pager { } } - function query() { + /** + * {@inheritdoc} + */ + public function query() { if ($this->items_per_page_exposed()) { if (!empty($_GET['items_per_page']) && $_GET['items_per_page'] > 0) { - $this->options['items_per_page'] = $_GET['items_per_page']; + $this->options['items_per_page'] = (int) $_GET['items_per_page']; } elseif (!empty($_GET['items_per_page']) && $_GET['items_per_page'] == 'All' && $this->options['expose']['items_per_page_options_all']) { $this->options['items_per_page'] = 0; @@ -248,16 +260,15 @@ class views_plugin_pager_full extends views_plugin_pager { } if ($this->offset_exposed()) { if (isset($_GET['offset']) && $_GET['offset'] >= 0) { - $this->options['offset'] = $_GET['offset']; + $this->options['offset'] = (int) $_GET['offset']; } } - $limit = $this->options['items_per_page']; - $offset = $this->current_page * $this->options['items_per_page'] + $this->options['offset']; + $limit = $this->get_items_per_page(); + $offset = $this->current_page * $limit + $this->get_offset(); if (!empty($this->options['total_pages'])) { if ($this->current_page >= $this->options['total_pages']) { - $limit = $this->options['items_per_page']; - $offset = $this->options['total_pages'] * $this->options['items_per_page']; + $offset = $this->options['total_pages'] * $limit; } } @@ -265,7 +276,10 @@ class views_plugin_pager_full extends views_plugin_pager { $this->view->query->set_offset($offset); } - function render($input) { + /** + * {@inheritdoc} + */ + public function render($input) { $pager_theme = views_theme_functions('pager', $this->view, $this->display); // The 0, 1, 3, 4 index are correct. See theme_pager documentation. $tags = array( @@ -286,11 +300,11 @@ class views_plugin_pager_full extends views_plugin_pager { /** * Set the current page. * - * @param $number + * @param int $number * If provided, the page number will be set to this. If NOT provided, * the page number will be set from the global page array. */ - function set_current_page($number = NULL) { + public function set_current_page($number = NULL) { if (isset($number)) { $this->current_page = $number; return; @@ -320,7 +334,10 @@ class views_plugin_pager_full extends views_plugin_pager { } } - function get_pager_total() { + /** + * {@inheritdoc} + */ + public function get_pager_total() { if ($items_per_page = intval($this->get_items_per_page())) { return ceil($this->total_items / $items_per_page); } @@ -336,7 +353,7 @@ class views_plugin_pager_full extends views_plugin_pager { * items available and to update the current page if the requested * page is out of range. */ - function update_page_info() { + public function update_page_info() { if (!empty($this->options['total_pages'])) { if (($this->options['total_pages'] * $this->options['items_per_page']) < $this->total_items) { $this->total_items = $this->options['total_pages'] * $this->options['items_per_page']; @@ -356,34 +373,47 @@ class views_plugin_pager_full extends views_plugin_pager { // Calculate and set the count of available pages. $pager_total[$pager_id] = $this->get_pager_total(); - // See if the requested page was within range: + // See if the requested page was within range. if ($this->current_page < 0) { $this->current_page = 0; } - else if ($this->current_page >= $pager_total[$pager_id]) { - // Pages are numbered from 0 so if there are 10 pages, the last page is 9. + elseif ($this->current_page >= $pager_total[$pager_id]) { + // Pages are numbered from 0 so if there are 10 pages, the last page is + // 9. $this->current_page = $pager_total[$pager_id] - 1; } - // Put this number in to guarantee that we do not generate notices when the pager - // goes to look for it later. + // Put this number in to guarantee that we do not generate notices when + // the pager goes to look for it later. $pager_page_array[$pager_id] = $this->current_page; } } - function uses_exposed() { + /** + * + */ + public function uses_exposed() { return $this->items_per_page_exposed() || $this->offset_exposed(); } - function items_per_page_exposed() { + /** + * + */ + public function items_per_page_exposed() { return !empty($this->options['expose']['items_per_page']); } - function offset_exposed() { + /** + * + */ + public function offset_exposed() { return !empty($this->options['expose']['offset']); } - function exposed_form_alter(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function exposed_form_alter(&$form, &$form_state) { if ($this->items_per_page_exposed()) { $options = explode(',', $this->options['expose']['items_per_page_options']); $sanitized_options = array(); @@ -414,11 +444,15 @@ class views_plugin_pager_full extends views_plugin_pager { } } - function exposed_form_validate(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function exposed_form_validate(&$form, &$form_state) { if (!empty($form_state['values']['offset']) && trim($form_state['values']['offset'])) { if (!is_numeric($form_state['values']['offset']) || $form_state['values']['offset'] < 0) { - form_set_error('offset', t('Offset must be an number greater or equal than 0.')); + form_set_error('offset', t('Offset must be a number greater than or equal to 0.')); } } } + } diff --git a/sites/all/modules/views/plugins/views_plugin_pager_mini.inc b/sites/all/modules/views/plugins/views_plugin_pager_mini.inc index 87d5541..4e7dc35 100644 --- a/sites/all/modules/views/plugins/views_plugin_pager_mini.inc +++ b/sites/all/modules/views/plugins/views_plugin_pager_mini.inc @@ -11,21 +11,24 @@ * @ingroup views_pager_plugins */ class views_plugin_pager_mini extends views_plugin_pager_full { - function summary_title() { + + /** + * {@inheritdoc} + */ + public function summary_title() { if (!empty($this->options['offset'])) { return format_plural($this->options['items_per_page'], 'Mini pager, @count item, skip @skip', 'Mini pager, @count items, skip @skip', array('@count' => $this->options['items_per_page'], '@skip' => $this->options['offset'])); } - return format_plural($this->options['items_per_page'], 'Mini pager, @count item', 'Mini pager, @count items', array('@count' => $this->options['items_per_page'])); + return format_plural($this->options['items_per_page'], 'Mini pager, @count item', 'Mini pager, @count items', array('@count' => $this->options['items_per_page'])); } /** - * Overrides views_plugin_pager_full::option_definition(). - * - * Overrides the full pager options form by deleting unused settings. + * {@inheritdoc} */ - function option_definition() { + public function option_definition() { $options = parent::option_definition(); + // Overrides the full pager options form by deleting unused settings. unset($options['quantity']); unset($options['tags']['first']); unset($options['tags']['last']); @@ -36,25 +39,25 @@ class views_plugin_pager_mini extends views_plugin_pager_full { } /** - * Overrides views_plugin_pager_full::options_form(). - * - * Overrides the full pager options form by deleting unused settings. + * {@inheritdoc} */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); + + // Overrides the full pager options form by deleting unused settings. unset($form['quantity']); unset($form['tags']['first']); unset($form['tags']['last']); } /** - * Overrides views_plugin_pager_full::render(). - * - * Overrides the full pager renderer by changing the theme function - * and leaving out variables that are not used in the mini pager. + * {@inheritdoc} */ - function render($input) { + public function render($input) { + // Overrides the full pager renderer by changing the theme function and + // leaving out variables that are not used in the mini pager. $pager_theme = views_theme_functions('views_mini_pager', $this->view, $this->display); + // The 1, 3 index are correct. // @see theme_pager(). $tags = array( @@ -67,4 +70,5 @@ class views_plugin_pager_mini extends views_plugin_pager_full { 'parameters' => $input, )); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_pager_none.inc b/sites/all/modules/views/plugins/views_plugin_pager_none.inc index 12b96d0..3faa301 100644 --- a/sites/all/modules/views/plugins/views_plugin_pager_none.inc +++ b/sites/all/modules/views/plugins/views_plugin_pager_none.inc @@ -12,21 +12,30 @@ */ class views_plugin_pager_none extends views_plugin_pager { - function init(&$view, &$display, $options = array()) { + /** + * {@inheritdoc} + */ + public function init(&$view, &$display, $options = array()) { parent::init($view, $display, $options); // If the pager is set to none, then it should show all items. $this->set_items_per_page(0); } - function summary_title() { + /** + * {@inheritdoc} + */ + public function summary_title() { if (!empty($this->options['offset'])) { return t('All items, skip @skip', array('@skip' => $this->options['offset'])); } return t('All items'); } - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['offset'] = array('default' => 0); @@ -36,7 +45,7 @@ class views_plugin_pager_none extends views_plugin_pager { /** * Provide the default form for setting options. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['offset'] = array( '#type' => 'textfield', @@ -46,30 +55,50 @@ class views_plugin_pager_none extends views_plugin_pager { ); } - function use_pager() { + /** + * {@inheritdoc} + */ + public function use_pager() { return FALSE; } - function use_count_query() { + /** + * {@inheritdoc} + */ + public function use_count_query() { return FALSE; } - function get_items_per_page() { + /** + * {@inheritdoc} + */ + public function get_items_per_page() { return 0; } - function execute_count_query(&$count_query) { - // If we are displaying all items, never count. But we can update the count in post_execute. + /** + * {@inheritdoc} + */ + public function execute_count_query(&$count_query) { + // If we are displaying all items, never count. But we can update the count + // in post_execute. } - function post_execute(&$result) { + /** + * {@inheritdoc} + */ + public function post_execute(&$result) { $this->total_items = count($result); } - function query() { + /** + * {@inheritdoc} + */ + public function query() { // The only query modifications we might do are offsets. if (!empty($this->options['offset'])) { $this->view->query->set_offset($this->options['offset']); } } + } diff --git a/sites/all/modules/views/plugins/views_plugin_pager_some.inc b/sites/all/modules/views/plugins/views_plugin_pager_some.inc index 09452ce..12025b2 100644 --- a/sites/all/modules/views/plugins/views_plugin_pager_some.inc +++ b/sites/all/modules/views/plugins/views_plugin_pager_some.inc @@ -11,14 +11,21 @@ * @ingroup views_pager_plugins */ class views_plugin_pager_some extends views_plugin_pager { - function summary_title() { + + /** + * + */ + public function summary_title() { if (!empty($this->options['offset'])) { return format_plural($this->options['items_per_page'], '@count item, skip @skip', '@count items, skip @skip', array('@count' => $this->options['items_per_page'], '@skip' => $this->options['offset'])); } - return format_plural($this->options['items_per_page'], '@count item', '@count items', array('@count' => $this->options['items_per_page'])); + return format_plural($this->options['items_per_page'], '@count item', '@count items', array('@count' => $this->options['items_per_page'])); } - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['items_per_page'] = array('default' => 10); $options['offset'] = array('default' => 0); @@ -29,7 +36,7 @@ class views_plugin_pager_some extends views_plugin_pager { /** * Provide the default form for setting options. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $pager_text = $this->display->handler->get_pager_text(); $form['items_per_page'] = array( @@ -47,16 +54,26 @@ class views_plugin_pager_some extends views_plugin_pager { ); } - function use_pager() { + /** + * {@inheritdoc} + */ + public function use_pager() { return FALSE; } - function use_count_query() { + /** + * {@inheritdoc} + */ + public function use_count_query() { return FALSE; } - function query() { + /** + * {@inheritdoc} + */ + public function query() { $this->view->query->set_limit($this->options['items_per_page']); $this->view->query->set_offset($this->options['offset']); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_query.inc b/sites/all/modules/views/plugins/views_plugin_query.inc index 7418e61..fe45793 100644 --- a/sites/all/modules/views/plugins/views_plugin_query.inc +++ b/sites/all/modules/views/plugins/views_plugin_query.inc @@ -2,7 +2,7 @@ /** * @file - * Defines the base query class, which is the underlying layer in a View. + * Definition of views_plugin_query. */ /** @@ -14,20 +14,21 @@ */ /** - * Object used to create a SELECT query. + * The base query class, which is the underlying layer in a View. */ class views_plugin_query extends views_plugin { + /** * A pager plugin that should be provided by the display. * * @var views_plugin_pager */ - var $pager = NULL; + public $pager = NULL; /** * Constructor; Create the basic query object and fill with default values. */ - function init($base_table, $base_field, $options) { + public function init($base_table, $base_field, $options) { $this->base_table = $base_table; $this->base_field = $base_field; $this->unpack_options($this->options, $options); @@ -37,13 +38,14 @@ class views_plugin_query extends views_plugin { * Generate a query and a countquery from all of the information supplied * to the object. * - * @param $get_count - * Provide a countquery if this is true, otherwise provide a normal query. + * @param bool $get_count + * Provide a countquery if this is TRUE, otherwise provide a normal query. * * @return SelectQuery * A SelectQuery object. */ - function query($get_count = FALSE) { } + public function query($get_count = FALSE) { + } /** * Let modules modify the query just prior to finalizing it. @@ -51,7 +53,8 @@ class views_plugin_query extends views_plugin { * @param view $view * The view which is executed. */ - function alter(&$view) { } + public function alter(&$view) { + } /** * Builds the necessary info to execute the query. @@ -59,7 +62,8 @@ class views_plugin_query extends views_plugin { * @param view $view * The view which is executed. */ - function build(&$view) { } + public function build(&$view) { + } /** * Executes the query and fills the associated view object with according @@ -74,7 +78,8 @@ class views_plugin_query extends views_plugin { * @param view $view * The view which is executed. */ - function execute(&$view) { } + public function execute(&$view) { + } /** * Add a signature to the query, if such a thing is feasible. @@ -85,48 +90,61 @@ class views_plugin_query extends views_plugin { * @param view $view * The view which is executed. */ - function add_signature(&$view) { } + public function add_signature(&$view) { + } /** * Get aggregation info for group by queries. * * If NULL, aggregation is not allowed. */ - function get_aggregation_info() { } + public function get_aggregation_info() { + } /** * Add settings for the ui. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); } - function options_validate(&$form, &$form_state) { } + /** + * {@inheritdoc} + */ + public function options_validate(&$form, &$form_state) { + } - function options_submit(&$form, &$form_state) { } + /** + * {@inheritdoc} + */ + public function options_submit(&$form, &$form_state) { + } - function summary_title() { + /** + * {@inheritdoc} + */ + public function summary_title() { return t('Settings'); } /** * Set a LIMIT on the query, specifying a maximum number of results. */ - function set_limit($limit) { + public function set_limit($limit) { $this->limit = $limit; } /** * Set an OFFSET on the query, specifying a number of results to skip */ - function set_offset($offset) { + public function set_offset($offset) { $this->offset = $offset; } /** * Render the pager, if necessary. */ - function render_pager($exposed_input) { + public function render_pager($exposed_input) { if (!empty($this->pager) && $this->pager->use_pager()) { return $this->pager->render($exposed_input); } @@ -137,18 +155,18 @@ class views_plugin_query extends views_plugin { /** * Create a new grouping for the WHERE or HAVING clause. * - * @param $type + * @param string $type * Either 'AND' or 'OR'. All items within this group will be added * to the WHERE clause with this logical operator. - * @param $group + * @param string $group * An ID to use for this group. If unspecified, an ID will be generated. - * @param $where + * @param string $where * 'where' or 'having'. * - * @return $group + * @return string * The group ID generated. */ - function set_where_group($type = 'AND', $group = NULL, $where = 'where') { + public function set_where_group($type = 'AND', $group = NULL, $where = 'where') { // Set an alias. $groups = &$this->$where; @@ -168,19 +186,20 @@ class views_plugin_query extends views_plugin { /** * Control how all WHERE and HAVING groups are put together. * - * @param $type - * Either 'AND' or 'OR' + * @param string $type + * Either 'AND' or 'OR'. */ - function set_group_operator($type = 'AND') { + public function set_group_operator($type = 'AND') { $this->group_operator = strtoupper($type); } /** * Returns the according entity objects for the given query results. */ - function get_result_entities($results, $relationship = NULL) { + public function get_result_entities($results, $relationship = NULL) { return FALSE; } + } /** diff --git a/sites/all/modules/views/plugins/views_plugin_query_default.inc b/sites/all/modules/views/plugins/views_plugin_query_default.inc index 99e0f0e..db3e7e2 100644 --- a/sites/all/modules/views/plugins/views_plugin_query_default.inc +++ b/sites/all/modules/views/plugins/views_plugin_query_default.inc @@ -2,7 +2,7 @@ /** * @file - * Defines the default query object. + * Definition of views_plugin_query_default. */ /** @@ -15,95 +15,98 @@ class views_plugin_query_default extends views_plugin_query { /** * A list of tables in the order they should be added, keyed by alias. */ - var $table_queue = array(); + public $table_queue = array(); /** - * Holds an array of tables and counts added so that we can create aliases + * Holds an array of tables and counts added so that we can create aliases. */ - var $tables = array(); + public $tables = array(); /** * Holds an array of relationships, which are aliases of the primary * table that represent different ways to join the same table in. */ - var $relationships = array(); + public $relationships = array(); /** * An array of sections of the WHERE query. Each section is in itself * an array of pieces and a flag as to whether or not it should be AND * or OR. */ - var $where = array(); + public $where = array(); + /** * An array of sections of the HAVING query. Each section is in itself * an array of pieces and a flag as to whether or not it should be AND * or OR. */ - var $having = array(); + public $having = array(); + /** * The default operator to use when connecting the WHERE groups. May be * AND or OR. */ - var $group_operator = 'AND'; + public $group_operator = 'AND'; /** * A simple array of order by clauses. */ - var $orderby = array(); + public $orderby = array(); /** * A simple array of group by clauses. */ - var $groupby = array(); - + public $groupby = array(); /** * An array of fields. */ - var $fields = array(); - + public $fields = array(); /** * The table header to use for tablesort. This matters because tablesort * needs to modify the query and needs the header. */ - var $header = array(); + public $header = array(); /** * A flag as to whether or not to make the primary field distinct. */ - var $distinct = FALSE; + public $distinct = FALSE; - var $has_aggregate = FALSE; + /** + * + */ + public $has_aggregate = FALSE; /** * Should this query be optimized for counts, for example no sorts. */ - var $get_count_optimized = NULL; + public $get_count_optimized = NULL; /** * The current used pager plugin. * * @var views_plugin_pager */ - var $pager = NULL; + public $pager = NULL; - /** + /** * An array mapping table aliases and field names to field aliases. */ - var $field_aliases = array(); + public $field_aliases = array(); - /** + /** * Query tags which will be passed over to the dbtng query object. */ - var $tags = array(); + public $tags = array(); /** * Is the view marked as not distinct. * * @var bool */ - var $no_distinct; + public $no_distinct; /** * Defines the distinct type. @@ -115,20 +118,21 @@ class views_plugin_query_default extends views_plugin_query { public $pure_distinct = FALSE; /** - * Constructor; Create the basic query object and fill with default values. + * {@inheritdoc} */ - function init($base_table = 'node', $base_field = 'nid', $options) { + public function init($base_table = 'node', $base_field = 'nid', $options) { parent::init($base_table, $base_field, $options); - $this->base_table = $base_table; // Predefine these above, for clarity. + $this->base_table = $base_table; + // Predefine these above, for clarity. $this->base_field = $base_field; $this->relationships[$base_table] = array( 'link' => NULL, 'table' => $base_table, 'alias' => $base_table, - 'base' => $base_table + 'base' => $base_table, ); - // init the table queue with our primary table. + // Unit the table queue with our primary table. $this->table_queue[$base_table] = array( 'alias' => $base_table, 'table' => $base_table, @@ -136,22 +140,20 @@ class views_plugin_query_default extends views_plugin_query { 'join' => NULL, ); - // init the tables with our primary table + // Init the tables with our primary table. $this->tables[$base_table][$base_table] = array( 'count' => 1, 'alias' => $base_table, ); -/** - * -- we no longer want the base field to appear automatically. - if ($base_field) { - $this->fields[$base_field] = array( - 'table' => $base_table, - 'field' => $base_field, - 'alias' => $base_field, - ); - } - */ + // We no longer want the base field to appear automatically. + // if ($base_field) { + // $this->fields[$base_field] = array( + // 'table' => $base_table, + // 'field' => $base_field, + // 'alias' => $base_field, + // ); + // } $this->count_field = array( 'table' => $base_table, @@ -161,8 +163,9 @@ class views_plugin_query_default extends views_plugin_query { ); } - // ---------------------------------------------------------------- - // Utility methods to set flags and data. + /** + * Utility methods to set flags and data. + */ /** * Set the view to be distinct. @@ -175,7 +178,7 @@ class views_plugin_query_default extends views_plugin_query { * @param bool $pure_distinct * Should only the sql keyword be added. */ - function set_distinct($value = TRUE, $pure_distinct = FALSE) { + public function set_distinct($value = TRUE, $pure_distinct = FALSE) { if (!(isset($this->no_distinct) && $value)) { $this->distinct = $value; $this->pure_distinct = $pure_distinct; @@ -185,7 +188,7 @@ class views_plugin_query_default extends views_plugin_query { /** * Set what field the query will count() on for paging. */ - function set_count_field($table, $field, $alias = NULL) { + public function set_count_field($table, $field, $alias = NULL) { if (empty($alias)) { $alias = $table . '_' . $field; } @@ -198,14 +201,19 @@ class views_plugin_query_default extends views_plugin_query { } /** - * Set the table header; used for click-sorting because it's needed - * info to modify the ORDER BY clause. + * Set the table header. + * + * Used for click-sorting because it's needed info to modify the ORDER BY + * clause. */ - function set_header($header) { + public function set_header($header) { $this->header = $header; } - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['disable_sql_rewrite'] = array( 'default' => FALSE, @@ -237,16 +245,29 @@ class views_plugin_query_default extends views_plugin_query { /** * Add settings for the ui. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); - $form['disable_sql_rewrite'] = array( - '#title' => t('Disable SQL rewriting'), - '#description' => t('Disabling SQL rewriting will disable node_access checks as well as other modules that implement hook_query_alter().'), - '#type' => 'checkbox', - '#default_value' => !empty($this->options['disable_sql_rewrite']), - '#suffix' => ' ', - ); + // Establish which query tag will be affected by disable_sql_rewrite. + // This 'access query tag' is defined by hook_views_data() for the base table. + // e.g. node_views_data() + if (!empty($form_state['view']->base_table)) { + $base_table = $form_state['view']->base_table; + $base_table_data = views_fetch_data($base_table); + if (!empty($base_table_data['table']['base']['access query tag'])) { + $access_tag = $base_table_data['table']['base']['access query tag']; + $disable_rewrite = !empty($this->options['disable_sql_rewrite']); + $form['disable_sql_rewrite'] = array( + '#title' => t('Disable access checks'), + '#description' => t('Do not apply %access_tag checks to this query. Selecting this option omits that tag from the alterable query.', array('%access_tag' => $access_tag)), + '#type' => 'checkbox', + '#default_value' => $disable_rewrite, + '#suffix' => ' ', + ); + } + } $form['distinct'] = array( '#type' => 'checkbox', '#title' => t('Distinct'), @@ -284,45 +305,45 @@ class views_plugin_query_default extends views_plugin_query { /** * Special submit handling. */ - function options_submit(&$form, &$form_state) { + public function options_submit(&$form, &$form_state) { $element = array('#parents' => array('query', 'options', 'query_tags')); $value = explode(',', drupal_array_get_nested_value($form_state['values'], $element['#parents'])); $value = array_filter(array_map('trim', $value)); form_set_value($element, $value, $form_state); } - // ---------------------------------------------------------------- - // Table/join adding + /** + * Table/join adding. + */ /** - * A relationship is an alternative endpoint to a series of table - * joins. Relationships must be aliases of the primary table and - * they must join either to the primary table or to a pre-existing - * relationship. + * A relationship is an alternative endpoint to a series of table joins. * - * An example of a relationship would be a nodereference table. - * If you have a nodereference named 'book_parent' which links to a - * parent node, you could set up a relationship 'node_book_parent' - * to 'node'. Then, anything that links to 'node' can link to - * 'node_book_parent' instead, thus allowing all properties of - * both nodes to be available in the query. + * Relationships must be aliases of the primary table and they must join + * either to the primary table or to a pre-existing relationship. * - * @param $alias - * What this relationship will be called, and is also the alias - * for the table. + * An example of a relationship would be a nodereference table. If you have a + * nodereference named 'book_parent' which links to a parent node, you could + * set up a relationship 'node_book_parent' to 'node'. Then, anything that + * links to 'node' can link to 'node_book_parent' instead, thus allowing all + * properties of both nodes to be available in the query. + * + * @param string $alias + * What this relationship will be called, and is also the alias for the + * table. * @param views_join $join * A views_join object (or derived object) to join the alias in. - * @param $base - * The name of the 'base' table this relationship represents; this - * tells the join search which path to attempt to use when finding - * the path to this relationship. - * @param $link_point - * If this relationship links to something other than the primary - * table, specify that table here. For example, a 'track' node - * might have a relationship to an 'album' node, which might - * have a relationship to an 'artist' node. + * @param string $base + * The name of the 'base' table this relationship represents; this tells the + * join search which path to attempt to use when finding the path to this + * relationship. + * @param string $link_point + * If this relationship links to something other than the primary table, + * specify that table here. For example, a 'track' node might have a + * relationship to an 'album' node, which might have a relationship to an + * 'artist' node. */ - function add_relationship($alias, $join, $base, $link_point = NULL) { + public function add_relationship($alias, $join, $base, $link_point = NULL) { if (empty($link_point)) { $link_point = $this->base_table; } @@ -342,8 +363,7 @@ class views_plugin_query_default extends views_plugin_query { $join = $this->adjust_join($join, $link_point); } - // Add the table directly to the queue to avoid accidentally marking - // it. + // Add the table directly to the queue to avoid accidentally marking it. $this->table_queue[$alias] = array( 'table' => $join->table, 'num' => 1, @@ -369,34 +389,34 @@ class views_plugin_query_default extends views_plugin_query { /** * Add a table to the query, ensuring the path exists. * - * This function will test to ensure that the path back to the primary - * table is valid and exists; if you do not wish for this testing to - * occur, use $query->queue_table() instead. + * This function will test to ensure that the path back to the primary table + * is valid and exists; if you do not wish for this testing to occur, use + * $query->queue_table() instead. * - * @param $table + * @param string $table * The name of the table to add. It needs to exist in the global table * array. - * @param $relationship - * An alias of a table; if this is set, the path back to this table will - * be tested prior to adding the table, making sure that all intermediary - * tables exist and are properly aliased. If set to NULL the path to - * the primary table will be ensured. If the path cannot be made, the - * table will NOT be added. + * @param string $relationship + * An alias of a table; if this is set, the path back to this table will be + * tested prior to adding the table, making sure that all intermediary + * tables exist and are properly aliased. If set to NULL the path to the + * primary table will be ensured. If the path cannot be made, the table + * will NOT be added. * @param views_join $join - * In some join configurations this table may actually join back through - * a different method; this is most likely to be used when tracing - * a hierarchy path. (node->parent->parent2->parent3). This parameter - * will specify how this table joins if it is not the default. - * @param $alias + * In some join configurations this table may actually join back through a + * different method; this is most likely to be used when tracing a + * hierarchy path. (node->parent->parent2->parent3). This parameter will + * specify how this table joins if it is not the default. + * @param string $alias * A specific alias to use, rather than the default alias. * - * @return $alias + * @return string * The alias of the table; this alias can be used to access information * about the table and should always be used to refer to the table when * adding parts to the query. Or FALSE if the table was not able to be * added. */ - function add_table($table, $relationship = NULL, $join = NULL, $alias = NULL) { + public function add_table($table, $relationship = NULL, $join = NULL, $alias = NULL) { if (!$this->ensure_path($table, $relationship, $join)) { return FALSE; } @@ -415,27 +435,27 @@ class views_plugin_query_default extends views_plugin_query { * ensure_table() should be used instead of this one, unless you are * absolutely sure this is what you want. * - * @param $table + * @param string $table * The name of the table to add. It needs to exist in the global table * array. - * @param $relationship + * @param string $relationship * The primary table alias this table is related to. If not set, the * primary table will be used. * @param views_join $join - * In some join configurations this table may actually join back through - * a different method; this is most likely to be used when tracing - * a hierarchy path. (node->parent->parent2->parent3). This parameter - * will specify how this table joins if it is not the default. - * @param $alias + * In some join configurations this table may actually join back through a + * different method; this is most likely to be used when tracing a + * hierarchy path. (node->parent->parent2->parent3). This parameter will + * specify how this table joins if it is not the default. + * @param string $alias * A specific alias to use, rather than the default alias. * - * @return $alias + * @return string * The alias of the table; this alias can be used to access information * about the table and should always be used to refer to the table when * adding parts to the query. Or FALSE if the table was not able to be * added. */ - function queue_table($table, $relationship = NULL, $join = NULL, $alias = NULL) { + public function queue_table($table, $relationship = NULL, $join = NULL, $alias = NULL) { // If the alias is set, make sure it doesn't already exist. if (isset($this->table_queue[$alias])) { return $alias; @@ -458,8 +478,8 @@ class views_plugin_query_default extends views_plugin_query { } } - // Check this again to make sure we don't blow up existing aliases for already - // adjusted joins. + // Check this again to make sure we don't blow up existing aliases for + // already adjusted joins. if (isset($this->table_queue[$alias])) { return $alias; } @@ -471,8 +491,8 @@ class views_plugin_query_default extends views_plugin_query { $alias = $this->tables[$relationship][$table]['alias'] . $this->tables[$relationship][$table]['count']; } - // If this is a relationship based table, add a marker with - // the relationship as a primary table for the alias. + // If this is a relationship based table, add a marker with the + // relationship as a primary table for the alias. if ($table != $alias) { $this->mark_table($alias, $this->base_table, $alias); } @@ -498,14 +518,17 @@ class views_plugin_query_default extends views_plugin_query { return $alias; } - function mark_table($table, $relationship, $alias) { + /** + * + */ + public function mark_table($table, $relationship, $alias) { // Mark that this table has been added. if (empty($this->tables[$relationship][$table])) { if (!isset($alias)) { $alias = ''; if ($relationship != $this->base_table) { - // double underscore will help prevent accidental name - // space collisions. + // Double underscore will help prevent accidental name space + // collisions. $alias = $relationship . '__'; } $alias .= $table; @@ -523,33 +546,33 @@ class views_plugin_query_default extends views_plugin_query { } /** - * Ensure a table exists in the queue; if it already exists it won't - * do anything, but if it doesn't it will add the table queue. It will ensure - * a path leads back to the relationship table. + * Ensure a table exists in the queue; if it already exists it won't do + * anything, but if it doesn't it will add the table queue. It will ensure a + * path leads back to the relationship table. * - * @param $table + * @param string $table * The unaliased name of the table to ensure. - * @param $relationship + * @param string $relationship * The relationship to ensure the table links to. Each relationship will - * get a unique instance of the table being added. If not specified, - * will be the primary table. + * get a unique instance of the table being added. If not specified, will + * be the primary table. * @param views_join $join * A views_join object (or derived object) to join the alias in. * - * @return + * @return string * The alias used to refer to this specific table, or NULL if the table * cannot be ensured. */ - function ensure_table($table, $relationship = NULL, $join = NULL) { - // ensure a relationship + public function ensure_table($table, $relationship = NULL, $join = NULL) { + // Ensure a relationship. if (empty($relationship)) { $relationship = $this->base_table; } // If the relationship is the primary table, this actually be a relationship - // link back from an alias. We store all aliases along with the primary table - // to detect this state, because eventually it'll hit a table we already - // have and that's when we want to stop. + // link back from an alias. We store all aliases along with the primary + // table to detect this state, because eventually it'll hit a table we + // already have and that's when we want to stop. if ($relationship == $this->base_table && !empty($this->tables[$relationship][$table])) { return $this->tables[$relationship][$table]['alias']; } @@ -578,31 +601,28 @@ class views_plugin_query_default extends views_plugin_query { $join = $this->adjust_join($join, $relationship); if ($this->ensure_path($table, $relationship, $join)) { - // Attempt to eliminate redundant joins. If this table's - // relationship and join exactly matches an existing table's - // relationship and join, we do not have to join to it again; - // just return the existing table's alias. See - // http://groups.drupal.org/node/11288 for details. + // Attempt to eliminate redundant joins. If this table's relationship + // and join exactly matches an existing table's relationship and join, we + // do not have to join to it again; just return the existing table's + // alias. + // @see http://groups.drupal.org/node/11288 // - // This can be done safely here but not lower down in - // queue_table(), because queue_table() is also used by - // add_table() which requires the ability to intentionally add - // the same table with the same join multiple times. For - // example, a view that filters on 3 taxonomy terms using AND - // needs to join taxonomy_term_data 3 times with the same join. - + // This can be done safely here but not lower down in queue_table(), + // because queue_table() is also used by add_table() which requires the + // ability to intentionally add the same table with the same join + // multiple times. For example, a view that filters on 3 taxonomy terms + // using AND needs to join taxonomy_term_data 3 times with the same join. // scan through the table queue to see if a matching join and // relationship exists. If so, use it instead of this join. - - // TODO: Scanning through $this->table_queue results in an - // O(N^2) algorithm, and this code runs every time the view is - // instantiated (Views 2 does not currently cache queries). - // There are a couple possible "improvements" but we should do - // some performance testing before picking one. + // @todo Scanning through $this->table_queue results in an O(N^2) + // algorithm, and this code runs every time the view is instantiated + // (Views 2 does not currently cache queries). There are a couple + // possible "improvements" but we should do some performance testing + // before picking one. foreach ($this->table_queue as $queued_table) { - // In PHP 4 and 5, the == operation returns TRUE for two objects - // if they are instances of the same class and have the same - // attributes and values. + // In PHP 4 and 5, the == operation returns TRUE for two objects if + // they are instances of the same class and have the same attributes + // and values. if ($queued_table['relationship'] == $relationship && $queued_table['join'] == $join) { return $queued_table['alias']; } @@ -614,12 +634,12 @@ class views_plugin_query_default extends views_plugin_query { /** * Make sure that the specified table can be properly linked to the primary - * table in the JOINs. This function uses recursion. If the tables - * needed to complete the path back to the primary table are not in the - * query they will be added, but additional copies will NOT be added - * if the table is already there. + * table in the JOINs. This function uses recursion. If the tables needed + * to complete the path back to the primary table are not in the query they + * will be added, but additional copies will NOT be added if the table is + * already there. */ - function ensure_path($table, $relationship = NULL, $join = NULL, $traced = array(), $add = array()) { + public function ensure_path($table, $relationship = NULL, $join = NULL, $traced = array(), $add = array()) { if (!isset($relationship)) { $relationship = $this->base_table; } @@ -652,7 +672,7 @@ class views_plugin_query_default extends views_plugin_query { // Have we been this way? if (isset($traced[$join->left_table])) { - // we looped. Broked. + // We looped. Broked. return FALSE; } @@ -668,10 +688,12 @@ class views_plugin_query_default extends views_plugin_query { } /** - * Fix a join to adhere to the proper relationship; the left table can vary - * based upon what relationship items are joined in on. + * Fix a join to adhere to the proper relationship. + * + * The left table can vary based upon what relationship items are joined in + * on. */ - function adjust_join($join, $relationship) { + public function adjust_join($join, $relationship) { if (!empty($join->adjusted)) { return $join; } @@ -683,9 +705,8 @@ class views_plugin_query_default extends views_plugin_query { // Adjusts the left table for our relationship. if ($relationship != $this->base_table) { // If we're linking to the primary table, the relationship to use will - // be the prior relationship. Unless it's a direct link. - - // Safety! Don't modify an original here. + // be the prior relationship. Unless it's a direct link. Safety! Don't + // modify an original here. $join = clone $join; // Do we need to try to ensure a path? @@ -695,7 +716,8 @@ class views_plugin_query_default extends views_plugin_query { $this->ensure_table($join->left_table, $relationship); } - // First, if this is our link point/anchor table, just use the relationship + // First, if this is our link point/anchor table, just use the + // relationship. if ($join->left_table == $this->relationships[$relationship]['table']) { $join->left_table = $relationship; } @@ -716,15 +738,15 @@ class views_plugin_query_default extends views_plugin_query { /** * Retrieve join data from the larger join data cache. * - * @param $table + * @param string $table * The table to get the join information for. - * @param $base_table + * @param string $base_table * The path we're following to get this join. * * @return views_join * A views_join object or child object, if one exists. */ - function get_join_data($table, $base_table) { + public function get_join_data($table, $base_table) { // Check to see if we're linking to a known alias. If so, get the real // table's data instead. if (!empty($this->table_queue[$table])) { @@ -739,7 +761,7 @@ class views_plugin_query_default extends views_plugin_query { * If you need the alias of a table with a particular relationship, use * ensure_table(). */ - function get_table_info($table) { + public function get_table_info($table) { if (!empty($this->table_queue[$table])) { return $this->table_queue[$table]; } @@ -755,27 +777,26 @@ class views_plugin_query_default extends views_plugin_query { /** * Add a field to the query table, possibly with an alias. This will - * automatically call ensure_table to make sure the required table - * exists, *unless* $table is unset. + * automatically call ensure_table to make sure the required table exists, + * *unless* $table is unset. * - * @param $table - * The table this field is attached to. If NULL, it is assumed this will - * be a formula; otherwise, ensure_table is used to make sure the - * table exists. - * @param $field + * @param string $table + * The table this field is attached to. If NULL, it is assumed this will be + * a formula; otherwise, ensure_table is used to make sure the table exists. + * @param string $field * The name of the field to add. This may be a real field or a formula. - * @param $alias + * @param string $alias * The alias to create. If not specified, the alias will be $table_$field * unless $table is NULL. When adding formulae, it is recommended that an * alias be used. - * @param $params + * @param array $params * An array of parameters additional to the field that will control items * such as aggregation functions and DISTINCT. * - * @return $name - * The name that this field can be referred to as. Usually this is the alias. + * @return string + * The name that this field can be referred to as, usually the alias. */ - function add_field($table, $field, $alias = '', $params = array()) { + public function add_field($table, $field, $alias = '', $params = array()) { // We check for this specifically because it gets a special alias. if ($table == $this->base_table && $field == $this->base_field && empty($alias)) { $alias = $this->base_field; @@ -789,13 +810,13 @@ class views_plugin_query_default extends views_plugin_query { $alias = $table . '_' . $field; } - // Make sure an alias is assigned + // Make sure an alias is assigned. $alias = $alias ? $alias : $field; - // PostgreSQL truncates aliases to 63 characters: http://drupal.org/node/571548 - + // PostgreSQL truncates aliases to 63 characters. + // @see http://drupal.org/node/571548 // We limit the length of the original alias up to 60 characters - // to get a unique alias later if its have duplicates + // to get a unique alias later if its have duplicates. $alias = strtolower(substr($alias, 0, 60)); // Create a field info array. @@ -805,9 +826,9 @@ class views_plugin_query_default extends views_plugin_query { 'alias' => $alias, ) + $params; - // Test to see if the field is actually the same or not. Due to - // differing parameters changing the aggregation function, we need - // to do some automatic alias collision detection: + // Test to see if the field is actually the same or not. Due to differing + // parameters changing the aggregation function, we need to do some + // automatic alias collision detection. $base = $alias; $counter = 0; while (!empty($this->fields[$alias]) && $this->fields[$alias] != $field_info) { @@ -825,35 +846,40 @@ class views_plugin_query_default extends views_plugin_query { } /** - * Remove all fields that may've been added; primarily used for summary - * mode where we're changing the query because we didn't get data we needed. + * Remove all fields that may've been added. + * + * Primarily used for summary mode where we're changing the query because we + * didn't get data we needed. */ - function clear_fields() { + public function clear_fields() { $this->fields = array(); } /** - * Add a simple WHERE clause to the query. The caller is responsible for - * ensuring that all fields are fully qualified (TABLE.FIELD) and that - * the table already exists in the query. + * Add a simple WHERE clause to the query. * - * @param $group + * The caller is responsible for ensuring that all fields are fully qualified + * (TABLE.FIELD) and that the table already exists in the query. + * + * @param string $group * The WHERE group to add these to; groups are used to create AND/OR - * sections. Groups cannot be nested. Use 0 as the default group. - * If the group does not yet exist it will be created as an AND group. - * @param $field + * sections. Groups cannot be nested. Use 0 as the default group. If the + * group does not yet exist it will be created as an AND group. + * @param string $field * The name of the field to check. - * @param $value - * The value to test the field against. In most cases, this is a scalar. For more - * complex options, it is an array. The meaning of each element in the array is - * dependent on the $operator. - * @param $operator - * The comparison operator, such as =, <, or >=. It also accepts more complex - * options such as IN, LIKE, or BETWEEN. Defaults to IN if $value is an array - * = otherwise. If $field is a string you have to use 'formula' here. + * @param string $value + * The value to test the field against. In most cases, this is a scalar. For + * more complex options, it is an array. The meaning of each element in the + * array is dependent on the $operator. + * @param string $operator + * The comparison operator, such as =, <, or >=. It also accepts more + * complex options such as IN, LIKE, or BETWEEN. Defaults to IN if $value is + * an array = otherwise. If $field is a string you have to use 'formula' + * here. * * The $field, $value and $operator arguments can also be passed in with a * single DatabaseCondition object, like this: + * * @code * $this->query->add_where( * $this->options['group'], @@ -866,9 +892,9 @@ class views_plugin_query_default extends views_plugin_query { * @see QueryConditionInterface::condition() * @see DatabaseCondition */ - function add_where($group, $field, $value = NULL, $operator = NULL) { - // Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all - // the default group. + public function add_where($group, $field, $value = NULL, $operator = NULL) { + // Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all the + // default group. if (empty($group)) { $group = 0; } @@ -889,22 +915,22 @@ class views_plugin_query_default extends views_plugin_query { * Add a complex WHERE clause to the query. * * The caller is responsible for ensuring that all fields are fully qualified - * (TABLE.FIELD) and that the table already exists in the query. - * Internally the dbtng method "where" is used. + * (TABLE.FIELD) and that the table already exists in the query. Internally + * the dbtng method "where" is used. * - * @param $group + * @param string $group * The WHERE group to add these to; groups are used to create AND/OR - * sections. Groups cannot be nested. Use 0 as the default group. - * If the group does not yet exist it will be created as an AND group. - * @param $snippet - * The snippet to check. This can be either a column or - * a complex expression like "UPPER(table.field) = 'value'" - * @param $args + * sections. Groups cannot be nested. Use 0 as the default group. If the + * group does not yet exist it will be created as an AND group. + * @param string $snippet + * The snippet to check. This can be either a column or a complex expression + * like "UPPER(table.field) = 'value'". + * @param array $args * An associative array of arguments. * * @see QueryConditionInterface::where() */ - function add_where_expression($group, $snippet, $args = array()) { + public function add_where_expression($group, $snippet, $args = array()) { // Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all // the default group. if (empty($group)) { @@ -927,29 +953,30 @@ class views_plugin_query_default extends views_plugin_query { * Add a simple HAVING clause to the query. * * The caller is responsible for ensuring that all fields are fully qualified - * (TABLE.FIELD) and that the table and an appropriate GROUP BY already exist in the query. - * Internally the dbtng method "havingCondition" is used. + * (TABLE.FIELD) and that the table and an appropriate GROUP BY already exist + * in the query. Internally the dbtng method "havingCondition" is used. * - * @param $group + * @param string $group * The HAVING group to add these to; groups are used to create AND/OR - * sections. Groups cannot be nested. Use 0 as the default group. - * If the group does not yet exist it will be created as an AND group. - * @param $field + * sections. Groups cannot be nested. Use 0 as the default group. If the + * group does not yet exist it will be created as an AND group. + * @param string $field * The name of the field to check. - * @param $value - * The value to test the field against. In most cases, this is a scalar. For more - * complex options, it is an array. The meaning of each element in the array is - * dependent on the $operator. - * @param $operator - * The comparison operator, such as =, <, or >=. It also accepts more complex - * options such as IN, LIKE, or BETWEEN. Defaults to IN if $value is an array - * = otherwise. If $field is a string you have to use 'formula' here. + * @param string $value + * The value to test the field against. In most cases, this is a scalar. For + * more complex options, it is an array. The meaning of each element in the + * array is dependent on the $operator. + * @param string $operator + * The comparison operator, such as =, <, or >=. It also accepts more + * complex options such as IN, LIKE, or BETWEEN. Defaults to IN if $value is + * an array = otherwise. If $field is a string you have to use 'formula' + * here. * * @see SelectQueryInterface::havingCondition() */ - function add_having($group, $field, $value = NULL, $operator = NULL) { - // Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all - // the default group. + public function add_having($group, $field, $value = NULL, $operator = NULL) { + // Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all the + // default group. if (empty($group)) { $group = 0; } @@ -969,23 +996,24 @@ class views_plugin_query_default extends views_plugin_query { /** * Add a complex HAVING clause to the query. - * The caller is responsible for ensuring that all fields are fully qualified - * (TABLE.FIELD) and that the table and an appropriate GROUP BY already exist in the query. - * Internally the dbtng method "having" is used. * - * @param $group + * The caller is responsible for ensuring that all fields are fully qualified + * (TABLE.FIELD) and that the table and an appropriate GROUP BY already exist + * in the query. Internally the dbtng method "having" is used. + * + * @param string $group * The HAVING group to add these to; groups are used to create AND/OR - * sections. Groups cannot be nested. Use 0 as the default group. - * If the group does not yet exist it will be created as an AND group. - * @param $snippet - * The snippet to check. This can be either a column or - * a complex expression like "COUNT(table.field) > 3" - * @param $args + * sections. Groups cannot be nested. Use 0 as the default group. If the + * group does not yet exist it will be created as an AND group. + * @param string $snippet + * The snippet to check. This can be either a column or a complex + * expression like "COUNT(table.field) > 3" + * @param array $args * An associative array of arguments. * * @see QueryConditionInterface::having() */ - function add_having_expression($group, $snippet, $args = array()) { + public function add_having_expression($group, $snippet, $args = array()) { // Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all // the default group. if (empty($group)) { @@ -1008,31 +1036,32 @@ class views_plugin_query_default extends views_plugin_query { /** * Add an ORDER BY clause to the query. * - * @param $table - * The table this field is part of. If a formula, enter NULL. - * If you want to orderby random use "rand" as table and nothing else. - * @param $field - * The field or formula to sort on. If already a field, enter NULL - * and put in the alias. - * @param $order + * @param string $table + * The table this field is part of. If a formula, enter NULL. If you want to + * orderby random use "rand" as table and nothing else. + * @param string $field + * The field or formula to sort on. If already a field, enter NULL and put + * in the alias. + * @param string $order * Either ASC or DESC. - * @param $alias - * The alias to add the field as. In SQL, all fields in the order by - * must also be in the SELECT portion. If an $alias isn't specified - * one will be generated for from the $field; however, if the - * $field is a formula, this alias will likely fail. - * @param $params + * @param string $alias + * The alias to add the field as. In SQL, all fields in the order by must + * also be in the SELECT portion. If an $alias isn't specified one will be + * generated for from the $field; however, if the $field is a formula, this + * alias will likely fail. + * @param string $params * Any params that should be passed through to the add_field. */ - function add_orderby($table, $field = NULL, $order = 'ASC', $alias = '', $params = array()) { + public function add_orderby($table, $field = NULL, $order = 'ASC', $alias = '', $params = array()) { // Only ensure the table if it's not the special random key. - // @todo: Maybe it would make sense to just add a add_orderby_rand or something similar. + // @todo Maybe it would make sense to just add a add_orderby_rand or + // something similar. if ($table && $table != 'rand') { $this->ensure_table($table); } - // Only fill out this aliasing if there is a table; - // otherwise we assume it is a formula. + // Only fill out this aliasing if there is a table; otherwise we assume it + // is a formula. if (!$alias && $table) { $as = $table . '_' . $field; } @@ -1046,27 +1075,17 @@ class views_plugin_query_default extends views_plugin_query { $this->orderby[] = array( 'field' => $as, - 'direction' => strtoupper($order) + 'direction' => strtoupper($order), ); - - /** - * -- removing, this should be taken care of by field adding now. - * -- leaving commented because I am unsure. - // If grouping, all items in the order by must also be in the - // group by clause. Check $table to ensure that this is not a - // formula. - if ($this->groupby && $table) { - $this->add_groupby($as); - } - */ } /** - * Add a simple GROUP BY clause to the query. The caller is responsible - * for ensuring that the fields are fully qualified and the table is properly - * added. + * Add a simple GROUP BY clause to the query. + * + * The caller is responsible for ensuring that the fields are fully qualified + * and the table is properly added. */ - function add_groupby($clause) { + public function add_groupby($clause) { // Only add it if it's not already in there. if (!in_array($clause, $this->groupby)) { $this->groupby[] = $clause; @@ -1078,7 +1097,7 @@ class views_plugin_query_default extends views_plugin_query { * * @see views_plugin_query_default::add_field() */ - function get_field_alias($table_alias, $field) { + public function get_field_alias($table_alias, $field) { return isset($this->field_aliases[$table_alias][$field]) ? $this->field_aliases[$table_alias][$field] : FALSE; } @@ -1087,14 +1106,14 @@ class views_plugin_query_default extends views_plugin_query { * * @see SelectQuery::addTag() */ - function add_tag($tag) { + public function add_tag($tag) { $this->tags[] = $tag; } /** * Generates a unique placeholder used in the db query. */ - function placeholder($base = 'views') { + public function placeholder($base = 'views') { static $placeholders = array(); if (!isset($placeholders[$base])) { $placeholders[$base] = 0; @@ -1113,10 +1132,10 @@ class views_plugin_query_default extends views_plugin_query { * There is other code in filters which makes sure that the group IDs are * higher than zero. * - * @param $where - * 'where' or 'having'. + * @param string $where + * Either 'where' or 'having'. */ - function build_condition($where = 'where') { + public function build_condition($where = 'where') { $has_condition = FALSE; $has_arguments = FALSE; $has_filter = FALSE; @@ -1130,8 +1149,9 @@ class views_plugin_query_default extends views_plugin_query { $sub_group = $info['type'] == 'OR' ? db_or() : db_and(); foreach ($info['conditions'] as $key => $clause) { // DBTNG doesn't support to add the same subquery twice to the main - // query and the count query, so clone the subquery to have two instances - // of the same object. - http://drupal.org/node/1112854 + // query and the count query, so clone the subquery to have two + // instances of the same object. + // @see http://drupal.org/node/1112854 if (is_object($clause['value']) && $clause['value'] instanceof SelectQuery) { $clause['value'] = clone $clause['value']; } @@ -1172,7 +1192,7 @@ class views_plugin_query_default extends views_plugin_query { /** * Build fields array. */ - function compile_fields($fields_array, $query) { + public function compile_fields($fields_array, $query) { $non_aggregates = array(); foreach ($fields_array as $field) { $string = ''; @@ -1187,7 +1207,7 @@ class views_plugin_query_default extends views_plugin_query { } if (!empty($field['count'])) { - // Retained for compatibility + // Retained for compatibility. $field['function'] = 'count'; // It seems there's no way to abstract the table+column reference // without adding a field, aliasing, and then using the alias. @@ -1205,7 +1225,12 @@ class views_plugin_query_default extends views_plugin_query { } // This is a formula, using no tables. elseif (empty($field['table'])) { - $non_aggregates[] = $fieldname; + if (Database::getConnection()->databaseType() != 'pgsql') { + $non_aggregates[] = $fieldname; + } + elseif (!in_array($fieldname, $non_aggregates)) { + $non_aggregates[] = $fieldname; + } $placeholders = !empty($field['placeholders']) ? $field['placeholders'] : array(); $query->addExpression($string, $fieldname, $placeholders); } @@ -1213,14 +1238,22 @@ class views_plugin_query_default extends views_plugin_query { elseif ($this->distinct && !in_array($fieldname, $this->groupby)) { // d7cx: This code was there, apparently needed for PostgreSQL // $string = db_driver() == 'pgsql' ? "FIRST($string)" : $string; + if (Database::getConnection()->databaseType() == 'pgsql' && !in_array($string, $non_aggregates)) { + $non_aggregates[] = $string; + } $query->addField(!empty($field['table']) ? $field['table'] : $this->base_table, $field['field'], $fieldname); } elseif (empty($field['aggregate'])) { - $non_aggregates[] = $fieldname; + if (Database::getConnection()->databaseType() != 'pgsql') { + $non_aggregates[] = $fieldname; + } + elseif (!in_array($string, $non_aggregates)) { + $non_aggregates[] = $string; + } $query->addField(!empty($field['table']) ? $field['table'] : $this->base_table, $field['field'], $fieldname); } - // @TODO Remove this old code. + // @todo Remove this old code. if (!empty($field['distinct']) && empty($field['function'])) { $distinct[] = $string; } @@ -1242,26 +1275,25 @@ class views_plugin_query_default extends views_plugin_query { * Generate a query and a countquery from all of the information supplied * to the object. * - * @param $get_count + * @param bool $get_count * Provide a countquery if this is true, otherwise provide a normal query. * * @return SelectQuery * A SelectQuery object. */ - function query($get_count = FALSE) { + public function query($get_count = FALSE) { // Check query distinct value. if (empty($this->no_distinct) && $this->distinct && !empty($this->fields)) { - if ($this->pure_distinct === FALSE){ + if ($this->pure_distinct === FALSE) { $base_field_alias = $this->add_field($this->base_table, $this->base_field); $this->add_groupby($base_field_alias); } $distinct = TRUE; } - /** - * An optimized count query includes just the base field instead of all the fields. - * Determine of this query qualifies by checking for a groupby or distinct. - */ + // An optimized count query includes just the base field instead of all the + // fields. Determine of this query qualifies by checking for a groupby or + // distinct. $fields_array = $this->fields; if ($get_count && !$this->groupby) { foreach ($fields_array as $field) { @@ -1281,18 +1313,18 @@ class views_plugin_query_default extends views_plugin_query { $options = array(); $target = 'default'; $key = 'default'; - // Detect an external database and set the + // Detect an external database and set the. if (isset($this->view->base_database)) { $key = $this->view->base_database; } - // Set the slave target if the slave option is set + // Set the slave target if the slave option is set. if (!empty($this->options['slave'])) { $target = 'slave'; } - // Go ahead and build the query. - // db_select doesn't support to specify the key, so use getConnection directly. + // Go ahead and build the query. db_select doesn't support to specify the + // key, so use getConnection directly. $query = Database::getConnection($target, $key) ->select($this->base_table, $this->base_table, $options) ->addTag('views') @@ -1325,8 +1357,9 @@ class views_plugin_query_default extends views_plugin_query { if (count($this->having)) { $this->has_aggregate = TRUE; } - elseif (!$this->has_aggregate) { - // Allow 'GROUP BY' even no aggregation function has been set. + // Allow 'GROUP BY' even if no aggregation function has been set, but only + // when there is a legitimate display_handler. + elseif (!$this->has_aggregate && !empty($this->view->display_handler)) { $this->has_aggregate = $this->view->display_handler->get_option('group_by'); } if ($this->has_aggregate && (!empty($this->groupby) || !empty($non_aggregates))) { @@ -1340,7 +1373,7 @@ class views_plugin_query_default extends views_plugin_query { } if (!$this->get_count_optimized) { - // we only add the orderby if we're not counting. + // We only add the orderby if we're not counting. if ($this->orderby) { foreach ($this->orderby as $order) { if ($order['field'] == 'rand_') { @@ -1374,8 +1407,8 @@ class views_plugin_query_default extends views_plugin_query { if (!$get_count) { if (!empty($this->limit) || !empty($this->offset)) { - // We can't have an offset without a limit, so provide a very large limit - // instead. + // We can't have an offset without a limit, so provide a very large + // limit instead. $limit = intval(!empty($this->limit) ? $this->limit : 999999); $offset = intval(!empty($this->offset) ? $this->offset : 0); $query->range($offset, $limit); @@ -1388,7 +1421,7 @@ class views_plugin_query_default extends views_plugin_query { /** * Get the arguments attached to the WHERE and HAVING clauses of this query. */ - function get_where_args() { + public function get_where_args() { $args = array(); foreach ($this->where as $group => $where) { $args = array_merge($args, $where['args']); @@ -1402,7 +1435,7 @@ class views_plugin_query_default extends views_plugin_query { /** * Let modules modify the query just prior to finalizing it. */ - function alter(&$view) { + public function alter(&$view) { foreach (module_implements('views_query_alter') as $module) { $function = $module . '_views_query_alter'; $function($view, $this); @@ -1412,7 +1445,7 @@ class views_plugin_query_default extends views_plugin_query { /** * Builds the necessary info to execute the query. */ - function build(&$view) { + public function build(&$view) { // Make the query distinct if the option was set. if (!empty($this->options['distinct'])) { $this->set_distinct(TRUE, !empty($this->options['pure_distinct'])); @@ -1437,8 +1470,9 @@ class views_plugin_query_default extends views_plugin_query { * Values to set: $view->result, $view->total_rows, $view->execute_time, * $view->current_page. */ - function execute(&$view) { - $external = FALSE; // Whether this query will run against an external database. + public function execute(&$view) { + // Whether this query will run against an external database. + $external = FALSE; $query = $view->build_info['query']; $count_query = $view->build_info['count_query']; @@ -1462,9 +1496,9 @@ class views_plugin_query_default extends views_plugin_query { // If not, then hook_query_node_access_alter() may munge the count by // adding a distinct against an empty query string // (e.g. COUNT DISTINCT(1) ...) and no pager will return. - // See pager.inc > PagerDefault::execute() - // http://api.drupal.org/api/drupal/includes--pager.inc/function/PagerDefault::execute/7 - // See http://drupal.org/node/1046170. + // @see pager.inc > PagerDefault::execute() + // @see http://api.drupal.org/api/drupal/includes--pager.inc/function/PagerDefault::execute/7 + // @see http://drupal.org/node/1046170. $count_query->preExecute(); // Build the count query. @@ -1480,7 +1514,6 @@ class views_plugin_query_default extends views_plugin_query { $start = microtime(TRUE); - try { if ($this->pager->use_count_query() || !empty($view->get_total_rows)) { $this->pager->execute_count_query($count_query); @@ -1518,12 +1551,18 @@ class views_plugin_query_default extends views_plugin_query { $view->execute_time = microtime(TRUE) - $start; } - function add_signature(&$view) { + /** + * + */ + public function add_signature(&$view) { $view->query->add_field(NULL, "'" . $view->name . ':' . $view->current_display . "'", 'view_name'); } - function get_aggregation_info() { - // @todo -- need a way to get database specific and customized aggregation + /** + * + */ + public function get_aggregation_info() { + // @todo Need a way to get database specific and customized aggregation // functions into here. return array( 'group' => array( @@ -1594,15 +1633,14 @@ class views_plugin_query_default extends views_plugin_query { 'filter' => 'views_handler_filter_group_by_numeric', 'sort' => 'views_handler_sort_group_by_numeric', ), - ) + ), ) + views_fetch_plugin_data('query_aggregate'); } /** * Returns the according entity objects for the given query results. - * */ - function get_result_entities($results, $relationship = NULL) { + public function get_result_entities($results, $relationship = NULL) { $base_table = $this->base_table; $base_table_alias = $base_table; @@ -1664,12 +1702,19 @@ class views_plugin_query_default extends views_plugin_query { return array($entity_type, $result); } + } +/** + * + */ function views_query_default_aggregation_method_simple($group_type, $field) { return strtoupper($group_type) . '(' . $field . ')'; } +/** + * + */ function views_query_default_aggregation_method_distinct($group_type, $field) { $group_type = str_replace('_distinct', '', $group_type); return strtoupper($group_type) . '(DISTINCT ' . $field . ')'; diff --git a/sites/all/modules/views/plugins/views_plugin_row.inc b/sites/all/modules/views/plugins/views_plugin_row.inc index 157cc26..833a675 100644 --- a/sites/all/modules/views/plugins/views_plugin_row.inc +++ b/sites/all/modules/views/plugins/views_plugin_row.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the base row style plugin. + * Definition of views_plugin_row. */ /** @@ -17,14 +17,15 @@ */ /** - * Default plugin to view a single row of a table. This is really just a wrapper around - * a theme function. + * Default plugin to view a single row of a table. This is really just a wrapper + * around a theme function. */ class views_plugin_row extends views_plugin { + /** - * Initialize the row plugin. + * {@inheritdoc} */ - function init(&$view, &$display, $options = NULL) { + public function init(&$view, &$display, $options = NULL) { $this->view = &$view; $this->display = &$display; @@ -32,12 +33,17 @@ class views_plugin_row extends views_plugin { $this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('row_options')); } - function uses_fields() { + /** + * {@inheritdoc} + */ + public function uses_fields() { return !empty($this->definition['uses fields']); } - - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); if (isset($this->base_table)) { $options['relationship'] = array('default' => 'none'); @@ -49,7 +55,7 @@ class views_plugin_row extends views_plugin { /** * Provide a form for setting options. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); if (isset($this->base_table)) { $view = &$form_state['view']; @@ -98,15 +104,20 @@ class views_plugin_row extends views_plugin { /** * Validate the options form. */ - function options_validate(&$form, &$form_state) { } + public function options_validate(&$form, &$form_state) { + } /** * Perform any necessary changes to the form values prior to storage. * There is no need for this function to actually store the data. */ - function options_submit(&$form, &$form_state) { } + public function options_submit(&$form, &$form_state) { + } - function query() { + /** + * {@inheritdoc} + */ + public function query() { if (isset($this->base_table)) { if (isset($this->options['relationship']) && isset($this->view->relationship[$this->options['relationship']])) { $relationship = $this->view->relationship[$this->options['relationship']]; @@ -121,10 +132,11 @@ class views_plugin_row extends views_plugin { /** * Allow the style to do stuff before each row is rendered. * - * @param $result + * @param array $result * The full array of results from the query. */ - function pre_render($result) { } + public function pre_render($result) { + } /** * Render a row object. This usually passes through to a theme template @@ -136,7 +148,7 @@ class views_plugin_row extends views_plugin { * @return string * The rendered output of a single row, used by the style plugin. */ - function render($row) { + public function render($row) { return theme($this->theme_functions(), array( 'view' => $this->view, @@ -145,6 +157,7 @@ class views_plugin_row extends views_plugin { 'field_alias' => isset($this->field_alias) ? $this->field_alias : '', )); } + } /** diff --git a/sites/all/modules/views/plugins/views_plugin_row_fields.inc b/sites/all/modules/views/plugins/views_plugin_row_fields.inc index b1c02e1..edc854c 100644 --- a/sites/all/modules/views/plugins/views_plugin_row_fields.inc +++ b/sites/all/modules/views/plugins/views_plugin_row_fields.inc @@ -2,11 +2,11 @@ /** * @file - * Contains the base row style plugin. + * Definition of views_plugin_row_fields. */ /** - * The basic 'fields' row plugin + * The basic 'fields' row plugin. * * This displays fields one after another, giving options for inline * or not. @@ -14,7 +14,11 @@ * @ingroup views_row_plugins */ class views_plugin_row_fields extends views_plugin_row { - function option_definition() { + + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['inline'] = array('default' => array()); @@ -27,7 +31,7 @@ class views_plugin_row_fields extends views_plugin_row { /** * Provide a form for setting options. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $options = $this->display->handler->get_field_labels(); @@ -80,7 +84,8 @@ class views_plugin_row_fields extends views_plugin_row { * Perform any necessary changes to the form values prior to storage. * There is no need for this function to actually store the data. */ - function options_submit(&$form, &$form_state) { + public function options_submit(&$form, &$form_state) { $form_state['values']['row_options']['inline'] = array_filter($form_state['values']['row_options']['inline']); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_row_rss_fields.inc b/sites/all/modules/views/plugins/views_plugin_row_rss_fields.inc index 9355e83..4af7c9f 100644 --- a/sites/all/modules/views/plugins/views_plugin_row_rss_fields.inc +++ b/sites/all/modules/views/plugins/views_plugin_row_rss_fields.inc @@ -1,14 +1,19 @@ ''); $options['link_field'] = array('default' => ''); @@ -20,7 +25,10 @@ class views_plugin_row_rss_fields extends views_plugin_row { return $options; } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $initial_labels = array('' => t('- None -')); @@ -89,7 +97,10 @@ class views_plugin_row_rss_fields extends views_plugin_row { ); } - function validate() { + /** + * + */ + public function validate() { $errors = parent::validate(); $required_options = array('title_field', 'link_field', 'description_field', 'creator_field', 'date_field'); foreach ($required_options as $required_option) { @@ -105,7 +116,10 @@ class views_plugin_row_rss_fields extends views_plugin_row { return $errors; } - function render($row) { + /** + * {@inheritdoc} + */ + public function render($row) { static $row_index; if (!isset($row_index)) { $row_index = 0; @@ -165,12 +179,12 @@ class views_plugin_row_rss_fields extends views_plugin_row { /** * Retrieves a views field value from the style plugin. * - * @param $index - * The index count of the row as expected by views_plugin_style::get_field(). - * @param $field_id + * @param int $index + * The index of the row as expected by views_plugin_style::get_field(). + * @param string $field_id * The ID assigned to the required field in the display. */ - function get_field($index, $field_id) { + public function get_field($index, $field_id) { if (empty($this->view->style_plugin) || !is_object($this->view->style_plugin) || empty($field_id)) { return ''; } diff --git a/sites/all/modules/views/plugins/views_plugin_style.inc b/sites/all/modules/views/plugins/views_plugin_style.inc index 5bd7086..1433f31 100644 --- a/sites/all/modules/views/plugins/views_plugin_style.inc +++ b/sites/all/modules/views/plugins/views_plugin_style.inc @@ -8,13 +8,13 @@ /** * @defgroup views_style_plugins Views style plugins * @{ - * Style plugins control how a view is rendered. For example, they - * can choose to display a collection of fields, node_view() output, - * table output, or any kind of crazy output they want. + * Style plugins control how a view is rendered. For example, they can choose to + * display a collection of fields, node_view() output, table output, or any kind + * of crazy output they want. * - * Many style plugins can have an optional 'row' plugin, that displays - * a single record. Not all style plugins can utilize this, so it is - * up to the plugin to set this up and call through to the row plugin. + * Many style plugins can have an optional 'row' plugin, that displays a single + * record. Not all style plugins can utilize this, so it is up to the plugin to + * set this up and call through to the row plugin. * * @see hook_views_plugins() */ @@ -23,29 +23,29 @@ * Base class to define a style plugin handler. */ class views_plugin_style extends views_plugin { + /** * Store all available tokens row rows. */ - var $row_tokens = array(); + public $row_tokens = array(); /** - * Contains the row plugin, if it's initialized - * and the style itself supports it. + * The row plugin, if it's initialized and the style itself supports it. * * @var views_plugin_row */ - var $row_plugin; + public $row_plugin; /** * Initialize a style plugin. * - * @param $view - * @param $display - * @param $options + * @param view $view + * @param object $display + * @param array $options * The style options might come externally as the style can be sourced * from at least two locations. If it's not included, look on the display. */ - function init(&$view, &$display, $options = NULL) { + public function init(&$view, &$display, $options = NULL) { $this->view = &$view; $this->display = &$display; @@ -65,7 +65,10 @@ class views_plugin_style extends views_plugin { ); } - function destroy() { + /** + * + */ + public function destroy() { parent::destroy(); if (isset($this->row_plugin)) { @@ -76,14 +79,14 @@ class views_plugin_style extends views_plugin { /** * Return TRUE if this style also uses a row plugin. */ - function uses_row_plugin() { + public function uses_row_plugin() { return !empty($this->definition['uses row plugin']); } /** * Return TRUE if this style also uses a row plugin. */ - function uses_row_class() { + public function uses_row_class() { return !empty($this->definition['uses row class']); } @@ -92,7 +95,7 @@ class views_plugin_style extends views_plugin { * * @return bool */ - function uses_fields() { + public function uses_fields() { // If we use a row plugin, ask the row plugin. Chances are, we don't // care, it does. $row_uses_fields = FALSE; @@ -108,7 +111,7 @@ class views_plugin_style extends views_plugin { * * Used to ensure we don't fetch tokens when not needed for performance. */ - function uses_tokens() { + public function uses_tokens() { if ($this->uses_row_class()) { $class = $this->options['row_class']; if (strpos($class, '[') !== FALSE || strpos($class, '!') !== FALSE || strpos($class, '%') !== FALSE) { @@ -120,7 +123,7 @@ class views_plugin_style extends views_plugin { /** * Return the token replaced row class for the specified row. */ - function get_row_class($row_index) { + public function get_row_class($row_index) { if ($this->uses_row_class()) { $class = $this->options['row_class']; @@ -129,7 +132,7 @@ class views_plugin_style extends views_plugin { // Explode the value by whitespace, this allows the function to handle // a single class name and multiple class names that are then tokenized. - foreach(explode(' ', $class) as $token_class) { + foreach (explode(' ', $class) as $token_class) { $classes = array_merge($classes, explode(' ', strip_tags($this->tokenize_value($token_class, $row_index)))); } } @@ -148,7 +151,7 @@ class views_plugin_style extends views_plugin { /** * Take a value and apply token replacement logic to it. */ - function tokenize_value($value, $row_index) { + public function tokenize_value($value, $row_index) { if (strpos($value, '[') !== FALSE || strpos($value, '!') !== FALSE || strpos($value, '%') !== FALSE) { $fake_item = array( 'alter_text' => TRUE, @@ -170,13 +173,16 @@ class views_plugin_style extends views_plugin { } /** - * Should the output of the style plugin be rendered even if it's a empty view. + * Should the output of the style plugin be rendered even if it's empty. */ - function even_empty() { + public function even_empty() { return !empty($this->definition['even empty']); } - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['grouping'] = array('default' => array()); if ($this->uses_row_class()) { @@ -189,19 +195,23 @@ class views_plugin_style extends views_plugin { return $options; } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); - // Only fields-based views can handle grouping. Style plugins can also exclude - // themselves from being groupable by setting their "use grouping" definition - // key to FALSE. - // @TODO: Document "uses grouping" in docs.php when docs.php is written. + // Only fields-based views can handle grouping. Style plugins can also + // exclude themselves from being groupable by setting their "use grouping" + // definition key to FALSE. + // @todo Document "uses grouping" in docs.php when docs.php is written. if ($this->uses_fields() && $this->definition['uses grouping']) { $options = array('' => t('- None -')); $field_labels = $this->display->handler->get_field_labels(TRUE); $options += $field_labels; // If there are no fields, we can't group on them. if (count($options) > 1) { - // This is for backward compatibility, when there was just a single select form. + // This is for backward compatibility, when there was just a single + // select form. if (is_string($this->options['grouping'])) { $grouping = $this->options['grouping']; $this->options['grouping'] = array(); @@ -282,7 +292,10 @@ class views_plugin_style extends views_plugin { } } - function options_validate(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_validate(&$form, &$form_state) { // Don't run validation on style plugins without the grouping setting. if (isset($form_state['values']['style_options']['grouping'])) { // Don't save grouping if no field is specified. @@ -299,21 +312,24 @@ class views_plugin_style extends views_plugin { * interfere with the sorts. If so it should build; if it returns * any non-TRUE value, normal sorting will NOT be added to the query. */ - function build_sort() { return TRUE; } + public function build_sort() { + return TRUE; + } /** * Called by the view builder to let the style build a second set of * sorts that will come after any other sorts in the view. */ - function build_sort_post() { } + public function build_sort_post() { + } /** * Allow the style to do stuff before each row is rendered. * - * @param $result + * @param array $result * The full array of results from the query. */ - function pre_render($result) { + public function pre_render($result) { if (!empty($this->row_plugin)) { $this->row_plugin->pre_render($result); } @@ -322,7 +338,7 @@ class views_plugin_style extends views_plugin { /** * Render the display in this style. */ - function render() { + public function render() { if ($this->uses_row_plugin() && empty($this->row_plugin)) { debug('views_plugin_style_default: Missing row plugin'); return; @@ -344,18 +360,19 @@ class views_plugin_style extends views_plugin { * Plugins may override this method if they wish some other way of handling * grouping. * - * @param $sets + * @param array $sets * Array containing the grouping sets to render. - * @param $level + * @param int $level * Integer indicating the hierarchical level of the grouping. * * @return string * Rendered output of given grouping sets. */ - function render_grouping_sets($sets, $level = 0) { + public function render_grouping_sets($sets, $level = 0) { $output = ''; foreach ($sets as $set) { $row = reset($set['rows']); + $level = isset($set['level']) ? $set['level'] : 0; // Render as a grouping set. if (is_array($row) && isset($row['group'])) { $output .= theme(views_theme_functions('views_view_grouping', $this->view, $this->display), @@ -393,18 +410,19 @@ class views_plugin_style extends views_plugin { /** * Group records as needed for rendering. * - * @param $records + * @param array $records * An array of records from the view to group. - * @param $groupings + * @param array $groupings * An array of grouping instructions on which fields to group. If empty, the * result set will be given a single group with an empty string as a label. - * @param $group_rendered + * @param bool $group_rendered * Boolean value whether to use the rendered or the raw field value for * grouping. If set to NULL the return is structured as before * Views 7.x-3.0-rc2. After Views 7.x-3.0 this boolean is only used if * $groupings is an old-style string or if the rendered option is missing * for a grouping instruction. - * @return + * + * @return array * The grouped record set. * A nested set structure is generated if multiple grouping fields are used. * @@ -429,9 +447,9 @@ class views_plugin_style extends views_plugin { * ) * @endcode */ - function render_grouping($records, $groupings = array(), $group_rendered = NULL) { - // This is for backward compatibility, when $groupings was a string containing - // the ID of a single field. + public function render_grouping($records, $groupings = array(), $group_rendered = NULL) { + // This is for backward compatibility, when $groupings was a string + // containing the ID of a single field. if (is_string($groupings)) { $rendered = $group_rendered === NULL ? TRUE : $group_rendered; $groupings = array(array('field' => $groupings, 'rendered' => $rendered)); @@ -446,7 +464,7 @@ class views_plugin_style extends views_plugin { // hierarchically positioned set where the current row belongs to. // While iterating, parent groups, that do not exist yet, are added. $set = &$sets; - foreach ($groupings as $info) { + foreach ($groupings as $level => $info) { $field = $info['field']; $rendered = isset($info['rendered']) ? $info['rendered'] : $group_rendered; $rendered_strip = isset($info['rendered_strip']) ? $info['rendered_strip'] : FALSE; @@ -479,13 +497,16 @@ class views_plugin_style extends views_plugin { // Create the group if it does not exist yet. if (empty($set[$grouping])) { $set[$grouping]['group'] = $group_content; + $set[$grouping]['level'] = $level; $set[$grouping]['rows'] = array(); } - // Move the set reference into the row set of the group we just determined. + // Move the set reference into the row set of the group we just + // determined. $set = &$set[$grouping]['rows']; } - // Add the row to the hierarchically positioned row set we just determined. + // Add the row to the hierarchically positioned row set we just + // determined. $set[$index] = $row; } } @@ -499,7 +520,7 @@ class views_plugin_style extends views_plugin { // If this parameter isn't explicitly set modify the output to be fully // backward compatible to code before Views 7.x-3.0-rc2. - // @TODO Remove this as soon as possible e.g. October 2020 + // @todo Remove this as soon as possible e.g. October 2020 if ($group_rendered === NULL) { $old_style_sets = array(); foreach ($sets as $group) { @@ -514,10 +535,10 @@ class views_plugin_style extends views_plugin { /** * Render all of the fields for a given style and store them on the object. * - * @param $result + * @param array $result * The result array from $view->result */ - function render_fields($result) { + public function render_fields($result) { if (!$this->uses_fields()) { return; } @@ -548,12 +569,12 @@ class views_plugin_style extends views_plugin { /** * Get a rendered field. * - * @param $index + * @param int $index * The index count of the row. - * @param $field + * @param string $field * The id of the field. */ - function get_field($index, $field) { + public function get_field($index, $field) { if (!isset($this->rendered_fields)) { $this->render_fields($this->view->result); } @@ -566,19 +587,22 @@ class views_plugin_style extends views_plugin { /** * Get the raw field value. * - * @param $index + * @param int $index * The index count of the row. - * @param $field + * @param string $field * The id of the field. */ - function get_field_value($index, $field) { + public function get_field_value($index, $field) { $this->view->row_index = $index; $value = $this->view->field[$field]->get_value($this->view->result[$index]); unset($this->view->row_index); return $value; } - function validate() { + /** + * {@inheritdoc} + */ + public function validate() { $errors = parent::validate(); if ($this->uses_row_plugin()) { @@ -596,12 +620,16 @@ class views_plugin_style extends views_plugin { return $errors; } - function query() { + /** + * {@inheritdoc} + */ + public function query() { parent::query(); if (isset($this->row_plugin)) { $this->row_plugin->query(); } } + } /** diff --git a/sites/all/modules/views/plugins/views_plugin_style_default.inc b/sites/all/modules/views/plugins/views_plugin_style_default.inc index a18f6cc..131b991 100644 --- a/sites/all/modules/views/plugins/views_plugin_style_default.inc +++ b/sites/all/modules/views/plugins/views_plugin_style_default.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the default style plugin. + * Definition of views_plugin_style_default. */ /** @@ -12,14 +12,19 @@ * @ingroup views_style_plugins */ class views_plugin_style_default extends views_plugin_style { + /** - * Set default options + * Set default options. */ - function options(&$options) { + public function options(&$options) { parent::options($options); } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_style_grid.inc b/sites/all/modules/views/plugins/views_plugin_style_grid.inc index a2e4375..ffa4cf0 100644 --- a/sites/all/modules/views/plugins/views_plugin_style_grid.inc +++ b/sites/all/modules/views/plugins/views_plugin_style_grid.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the grid style plugin. + * Definition of views_plugin_style_grid. */ /** @@ -11,10 +11,11 @@ * @ingroup views_style_plugins */ class views_plugin_style_grid extends views_plugin_style { + /** - * Set default options + * Set default options. */ - function option_definition() { + public function option_definition() { $options = parent::option_definition(); $options['columns'] = array('default' => '4'); @@ -29,7 +30,7 @@ class views_plugin_style_grid extends views_plugin_style { /** * Render the given style. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['columns'] = array( '#type' => 'textfield', @@ -67,4 +68,5 @@ class views_plugin_style_grid extends views_plugin_style { '#default_value' => $this->options['summary'], ); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_style_jump_menu.inc b/sites/all/modules/views/plugins/views_plugin_style_jump_menu.inc index b82facd..418766b 100644 --- a/sites/all/modules/views/plugins/views_plugin_style_jump_menu.inc +++ b/sites/all/modules/views/plugins/views_plugin_style_jump_menu.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the table style plugin. + * Definition of views_plugin_style_jump_menu. */ /** @@ -11,7 +11,11 @@ * @ingroup views_style_plugins */ class views_plugin_style_jump_menu extends views_plugin_style { - function option_definition() { + + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['hide'] = array('default' => FALSE, 'bool' => TRUE); @@ -28,7 +32,7 @@ class views_plugin_style_jump_menu extends views_plugin_style { /** * Render the given style. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $handlers = $this->display->handler->get_handlers('field'); if (empty($handlers)) { @@ -61,7 +65,7 @@ class views_plugin_style_jump_menu extends views_plugin_style { '#type' => 'checkbox', '#title' => t('Hide the "Go" button'), '#default_value' => !empty($this->options['hide']), - '#description' => t('If hidden, this button will only be hidden for users with javascript and the page will automatically jump when the select is changed.'), + '#description' => t('If hidden, this button will only be hidden for users with JavaScript and the page will automatically jump when the select is changed.'), ); $form['text'] = array( @@ -103,7 +107,7 @@ class views_plugin_style_jump_menu extends views_plugin_style { * * This is overridden so that we can render our grouping specially. */ - function render() { + public function render() { $sets = $this->render_grouping($this->view->result, $this->options['grouping']); // Turn this all into an $options array for the jump menu. @@ -122,8 +126,8 @@ class views_plugin_style_jump_menu extends views_plugin_style { $path = drupal_substr($path, drupal_strlen($base_path)); } - // use drupal_parse_url() to preserve query and fragment in case the user - // wants to do fun tricks. + // Use drupal_parse_url() to preserve query and fragment in case the + // user wants to do fun tricks. $url_options = drupal_parse_url($path); $path = url($url_options['path'], $url_options); @@ -144,8 +148,8 @@ class views_plugin_style_jump_menu extends views_plugin_style { $default_value = ''; if ($this->options['default_value']) { $lookup_options = array(); - // We need to check if the path is absolute - // or else language is not taken in account. + // We need to check if the path is absolute or else language is not taken + // in account. if (!empty($this->view->display[$this->view->current_display]->display_options['fields'][$this->options['path']]['absolute'])) { $lookup_options['absolute'] = TRUE; } @@ -169,8 +173,12 @@ class views_plugin_style_jump_menu extends views_plugin_style { return $form; } - function render_set($title, $records) { + /** + * + */ + public function render_set($title, $records) { $options = array(); $fields = $this->rendered_fields; } + } diff --git a/sites/all/modules/views/plugins/views_plugin_style_list.inc b/sites/all/modules/views/plugins/views_plugin_style_list.inc index 2a1dadb..7c8417f 100644 --- a/sites/all/modules/views/plugins/views_plugin_style_list.inc +++ b/sites/all/modules/views/plugins/views_plugin_style_list.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the list style plugin. + * Definition of views_plugin_style_list. */ /** @@ -11,10 +11,11 @@ * @ingroup views_style_plugins */ class views_plugin_style_list extends views_plugin_style { + /** - * Set default options + * Set default options. */ - function option_definition() { + public function option_definition() { $options = parent::option_definition(); $options['type'] = array('default' => 'ul'); @@ -27,7 +28,7 @@ class views_plugin_style_list extends views_plugin_style { /** * Render the given style. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['type'] = array( '#type' => 'radios', @@ -50,4 +51,5 @@ class views_plugin_style_list extends views_plugin_style { '#default_value' => $this->options['class'], ); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_style_mapping.inc b/sites/all/modules/views/plugins/views_plugin_style_mapping.inc index 513a71e..29ecebc 100644 --- a/sites/all/modules/views/plugins/views_plugin_style_mapping.inc +++ b/sites/all/modules/views/plugins/views_plugin_style_mapping.inc @@ -27,9 +27,9 @@ abstract class views_plugin_style_mapping extends views_plugin_style { abstract protected function define_mapping(); /** - * Overrides views_plugin_style::option_definition(). + * {@inheritdoc} */ - function option_definition() { + public function option_definition() { $options = parent::option_definition(); // Parse the mapping and add a default for each. @@ -50,9 +50,9 @@ abstract class views_plugin_style_mapping extends views_plugin_style { } /** - * Overrides views_plugin_style::options_form(). + * {@inheritdoc} */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); // Get the mapping. @@ -110,11 +110,10 @@ abstract class views_plugin_style_mapping extends views_plugin_style { } /** - * Overrides views_plugin_style::render(). - * - * Provides the mapping definition as an available variable. + * {@inheritdoc} */ - function render() { + public function render() { + // Provides the mapping definition as an available variable. return theme($this->theme_functions(), array( 'view' => $this->view, 'options' => $this->options, diff --git a/sites/all/modules/views/plugins/views_plugin_style_rss.inc b/sites/all/modules/views/plugins/views_plugin_style_rss.inc index 79fef3d..0092ea4 100644 --- a/sites/all/modules/views/plugins/views_plugin_style_rss.inc +++ b/sites/all/modules/views/plugins/views_plugin_style_rss.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the RSS style plugin. + * Definition of views_plugin_style_rss. */ /** @@ -11,7 +11,11 @@ * @ingroup views_style_plugins */ class views_plugin_style_rss extends views_plugin_style { - function attach_to($display_id, $path, $title) { + + /** + * + */ + public function attach_to($display_id, $path, $title) { $display = $this->view->display[$display_id]->handler; $url_options = array(); $input = $this->view->get_exposed_input(); @@ -36,12 +40,15 @@ class views_plugin_style_rss extends views_plugin_style { 'rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => $title, - 'href' => $url + 'href' => $url, )); } } - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['description'] = array('default' => '', 'translatable' => TRUE); @@ -49,7 +56,10 @@ class views_plugin_style_rss extends views_plugin_style { return $options; } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['description'] = array( @@ -67,7 +77,7 @@ class views_plugin_style_rss extends views_plugin_style { * @return * An array that can be passed to format_xml_elements(). */ - function get_channel_elements() { + public function get_channel_elements() { return array(); } @@ -80,7 +90,7 @@ class views_plugin_style_rss extends views_plugin_style { * @return * An array that can be passed to format_xml_elements(). */ - function get_channel_elements_atom_link() { + public function get_channel_elements_atom_link() { $url_options = array('absolute' => TRUE); $input = $this->view->get_exposed_input(); if ($input) { @@ -107,7 +117,7 @@ class views_plugin_style_rss extends views_plugin_style { * @return string * The string containing the description with the tokens replaced. */ - function get_description() { + public function get_description() { $description = $this->options['description']; // Allow substitutions from the first row. @@ -116,7 +126,10 @@ class views_plugin_style_rss extends views_plugin_style { return $description; } - function render() { + /** + * {@inheritdoc} + */ + public function render() { if (empty($this->row_plugin)) { vpr('views_plugin_style_default: Missing row plugin'); return; @@ -148,9 +161,10 @@ class views_plugin_style_rss extends views_plugin_style { array( 'view' => $this->view, 'options' => $this->options, - 'rows' => $rows + 'rows' => $rows, )); unset($this->view->row_index); return $output; } + } diff --git a/sites/all/modules/views/plugins/views_plugin_style_summary.inc b/sites/all/modules/views/plugins/views_plugin_style_summary.inc index 5081dd6..02e8973 100644 --- a/sites/all/modules/views/plugins/views_plugin_style_summary.inc +++ b/sites/all/modules/views/plugins/views_plugin_style_summary.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the default summary style plugin, which displays items in an HTML list. + * Definition of views_plugin_style_summary. */ /** @@ -11,7 +11,11 @@ * @ingroup views_style_plugins */ class views_plugin_style_summary extends views_plugin_style { - function option_definition() { + + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['base_path'] = array('default' => ''); @@ -22,13 +26,19 @@ class views_plugin_style_summary extends views_plugin_style { return $options; } - function query() { + /** + * {@inheritdoc} + */ + public function query() { if (!empty($this->options['override'])) { $this->view->set_items_per_page(intval($this->options['items_per_page'])); } } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { $form['base_path'] = array( '#type' => 'textfield', '#title' => t('Base path'), @@ -55,22 +65,26 @@ class views_plugin_style_summary extends views_plugin_style { '#title' => t('Items to display'), '#default_value' => $this->options['items_per_page'], '#dependency' => array( - 'edit-options-summary-options-' . str_replace('_', '-', $this->definition['name']) . '-override' => array(1) + 'edit-options-summary-options-' . str_replace('_', '-', $this->definition['name']) . '-override' => array(1), ), ); } - function render() { + /** + * {@inheritdoc} + */ + public function render() { $rows = array(); foreach ($this->view->result as $row) { - // @todo: Include separator as an option. + // @todo Include separator as an option. $rows[] = $row; } return theme($this->theme_functions(), array( 'view' => $this->view, 'options' => $this->options, - 'rows' => $rows + 'rows' => $rows, )); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_style_summary_jump_menu.inc b/sites/all/modules/views/plugins/views_plugin_style_summary_jump_menu.inc index a16a84b..ee75f24 100644 --- a/sites/all/modules/views/plugins/views_plugin_style_summary_jump_menu.inc +++ b/sites/all/modules/views/plugins/views_plugin_style_summary_jump_menu.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the default summary style plugin, which displays items in an HTML list. + * Definition of views_plugin_style_summary_jump_menu. */ /** @@ -11,7 +11,11 @@ * @ingroup views_style_plugins */ class views_plugin_style_summary_jump_menu extends views_plugin_style { - function option_definition() { + + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['base_path'] = array('default' => ''); @@ -26,7 +30,10 @@ class views_plugin_style_summary_jump_menu extends views_plugin_style { return $options; } - function query() { + /** + * {@inheritdoc} + */ + public function query() { // Copy the offset option. $pager = array( 'type' => 'none', @@ -35,7 +42,10 @@ class views_plugin_style_summary_jump_menu extends views_plugin_style { $this->display->handler->set_option('pager', $pager); } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { $form['base_path'] = array( '#type' => 'textfield', '#title' => t('Base path'), @@ -56,7 +66,7 @@ class views_plugin_style_summary_jump_menu extends views_plugin_style { '#type' => 'checkbox', '#title' => t('Hide the "Go" button'), '#default_value' => !empty($this->options['hide']), - '#description' => t('If hidden, this button will only be hidden for users with javascript and the page will automatically jump when the select is changed.'), + '#description' => t('If hidden, this button will only be hidden for users with JavaScript and the page will automatically jump when the select is changed.'), ); $form['text'] = array( @@ -93,7 +103,10 @@ class views_plugin_style_summary_jump_menu extends views_plugin_style { ); } - function render() { + /** + * {@inheritdoc} + */ + public function render() { $argument = $this->view->argument[$this->view->build_info['summary_level']]; $url_options = array(); @@ -143,4 +156,5 @@ class views_plugin_style_summary_jump_menu extends views_plugin_style { $form = drupal_get_form('ctools_jump_menu', $options, $settings); return drupal_render($form); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_style_summary_unformatted.inc b/sites/all/modules/views/plugins/views_plugin_style_summary_unformatted.inc index fc46624..fb16207 100644 --- a/sites/all/modules/views/plugins/views_plugin_style_summary_unformatted.inc +++ b/sites/all/modules/views/plugins/views_plugin_style_summary_unformatted.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the unformatted summary style plugin. + * Definition of views_plugin_style_summary_unformatted. */ /** @@ -11,14 +11,21 @@ * @ingroup views_style_plugins */ class views_plugin_style_summary_unformatted extends views_plugin_style_summary { - function option_definition() { + + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['inline'] = array('default' => FALSE, 'bool' => TRUE); $options['separator'] = array('default' => ''); return $options; } - function options_form(&$form, &$form_state) { + /** + * {@inheritdoc} + */ + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['inline'] = array( '#type' => 'checkbox', @@ -31,4 +38,5 @@ class views_plugin_style_summary_unformatted extends views_plugin_style_summary '#default_value' => $this->options['separator'], ); } + } diff --git a/sites/all/modules/views/plugins/views_plugin_style_table.inc b/sites/all/modules/views/plugins/views_plugin_style_table.inc index 45ed976..5467920 100644 --- a/sites/all/modules/views/plugins/views_plugin_style_table.inc +++ b/sites/all/modules/views/plugins/views_plugin_style_table.inc @@ -2,7 +2,7 @@ /** * @file - * Contains the table style plugin. + * Definition of views_plugin_style_table. */ /** @@ -24,10 +24,14 @@ class views_plugin_style_table extends views_plugin_style { */ public $order; - function option_definition() { + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['columns'] = array('default' => array()); + $options['class'] = array('default' => array()); $options['default'] = array('default' => ''); $options['info'] = array('default' => array()); $options['override'] = array('default' => TRUE, 'bool' => TRUE); @@ -45,7 +49,7 @@ class views_plugin_style_table extends views_plugin_style { * * @return bool */ - function build_sort() { + public function build_sort() { if (!isset($_GET['order']) && ($this->options['default'] == -1 || empty($this->view->field[$this->options['default']]))) { return TRUE; } @@ -62,7 +66,7 @@ class views_plugin_style_table extends views_plugin_style { /** * Add our actual sort criteria */ - function build_sort_post() { + public function build_sort_post() { if (!isset($_GET['order'])) { // check for a 'default' clicksort. If there isn't one, exit gracefully. if (empty($this->options['default'])) { @@ -111,10 +115,10 @@ class views_plugin_style_table extends views_plugin_style { * - Any fields not currently represented must be added. * - Columns must be re-ordered to match the fields. * - * @param $columns + * @param array $columns * An array of all fields; the key is the id of the field and the * value is the id of the column the field should be in. - * @param $fields + * @param array $fields * The fields to use for the columns. If not provided, they will * be requested from the current display. The running render should * send the fields through, as they may be different than what the @@ -123,7 +127,7 @@ class views_plugin_style_table extends views_plugin_style { * @return array * An array of all the sanitized columns. */ - function sanitize_columns($columns, $fields = NULL) { + public function sanitize_columns($columns, $fields = NULL) { $sanitized = array(); if ($fields === NULL) { $fields = $this->display->handler->get_option('fields'); @@ -157,7 +161,7 @@ class views_plugin_style_table extends views_plugin_style { /** * Render the given style. */ - function options_form(&$form, &$form_state) { + public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $handlers = $this->display->handler->get_handlers('field'); if (empty($handlers)) { @@ -175,7 +179,7 @@ class views_plugin_style_table extends views_plugin_style { $form['sticky'] = array( '#type' => 'checkbox', - '#title' => t('Enable Drupal style "sticky" table headers (Javascript)'), + '#title' => t('Enable Drupal style "sticky" table headers (JavaScript)'), '#default_value' => !empty($this->options['sticky']), '#description' => t('(Sticky header effects will not be active for preview below, only on live output.)'), ); @@ -195,6 +199,14 @@ class views_plugin_style_table extends views_plugin_style { '#default_value' => $this->options['summary'], '#maxlength' => 255, ); + + $form['class'] = array( + '#type' => 'textfield', + '#title' => t('CSS classes'), + '#description' => t('Add CSS classes to the table; multiple classes may be separated by spaces.'), + '#default_value' => $this->options['class'], + '#maxlength' => 255, + ); // Note: views UI registers this theme handler on our behalf. Your module // will have to register your theme handlers if you do stuff like this. @@ -202,7 +214,7 @@ class views_plugin_style_table extends views_plugin_style { $columns = $this->sanitize_columns($this->options['columns']); - // Create an array of allowed columns from the data we know: + // Create an array of allowed columns from the data we know. $field_names = $this->display->handler->get_field_labels(); if (isset($this->options['default'])) { @@ -293,7 +305,7 @@ class views_plugin_style_table extends views_plugin_style { '#type' => 'checkbox', '#title' => t('Show the empty text in the table'), '#default_value' => $this->options['empty_table'], - '#description' => t('Per default the table is hidden for an empty view. With this option it is posible to show an empty table with the text in it.'), + '#description' => t('Per default the table is hidden for an empty view. With this option it is possible to show an empty table with the text in it.'), ); $form['description_markup'] = array( @@ -301,7 +313,10 @@ class views_plugin_style_table extends views_plugin_style { ); } - function even_empty() { + /** + * + */ + public function even_empty() { return parent::even_empty() || !empty($this->options['empty_table']); } } diff --git a/sites/all/modules/views/plugins/views_wizard/file_managed.inc b/sites/all/modules/views/plugins/views_wizard/file_managed.inc index 049ce1b..191f9ab 100644 --- a/sites/all/modules/views/plugins/views_wizard/file_managed.inc +++ b/sites/all/modules/views/plugins/views_wizard/file_managed.inc @@ -14,8 +14,7 @@ $plugin = array( 'class' => 'ViewsUiFileManagedViewsWizard', ), 'title' => t('Files'), - 'filters' => array( - ), + 'filters' => array(), 'path_field' => array( 'id' => 'uri', 'table' => 'file_managed', diff --git a/sites/all/modules/views/plugins/views_wizard/node.inc b/sites/all/modules/views/plugins/views_wizard/node.inc index ccca48d..d5b3e3d 100644 --- a/sites/all/modules/views/plugins/views_wizard/node.inc +++ b/sites/all/modules/views/plugins/views_wizard/node.inc @@ -10,7 +10,7 @@ $plugin = array( 'base_table' => 'node', 'created_column' => 'created', 'available_sorts' => array( - 'title:DESC' => t('Title') + 'title:DESC' => t('Title'), ), 'form_wizard_class' => array( 'file' => 'views_ui_node_views_wizard.class.php', diff --git a/sites/all/modules/views/plugins/views_wizard/node_revision.inc b/sites/all/modules/views/plugins/views_wizard/node_revision.inc index ddf1d61..3a9ea64 100644 --- a/sites/all/modules/views/plugins/views_wizard/node_revision.inc +++ b/sites/all/modules/views/plugins/views_wizard/node_revision.inc @@ -17,7 +17,8 @@ $plugin = array( 'filters' => array( 'status' => array( 'value' => '1', - 'table' => 'node', // @todo - unclear if this should be node or node_revision + 'table' => 'node', +// @todo - unclear if this should be node or node_revision 'field' => 'status', ), ), diff --git a/sites/all/modules/views/plugins/views_wizard/taxonomy_term.inc b/sites/all/modules/views/plugins/views_wizard/taxonomy_term.inc index 599e354..687a4e9 100644 --- a/sites/all/modules/views/plugins/views_wizard/taxonomy_term.inc +++ b/sites/all/modules/views/plugins/views_wizard/taxonomy_term.inc @@ -14,8 +14,7 @@ if (module_exists('taxonomy')) { 'class' => 'ViewsUiTaxonomyTermViewsWizard', ), 'title' => t('Taxonomy terms'), - 'filters' => array( - ), + 'filters' => array(), 'path_field' => array( 'id' => 'tid', 'table' => 'taxonomy_term_data', diff --git a/sites/all/modules/views/plugins/views_wizard/views_ui_base_views_wizard.class.php b/sites/all/modules/views/plugins/views_wizard/views_ui_base_views_wizard.class.php index 8893ab8..35989c4 100644 --- a/sites/all/modules/views/plugins/views_wizard/views_ui_base_views_wizard.class.php +++ b/sites/all/modules/views/plugins/views_wizard/views_ui_base_views_wizard.class.php @@ -9,6 +9,10 @@ * Defines a common interface for Views Wizard plugins. */ interface ViewsWizardInterface { + + /** + * Constructor. + */ function __construct($plugin); /** @@ -31,6 +35,7 @@ interface ViewsWizardInterface { * @throws ViewsWizardException in the event of a problem. */ function create_view($form, &$form_state); + } /** @@ -43,6 +48,7 @@ class ViewsWizardException extends Exception { * A very generic Views Wizard class - can be constructed for any base table. */ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { + protected $base_table; protected $entity_type; protected $entity_info = array(); @@ -87,7 +93,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { $form['displays']['page'] = array( '#type' => 'fieldset', - '#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend'),), + '#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend')), '#tree' => TRUE, ); $form['displays']['page']['create'] = array( @@ -102,7 +108,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { // can be hidden en masse when the "Create a page" checkbox is unchecked. $form['displays']['page']['options'] = array( '#type' => 'container', - '#attributes' => array('class' => array('options-set'),), + '#attributes' => array('class' => array('options-set')), '#dependency' => array( 'edit-page-create' => array(1), ), @@ -224,7 +230,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { $form['displays']['block'] = array( '#type' => 'fieldset', - '#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend'),), + '#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend')), '#tree' => TRUE, ); $form['displays']['block']['create'] = array( @@ -238,7 +244,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { // can be hidden en masse when the "Create a block" checkbox is unchecked. $form['displays']['block']['options'] = array( '#type' => 'container', - '#attributes' => array('class' => array('options-set'),), + '#attributes' => array('class' => array('options-set')), '#dependency' => array( 'edit-block-create' => array(1), ), @@ -334,7 +340,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { } /** - * Build the part of the form that allows the user to select the view's filters. + * Build the part of the form that allows the user to select the filters. * * By default, this adds "of type" and "tagged with" filters (when they are * available). @@ -344,7 +350,8 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { $fields = views_fetch_fields($this->base_table, 'filter'); $entity_info = $this->entity_info; - // If the current base table support bundles and has more than one (like user). + // If the current base table support bundles and has more than one (like + // user). if (isset($entity_info['bundle keys']) && isset($entity_info['bundles'])) { // Get all bundles and their human readable names. $options = array('all' => t('All')); @@ -431,7 +438,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { } /** - * Build the part of the form that allows the user to select the view's sort order. + * Build the part of the form that allows the user to select the sort order. * * By default, this adds a "sorted by [date]" filter (when it is available). */ @@ -492,7 +499,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { * arrays of options for that display. */ protected function build_display_options($form, $form_state) { - // Display: Master + // Display: Master. $display_options['default'] = $this->default_display_options($form, $form_state); $display_options['default'] += array( 'filters' => array(), @@ -501,17 +508,17 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { $display_options['default']['filters'] += $this->default_display_filters($form, $form_state); $display_options['default']['sorts'] += $this->default_display_sorts($form, $form_state); - // Display: Page + // Display: Page. if (!empty($form_state['values']['page']['create'])) { $display_options['page'] = $this->page_display_options($form, $form_state); - // Display: Feed (attached to the page) + // Display: Feed (attached to the page). if (!empty($form_state['values']['page']['feed'])) { $display_options['feed'] = $this->page_feed_display_options($form, $form_state); } } - // Display: Block + // Display: Block. if (!empty($form_state['values']['block']['create'])) { $display_options['block'] = $this->block_display_options($form, $form_state); } @@ -573,13 +580,13 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { * Add the array of display options to the view, with appropriate overrides. */ protected function add_displays($view, $display_options, $form, $form_state) { - // Display: Master + // Display: Master. $default_display = $view->new_display('default', 'Master', 'default'); foreach ($display_options['default'] as $option => $value) { $default_display->set_option($option, $value); } - // Display: Page + // Display: Page. if (isset($display_options['page'])) { $display = $view->new_display('page', 'Page', 'page'); // The page display is usually the main one (from the user's point of @@ -587,14 +594,14 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { // so that new displays which are added later automatically inherit them. $this->set_default_options($display_options['page'], $display, $default_display); - // Display: Feed (attached to the page) + // Display: Feed (attached to the page). if (isset($display_options['feed'])) { $display = $view->new_display('feed', 'Feed', 'feed'); $this->set_override_options($display_options['feed'], $display, $default_display); } } - // Display: Block + // Display: Block. if (isset($display_options['block'])) { $display = $view->new_display('block', 'Block', 'block'); // When there is no page, the block display options should become the @@ -622,9 +629,10 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { $display_options['style_plugin'] = 'default'; $display_options['row_plugin'] = 'fields'; - // Add a least one field so the view validates and the user has already a preview. - // Therefore the basefield could provide 'defaults][field]' in it's base settings. - // If there is nothing like this choose the first field with a field handler. + // Add a least one field so the view validates and the user has already a + // preview. Therefore the basefield could provide 'defaults][field]' in + // it's base settings. If there is nothing like this choose the first field + // with a field handler. $data = views_fetch_data($this->base_table); if (isset($data['table']['base']['defaults']['field'])) { $field = $data['table']['base']['defaults']['field']; @@ -682,8 +690,9 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { } } $table_data = views_fetch_data($table); - // Check whether the bundle key filter handler is or an child of it views_handler_filter_in_operator - // If it's not just use a single value instead of an array. + // Check whether the bundle key filter handler is or an child of it + // views_handler_filter_in_operator. If it's not just use a single value + // instead of an array. $handler = $table_data[$bundle_key]['filter']['handler']; if ($handler == 'views_handler_filter_in_operator' || is_subclass_of($handler, 'views_handler_filter_in_operator')) { $value = drupal_map_assoc(array($form_state['values']['show']['type'])); @@ -700,7 +709,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { ); } - // @todo: Figure out why this isn't part of node_views_wizard. + // @todo Figure out why this isn't part of node_views_wizard. if (!empty($form_state['values']['show']['tagged_with']['tids'])) { $filters['tid'] = array( 'id' => 'tid', @@ -741,7 +750,8 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { protected function default_display_sorts_user($form, $form_state) { $sorts = array(); - // Don't add a sort if there is no form value or the user selected none as sort. + // Don't add a sort if there is no form value or the user selected none as + // sort. if (!empty($form_state['values']['show']['sort']) && $form_state['values']['show']['sort'] != 'none') { list($column, $sort) = explode(':', $form_state['values']['show']['sort']); // Column either be a column-name or the table-columnn-ame. @@ -826,14 +836,14 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { * so that new displays which the user adds later will be similar to this * one. * - * @param $options + * @param array $options * An array whose keys are the name of each option and whose values are the * desired values to set. - * @param $display + * @param object $display * The display which the options will be applied to. The default display * will actually be assigned the options (and this display will inherit * them) when possible. - * @param $default_display + * @param object$default_display * The default display, which will store the options when possible. */ protected function set_default_options($options, $display, $default_display) { @@ -862,13 +872,13 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { * the views wizard, then the view will wind up with the title stored as the * default (with the page and block both inheriting from it). * - * @param $options + * @param array $options * An array whose keys are the name of each option and whose values are the * desired values. - * @param $display + * @param object $display * The display which the options will apply to. It will get the options by * inheritance from the default display when possible. - * @param $default_display + * @param object $default_display * The default display, from which the options will be inherited when * possible. */ @@ -918,12 +928,12 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface { * * @throws ViewsWizardException if the values have not been validated. */ - function create_view($form, &$form_state) { - $view = $this->retrieve_validated_view($form, $form_state); - if (empty($view)) { - throw new ViewsWizardException(t('Attempted to create_view with values that have not been validated')); - } - return $view; - } + function create_view($form, &$form_state) { + $view = $this->retrieve_validated_view($form, $form_state); + if (empty($view)) { + throw new ViewsWizardException(t('Attempted to create_view with values that have not been validated')); + } + return $view; + } } diff --git a/sites/all/modules/views/plugins/views_wizard/views_ui_comment_views_wizard.class.php b/sites/all/modules/views/plugins/views_wizard/views_ui_comment_views_wizard.class.php index fa26d33..4b68e98 100644 --- a/sites/all/modules/views/plugins/views_wizard/views_ui_comment_views_wizard.class.php +++ b/sites/all/modules/views/plugins/views_wizard/views_ui_comment_views_wizard.class.php @@ -105,4 +105,5 @@ class ViewsUiCommentViewsWizard extends ViewsUiBaseViewsWizard { return $display_options; } + } diff --git a/sites/all/modules/views/plugins/views_wizard/views_ui_file_managed_views_wizard.class.php b/sites/all/modules/views/plugins/views_wizard/views_ui_file_managed_views_wizard.class.php index 111b631..12435cb 100644 --- a/sites/all/modules/views/plugins/views_wizard/views_ui_file_managed_views_wizard.class.php +++ b/sites/all/modules/views/plugins/views_wizard/views_ui_file_managed_views_wizard.class.php @@ -9,6 +9,7 @@ * Tests creating managed files views with the wizard. */ class ViewsUiFileManagedViewsWizard extends ViewsUiBaseViewsWizard { + protected function default_display_options($form, $form_state) { $display_options = parent::default_display_options($form, $form_state); @@ -37,4 +38,5 @@ class ViewsUiFileManagedViewsWizard extends ViewsUiBaseViewsWizard { return $display_options; } + } diff --git a/sites/all/modules/views/plugins/views_wizard/views_ui_node_revision_views_wizard.class.php b/sites/all/modules/views/plugins/views_wizard/views_ui_node_revision_views_wizard.class.php index 3623f53..49d52e0 100644 --- a/sites/all/modules/views/plugins/views_wizard/views_ui_node_revision_views_wizard.class.php +++ b/sites/all/modules/views/plugins/views_wizard/views_ui_node_revision_views_wizard.class.php @@ -65,4 +65,5 @@ class ViewsUiNodeRevisionViewsWizard extends ViewsUiNodeViewsWizard { return $display_options; } + } diff --git a/sites/all/modules/views/plugins/views_wizard/views_ui_node_views_wizard.class.php b/sites/all/modules/views/plugins/views_wizard/views_ui_node_views_wizard.class.php index 07bb91d..ffdd7d1 100644 --- a/sites/all/modules/views/plugins/views_wizard/views_ui_node_views_wizard.class.php +++ b/sites/all/modules/views/plugins/views_wizard/views_ui_node_views_wizard.class.php @@ -118,20 +118,24 @@ class ViewsUiNodeViewsWizard extends ViewsUiBaseViewsWizard { $display_options['row_options']['links'] = !empty($row_options['links']); $display_options['row_options']['comments'] = !empty($row_options['comments']); break; + case 'teasers': $display_options['row_plugin'] = 'node'; $display_options['row_options']['build_mode'] = 'teaser'; $display_options['row_options']['links'] = !empty($row_options['links']); $display_options['row_options']['comments'] = !empty($row_options['comments']); break; + case 'titles_linked': $display_options['row_plugin'] = 'fields'; $display_options['field']['title']['link_to_node'] = 1; break; + case 'titles': $display_options['row_plugin'] = 'fields'; $display_options['field']['title']['link_to_node'] = 0; break; } } + } diff --git a/sites/all/modules/views/plugins/views_wizard/views_ui_taxonomy_term_views_wizard.class.php b/sites/all/modules/views/plugins/views_wizard/views_ui_taxonomy_term_views_wizard.class.php index 8c1d6d5..b73156e 100644 --- a/sites/all/modules/views/plugins/views_wizard/views_ui_taxonomy_term_views_wizard.class.php +++ b/sites/all/modules/views/plugins/views_wizard/views_ui_taxonomy_term_views_wizard.class.php @@ -39,4 +39,5 @@ class ViewsUiTaxonomyTermViewsWizard extends ViewsUiBaseViewsWizard { return $display_options; } + } diff --git a/sites/all/modules/views/plugins/views_wizard/views_ui_users_views_wizard.class.php b/sites/all/modules/views/plugins/views_wizard/views_ui_users_views_wizard.class.php index 73eff48..c20c89e 100644 --- a/sites/all/modules/views/plugins/views_wizard/views_ui_users_views_wizard.class.php +++ b/sites/all/modules/views/plugins/views_wizard/views_ui_users_views_wizard.class.php @@ -9,6 +9,7 @@ * Tests creating user views with the wizard. */ class ViewsUiUsersViewsWizard extends ViewsUiBaseViewsWizard { + protected function default_display_options($form, $form_state) { $display_options = parent::default_display_options($form, $form_state); @@ -39,4 +40,5 @@ class ViewsUiUsersViewsWizard extends ViewsUiBaseViewsWizard { return $display_options; } + } diff --git a/sites/all/modules/views/test_templates/views-view--frontpage.tpl.php b/sites/all/modules/views/test_templates/views-view--frontpage.tpl.php index eb4f58b..bfe67b1 100644 --- a/sites/all/modules/views/test_templates/views-view--frontpage.tpl.php +++ b/sites/all/modules/views/test_templates/views-view--frontpage.tpl.php @@ -22,7 +22,7 @@ * - $pager: The pager next/prev links to display, if any * - $exposed: Exposed widget form/info to display * - $feed_icon: Feed icon to display, if any - * - $more: A link to view more, if any + * - $more: A link to view more, if any. * * @ingroup views_templates */ diff --git a/sites/all/modules/views/tests/README.txt b/sites/all/modules/views/tests/README.txt new file mode 100644 index 0000000..e292de3 --- /dev/null +++ b/sites/all/modules/views/tests/README.txt @@ -0,0 +1,29 @@ +Views Tests +``````````` +All of the tests may be executed with the following command: + +$ scripts/run-tests.sh --color --url http://example.com/ --php `which php` --concurrency 4 --verbose --directory 'sites/all/modules/contrib/views/tests' 2> /dev/null + +Explanation: + --color + Colorizes the output. Optional. + --url http://example.com/ + The name of the Drupal 7 hostname used locally for running tests, e.g. + "http://drupal7.dev". Required. + --php `which php` + Tells the test runner the path to the PHP binary. Only necessary if the test + runner is unable to find the path automatically or to use an alternative + PHP binary. Optional. + --cuncurrency 4 + Run multiple test processes simultaneously. Four appears to be a good + balance between melting the computer and improving performance. Optional. + --verbose + Display results for all of the assertion statements after the summary + details. Optional. + --directory 'sites/all/modules/contrib/views/tests' + Run all of the commands in the following directory. The path is relative to + the Drupal installation's root directory. This will run all of Views' tests + in one go, rather than either repeating the names of test groups or running + multiple commands. Optional. + 2> /dev/null + Outputs all error messages to /dev/null, i.e. hides them. Optional. diff --git a/sites/all/modules/views/tests/comment/views_handler_argument_comment_user_uid.test b/sites/all/modules/views/tests/comment/views_handler_argument_comment_user_uid.test index 353d929..9599499 100644 --- a/sites/all/modules/views/tests/comment/views_handler_argument_comment_user_uid.test +++ b/sites/all/modules/views/tests/comment/views_handler_argument_comment_user_uid.test @@ -20,10 +20,10 @@ class viewsHandlerArgumentCommentUserUidTest extends ViewsSqlTest { /** * Post comment. * - * @param $node + * @param object $node * Node to post comment on. - * @param $comment - * Comment to save + * @param array $comment + * Comment to save. */ function postComment($node, $comment = array()) { $comment += array( @@ -38,8 +38,8 @@ class viewsHandlerArgumentCommentUserUidTest extends ViewsSqlTest { function setUp() { parent::setUp(); - // Add two users, create a node with the user1 as author and another node with user2 as author. - // For the second node add a comment from user1. + // Add two users, create a node with the user1 as author and another node + // with user2 as author. For the second node add a comment from user1. $this->account = $this->drupalCreateUser(); $this->account2 = $this->drupalCreateUser(); $this->drupalLogin($this->account); @@ -51,7 +51,6 @@ class viewsHandlerArgumentCommentUserUidTest extends ViewsSqlTest { function testCommentUserUidTest() { $view = $this->view_comment_user_uid(); - $this->executeView($view, array($this->account->uid)); $resultset = array( array( @@ -67,7 +66,7 @@ class viewsHandlerArgumentCommentUserUidTest extends ViewsSqlTest { } function view_comment_user_uid() { - $view = new view; + $view = new view(); $view->name = 'test_comment_user_uid'; $view->description = ''; $view->tag = 'default'; @@ -103,4 +102,5 @@ class viewsHandlerArgumentCommentUserUidTest extends ViewsSqlTest { return $view; } + } diff --git a/sites/all/modules/views/tests/comment/views_handler_filter_comment_user_uid.test b/sites/all/modules/views/tests/comment/views_handler_filter_comment_user_uid.test index 1f3f75c..4093317 100644 --- a/sites/all/modules/views/tests/comment/views_handler_filter_comment_user_uid.test +++ b/sites/all/modules/views/tests/comment/views_handler_filter_comment_user_uid.test @@ -38,4 +38,5 @@ class viewsHandlerFilterCommentUserUidTest extends viewsHandlerArgumentCommentUs return $view; } + } diff --git a/sites/all/modules/views/tests/field/views_fieldapi.test b/sites/all/modules/views/tests/field/views_fieldapi.test index da4c27b..0d049e1 100644 --- a/sites/all/modules/views/tests/field/views_fieldapi.test +++ b/sites/all/modules/views/tests/field/views_fieldapi.test @@ -6,33 +6,40 @@ */ /** - * @TODO - * - Test on a generic entity not on a node. + * @todo Test on a generic entity not on a node. * * What has to be tested: - * - Take sure that every wanted field is added to the according entity type. - * - Take sure the joins are done correct. - * - Use basic fields and take sure that the full wanted object is build. - * - Use relationships between different entity types, for example node and the node author(user). + * - Take sure that every wanted field is added to the according entity type. + * - Take sure the joins are done correct. + * - Use basic fields and take sure that the full wanted object is build. + * - Use relationships between different entity types, for example node and + * the node author(user). */ /** * Provides some helper methods for testing fieldapi integration into views. */ class ViewsFieldApiTestHelper extends ViewsSqlTest { + /** * Stores the field definitions used by the test. + * * @var array */ public $fields; + /** * Stores the instances of the fields. They have * the same keys as the fields. + * * @var array */ public $instances; - protected function CreateUser($extra_edit = array()) { + /** + * + */ + protected function createUser($extra_edit = array()) { $permissions = array('access comments', 'access content', 'post comments', 'skip comment approval'); // Create a role with the given permission set. if (!($rid = $this->drupalCreateRole($permissions))) { @@ -92,6 +99,7 @@ class ViewsFieldApiTestHelper extends ViewsSqlTest { drupal_static_reset('_views_fetch_data_recursion_protected'); drupal_static_reset('_views_fetch_data_fully_loaded'); } + } /** @@ -116,7 +124,6 @@ class viewsFieldApiDataTest extends ViewsFieldApiTestHelper { $langcode = LANGUAGE_NONE; - $field_names = $this->setUpFields(); // The first one will be attached to nodes only. @@ -152,7 +159,7 @@ class viewsFieldApiDataTest extends ViewsFieldApiTestHelper { // Now create some example nodes/users for the view result. for ($i = 0; $i < 5; $i++) { $edit = array( - // @TODO Write a helper method to create such values. + // @todo Write a helper method to create such values. 'field_name_0' => array($langcode => array((array('value' => $this->randomName())))), 'field_name_2' => array($langcode => array((array('value' => $this->randomName())))), ); @@ -164,7 +171,7 @@ class viewsFieldApiDataTest extends ViewsFieldApiTestHelper { 'field_name_1' => array($langcode => array((array('value' => $this->randomName())))), 'field_name_2' => array($langcode => array((array('value' => $this->randomName())))), ); - $this->users[] = $this->CreateUser($edit); + $this->users[] = $this->createUser($edit); } // Reset views data cache. @@ -178,7 +185,7 @@ class viewsFieldApiDataTest extends ViewsFieldApiTestHelper { */ function testViewsData() { $data = views_fetch_data(); - + // Check the table and the joins of the first field. // Attached to node only. $field = $this->fields[0]; @@ -210,7 +217,6 @@ class viewsFieldApiDataTest extends ViewsFieldApiTestHelper { ); $this->assertEqual($expected_join, $data[$revision_table]['table']['join']['node_revision']); - // Check the table and the joins of the second field. // Attached to both node and user. $field_2 = $this->fields[2]; @@ -230,7 +236,7 @@ class viewsFieldApiDataTest extends ViewsFieldApiTestHelper { 'extra' => array( array('field' => 'entity_type', 'value' => 'node'), array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE), - ) + ), ); $this->assertEqual($expected_join, $data[$current_table_2]['table']['join']['node']); $expected_join = array( @@ -239,7 +245,7 @@ class viewsFieldApiDataTest extends ViewsFieldApiTestHelper { 'extra' => array( array('field' => 'entity_type', 'value' => 'node'), array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE), - ) + ), ); $this->assertEqual($expected_join, $data[$revision_table_2]['table']['join']['node_revision']); $expected_join = array( @@ -248,32 +254,25 @@ class viewsFieldApiDataTest extends ViewsFieldApiTestHelper { 'extra' => array( array('field' => 'entity_type', 'value' => 'user'), array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE), - ) + ), ); $this->assertEqual($expected_join, $data[$current_table_2]['table']['join']['users']); - // Check the fields - // @todo - - // Check the arguments - // @todo - - // Check the sort criterias - // @todo - - // Check the relationships - // @todo - + // @todo Check the fields. + // @todo Check the arguments. + // @todo Check the sort criterias. + // @todo Check the relationships. } + } /** * Tests the field_field handler. - * @TODO - * Check a entity-type with bundles - * Check a entity-type without bundles - * Check locale:disabled, locale:enabled and locale:enabled with another language - * Check revisions + * + * @todo Check a entity-type with bundles. + * @todo Check a entity-type without bundles. + * @todo Check locale:disabled, locale:enabled and locale:enabled with another language. + * @todo Check revisions. */ class viewsHandlerFieldFieldTest extends ViewsFieldApiTestHelper { public $nodes; @@ -282,7 +281,7 @@ class viewsHandlerFieldFieldTest extends ViewsFieldApiTestHelper { return array( 'name' => 'Fieldapi: Field handler', 'description' => 'Tests the field itself of the fieldapi integration', - 'group' => 'Views Modules' + 'group' => 'Views Modules', ); } @@ -353,7 +352,7 @@ class viewsHandlerFieldFieldTest extends ViewsFieldApiTestHelper { $this->executeView($view); // Take sure that the formatter works as expected. - // @TODO: actually there should be a specific formatter. + // @todo actually there should be a specific formatter. for ($i = 0; $i < 2; $i++) { $rendered_field = $view->style_plugin->get_field($i, $this->fields[0]['field_name']); $this->assertEqual(strlen($rendered_field), 3); @@ -384,7 +383,7 @@ class viewsHandlerFieldFieldTest extends ViewsFieldApiTestHelper { $view->destroy(); - // Test delta limit + offset + // Test delta limit + offset. $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE; $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3; $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_offset'] = 1; @@ -459,7 +458,7 @@ class viewsHandlerFieldFieldTest extends ViewsFieldApiTestHelper { } protected function getFieldView() { - $view = new view; + $view = new view(); $view->name = 'view_fieldapi'; $view->description = ''; $view->tag = 'default'; @@ -491,4 +490,3 @@ class viewsHandlerFieldFieldTest extends ViewsFieldApiTestHelper { } } - diff --git a/sites/all/modules/views/tests/handlers/views_handler_area_text.test b/sites/all/modules/views/tests/handlers/views_handler_area_text.test index 9f30e0c..c5ebe81 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_area_text.test +++ b/sites/all/modules/views/tests/handlers/views_handler_area_text.test @@ -22,7 +22,7 @@ class ViewsHandlerAreaTextTest extends ViewsSqlTest { public function testAreaText() { $view = $this->getBasicView(); - // add a text header + // add a text header. $string = $this->randomName(); $view->display['default']->handler->override_option('header', array( 'area' => array( diff --git a/sites/all/modules/views/tests/handlers/views_handler_argument_null.test b/sites/all/modules/views/tests/handlers/views_handler_argument_null.test index e8650a3..95db4df 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_argument_null.test +++ b/sites/all/modules/views/tests/handlers/views_handler_argument_null.test @@ -25,7 +25,7 @@ class ViewsHandlerArgumentNullTest extends ViewsSqlTest { } public function testAreaText() { - // Test validation + // Test validation. $view = $this->getBasicView(); // Add a null argument. diff --git a/sites/all/modules/views/tests/handlers/views_handler_argument_string.test b/sites/all/modules/views/tests/handlers/views_handler_argument_string.test index d078abf..4c76ff6 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_argument_string.test +++ b/sites/all/modules/views/tests/handlers/views_handler_argument_string.test @@ -53,6 +53,7 @@ class ViewsHandlerArgumentStringTest extends ViewsSqlTest { * Provide a test view for testGlossary. * * @see testGlossary + * * @return view */ function viewGlossary() { @@ -93,4 +94,5 @@ class ViewsHandlerArgumentStringTest extends ViewsSqlTest { return $view; } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_field.test b/sites/all/modules/views/tests/handlers/views_handler_field.test index 9e6dfca..df9574f 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_field.test +++ b/sites/all/modules/views/tests/handlers/views_handler_field.test @@ -6,11 +6,15 @@ */ /** - * Tests the generic field handler + * Tests the generic field handler. * * @see views_handler_field */ class ViewsHandlerFieldTest extends ViewsSqlTest { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Field', @@ -19,6 +23,9 @@ class ViewsHandlerFieldTest extends ViewsSqlTest { ); } + /** + * + */ protected function setUp() { parent::setUp(); $this->column_map = array( @@ -26,17 +33,12 @@ class ViewsHandlerFieldTest extends ViewsSqlTest { ); } - function testEmpty() { - $this->_testHideIfEmpty(); - $this->_testEmptyText(); - } - /** * Tests the hide if empty functionality. * * This tests alters the result to get easier and less coupled results. */ - function _testHideIfEmpty() { + public function testHideIfEmpty() { $view = $this->getBasicView(); $view->init_display(); $this->executeView($view); @@ -139,7 +141,8 @@ class ViewsHandlerFieldTest extends ViewsSqlTest { $render = $view->field['name']->advanced_render($view->result[0]); $this->assertIdentical($render, $random_name, 'If the rewritten string is not empty, "0" should not be treated as empty.'); - // Test when results are rewritten to an empty string and non-zero empty results are hidden. + // Test when results are rewritten to an empty string and non-zero empty + // results are hidden. $view->field['name']->options['hide_alter_empty'] = TRUE; $view->field['name']->options['hide_empty'] = TRUE; $view->field['name']->options['empty_zero'] = FALSE; @@ -254,7 +257,7 @@ class ViewsHandlerFieldTest extends ViewsSqlTest { /** * Tests the usage of the empty text. */ - function _testEmptyText() { + public function testEmptyText() { $view = $this->getBasicView(); $view->init_display(); $this->executeView($view); @@ -291,7 +294,7 @@ class ViewsHandlerFieldTest extends ViewsSqlTest { /** * Tests views_handler_field::is_value_empty(). */ - function testIsValueEmpty() { + public function testIsValueEmpty() { $view = $this->getBasicView(); $view->init_display(); $view->init_handlers(); diff --git a/sites/all/modules/views/tests/handlers/views_handler_field_boolean.test b/sites/all/modules/views/tests/handlers/views_handler_field_boolean.test index 286b942..38eb38c 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_field_boolean.test +++ b/sites/all/modules/views/tests/handlers/views_handler_field_boolean.test @@ -18,7 +18,7 @@ class ViewsHandlerFieldBooleanTest extends ViewsSqlTest { } function dataSet() { - // Use default dataset but remove the age from john and paul + // Use default dataset but remove the age from john and paul. $data = parent::dataSet(); $data[0]['age'] = 0; $data[3]['age'] = 0; @@ -105,4 +105,5 @@ class ViewsHandlerFieldBooleanTest extends ViewsSqlTest { $this->assertNotEqual($values['false'], $view->field['age']->advanced_render($view->result[0])); $this->assertNotEqual($values['true'], $view->field['age']->advanced_render($view->result[1])); } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_field_counter.test b/sites/all/modules/views/tests/handlers/views_handler_field_counter.test index 2ddcb6f..9a4766a 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_field_counter.test +++ b/sites/all/modules/views/tests/handlers/views_handler_field_counter.test @@ -48,7 +48,7 @@ class ViewsHandlerFilterCounterTest extends ViewsSqlTest { 'table' => 'views', 'field' => 'counter', 'relationship' => 'none', - 'counter_start' => $rand_start + 'counter_start' => $rand_start, ), 'name' => array( 'id' => 'name', @@ -64,7 +64,8 @@ class ViewsHandlerFilterCounterTest extends ViewsSqlTest { $this->assertEqual(2 + $rand_start, $view->style_plugin->rendered_fields[2]['counter']); } - // @TODO: Write tests for pager. + // @todo Write tests for pager. function testPager() { } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_field_custom.test b/sites/all/modules/views/tests/handlers/views_handler_field_custom.test index b45fd17..b8f8a08 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_field_custom.test +++ b/sites/all/modules/views/tests/handlers/views_handler_field_custom.test @@ -44,4 +44,5 @@ class ViewsHandlerFieldCustomTest extends ViewsSqlTest { $this->assertEqual($random, $view->style_plugin->get_field(0, 'name')); } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_field_date.test b/sites/all/modules/views/tests/handlers/views_handler_field_date.test index 7944142..54cbf0e 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_field_date.test +++ b/sites/all/modules/views/tests/handlers/views_handler_field_date.test @@ -9,6 +9,10 @@ * Tests the core views_handler_field_date handler. */ class ViewsHandlerFieldDateTest extends ViewsSqlTest { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Field: Date', @@ -17,12 +21,18 @@ class ViewsHandlerFieldDateTest extends ViewsSqlTest { ); } + /** + * + */ function viewsData() { $data = parent::viewsData(); $data['views_test']['created']['field']['handler'] = 'views_handler_field_date'; return $data; } + /** + * + */ public function testFieldDate() { $view = $this->getBasicView(); @@ -32,7 +42,8 @@ class ViewsHandlerFieldDateTest extends ViewsSqlTest { 'table' => 'views_test', 'field' => 'created', 'relationship' => 'none', - // c is iso 8601 date format @see http://php.net/manual/en/function.date.php + // c is iso 8601 date format. + // @see http://php.net/manual/en/function.date.php 'custom_date_format' => 'c', 'second_date_format' => 'custom', 'second_date_format_custom' => 'c', @@ -62,13 +73,17 @@ class ViewsHandlerFieldDateTest extends ViewsSqlTest { $intervals = array( 'raw time ago' => format_interval(REQUEST_TIME - $time, 2), 'time ago' => t('%time ago', array('%time' => format_interval(REQUEST_TIME - $time, 2))), - // TODO write tests for them -// 'raw time span' => format_interval(REQUEST_TIME - $time, 2), -// 'time span' => t('%time hence', array('%time' => format_interval(REQUEST_TIME - $time, 2))), + // @todo write tests for them + // 'raw time span' => format_interval(REQUEST_TIME - $time, 2), + // 'time span' => t('%time hence', + // array('%time' => format_interval(REQUEST_TIME - $time, 2))), ); $this->assertRenderedDatesEqual($view, $intervals); } + /** + * + */ protected function assertRenderedDatesEqual($view, $map, $timezone = NULL) { foreach ($map as $date_format => $expected_result) { $check_result_number = 0; @@ -114,4 +129,5 @@ class ViewsHandlerFieldDateTest extends ViewsSqlTest { return $data; } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_field_file_extension.test b/sites/all/modules/views/tests/handlers/views_handler_field_file_extension.test index ab8b0a9..ddc12f9 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_field_file_extension.test +++ b/sites/all/modules/views/tests/handlers/views_handler_field_file_extension.test @@ -63,4 +63,5 @@ class ViewsHandlerFileExtensionTest extends ViewsSqlTest { $this->assertEqual($view->field['name']->advanced_render($view->result[2]), 'tar.gz'); $this->assertEqual($view->field['name']->advanced_render($view->result[3]), ''); } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_field_file_size.test b/sites/all/modules/views/tests/handlers/views_handler_field_file_size.test index 8652754..a8828c7 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_field_file_size.test +++ b/sites/all/modules/views/tests/handlers/views_handler_field_file_size.test @@ -61,4 +61,5 @@ class ViewsHandlerTestFileSize extends ViewsSqlTest { $this->assertEqual($view->field['age']->advanced_render($view->result[2]), 1000); $this->assertEqual($view->field['age']->advanced_render($view->result[3]), 10000); } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_field_math.test b/sites/all/modules/views/tests/handlers/views_handler_field_math.test index ac33ac4..cd39528 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_field_math.test +++ b/sites/all/modules/views/tests/handlers/views_handler_field_math.test @@ -42,4 +42,5 @@ class ViewsHandlerFieldMath extends ViewsSqlTest { $this->assertEqual($rand1 + $rand2, $view->style_plugin->get_field(0, 'expression')); } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_field_url.test b/sites/all/modules/views/tests/handlers/views_handler_field_url.test index 527e94f..ad6f71d 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_field_url.test +++ b/sites/all/modules/views/tests/handlers/views_handler_field_url.test @@ -57,4 +57,5 @@ class ViewsHandlerFieldUrlTest extends ViewsSqlTest { $this->assertEqual(l('John', 'John'), $view->field['name']->advanced_render($view->result[0])); } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_field_xss.test b/sites/all/modules/views/tests/handlers/views_handler_field_xss.test index 65a1ce2..c12a408 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_field_xss.test +++ b/sites/all/modules/views/tests/handlers/views_handler_field_xss.test @@ -23,7 +23,7 @@ class ViewsHandlerTestXss extends ViewsSqlTest { $map = array( 'John' => 'John', "Foo\xC0barbaz" => '', - 'Fooÿñ' => 'Fooÿñ' + 'Fooÿñ' => 'Fooÿñ', ); return $map; @@ -57,4 +57,5 @@ class ViewsHandlerTestXss extends ViewsSqlTest { $counter++; } } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_filter_combine.test b/sites/all/modules/views/tests/handlers/views_handler_filter_combine.test index 99bf1eb..57d5e6f 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_filter_combine.test +++ b/sites/all/modules/views/tests/handlers/views_handler_filter_combine.test @@ -102,4 +102,5 @@ class ViewsHandlerFilterCombineTest extends ViewsSqlTest { unset($schema['views_test']['fields']['job']['not null']); return $schema; } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_filter_date.test b/sites/all/modules/views/tests/handlers/views_handler_filter_date.test index 8b92ccb..ad6a98b 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_filter_date.test +++ b/sites/all/modules/views/tests/handlers/views_handler_filter_date.test @@ -168,7 +168,7 @@ class ViewsHandlerFilterDateTest extends ViewsSqlTest { $view = $this->views_test_between(); $view->save(); - $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration')); + $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration')); $this->drupalLogin($admin_user); menu_rebuild(); $this->drupalGet('admin/structure/views/view/test_filter_date_between/edit'); @@ -182,7 +182,7 @@ class ViewsHandlerFilterDateTest extends ViewsSqlTest { } function views_test_between() { - $view = new view; + $view = new view(); $view->name = 'test_filter_date_between'; $view->description = ''; $view->tag = ''; @@ -218,4 +218,5 @@ class ViewsHandlerFilterDateTest extends ViewsSqlTest { $view = $this->views_test_between(); return $view; } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_filter_equality.test b/sites/all/modules/views/tests/handlers/views_handler_filter_equality.test index 5bb48c8..a1dbc4e 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_filter_equality.test +++ b/sites/all/modules/views/tests/handlers/views_handler_filter_equality.test @@ -34,7 +34,7 @@ class ViewsHandlerFilterEqualityTest extends ViewsSqlTest { function testEqual() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'name' => array( 'id' => 'name', @@ -59,7 +59,7 @@ class ViewsHandlerFilterEqualityTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Name, Operator: =, Value: Ringo + // Filter: Name, Operator: =, Value: Ringo. $filters['name']['group_info']['default_group'] = 1; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); @@ -76,7 +76,7 @@ class ViewsHandlerFilterEqualityTest extends ViewsSqlTest { function testNotEqual() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'name' => array( 'id' => 'name', @@ -110,7 +110,7 @@ class ViewsHandlerFilterEqualityTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Name, Operator: !=, Value: Ringo + // Filter: Name, Operator: !=, Value: Ringo. $filters['name']['group_info']['default_group'] = 2; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); diff --git a/sites/all/modules/views/tests/handlers/views_handler_filter_numeric.test b/sites/all/modules/views/tests/handlers/views_handler_filter_numeric.test index 2ab1aea..a18e20a 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_filter_numeric.test +++ b/sites/all/modules/views/tests/handlers/views_handler_filter_numeric.test @@ -38,7 +38,7 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { public function testFilterNumericSimple() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'age' => array( 'id' => 'age', @@ -82,7 +82,7 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { public function testFilterNumericBetween() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'age' => array( 'id' => 'age', @@ -114,11 +114,11 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { ); $this->assertIdenticalResultset($view, $resultset, $this->column_map); - // test not between + // test not between. $view->delete(); $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'age' => array( 'id' => 'age', @@ -160,7 +160,6 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); - $this->executeView($view); $resultset = array( array( @@ -188,7 +187,6 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); - $this->executeView($view); $resultset = array( array( @@ -211,7 +209,7 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { public function testFilterNumericEmpty() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'age' => array( 'id' => 'age', @@ -223,14 +221,13 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { )); $this->executeView($view); - $resultset = array( - ); + $resultset = array(); $this->assertIdenticalResultset($view, $resultset, $this->column_map); $view->delete(); $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'age' => array( 'id' => 'age', @@ -243,7 +240,7 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { $this->executeView($view); $resultset = array( - array( + array( 'name' => 'John', 'age' => 25, ), @@ -272,15 +269,13 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Age, Operator: empty, Value: + // Filter: Age, Operator: empty, Value. $filters['age']['group_info']['default_group'] = 4; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); - $this->executeView($view); - $resultset = array( - ); + $resultset = array(); $this->assertIdenticalResultset($view, $resultset, $this->column_map); } @@ -288,15 +283,14 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Age, Operator: empty, Value: + // Filter: Age, Operator: empty, Value. $filters['age']['group_info']['default_group'] = 5; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); - $this->executeView($view); $resultset = array( - array( + array( 'name' => 'John', 'age' => 25, ), @@ -320,6 +314,38 @@ class ViewsHandlerFilterNumericTest extends ViewsSqlTest { $this->assertIdenticalResultset($view, $resultset, $this->column_map); } + /** + * Tests the limit operators functionality. + */ + public function testFilterNumericExposedLimitOperators() { + $filters = $this->getGroupedExposedFilters(); + $view = $this->getBasicView(); + + $available_operators = array('<', '>', 'between'); + + $filters['age']['expose'] += array( + 'limit_operators' => TRUE, + 'available_operators' => drupal_map_assoc($available_operators), + ); + + $view->display['default']->handler->override_option('filters', $filters); + + + $this->executeView($view); + + $form = array(); + $form_state = array(); + $view->filter['age']->operator_form($form, $form_state); + + $operator = $form['operator']; + + $this->assertTrue(in_array($operator['#default_value'], $available_operators), 'Default value operator found in list of available operators.'); + + foreach ($available_operators as $available_operator) { + $this->assertTrue($operator['#options'][$available_operator], format_string('@operator found in options', array('@operator' => $available_operator))); + } + } + public function testAllowEmpty() { $view = $this->getBasicView(); diff --git a/sites/all/modules/views/tests/handlers/views_handler_filter_string.test b/sites/all/modules/views/tests/handlers/views_handler_filter_string.test index ee74a28..ab6af92 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_filter_string.test +++ b/sites/all/modules/views/tests/handlers/views_handler_filter_string.test @@ -75,7 +75,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringEqual() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'name' => array( 'id' => 'name', @@ -100,7 +100,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Name, Operator: =, Value: Ringo + // Filter: Name, Operator: =, Value: Ringo. $filters['name']['group_info']['default_group'] = 1; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); @@ -119,7 +119,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringNotEqual() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'name' => array( 'id' => 'name', @@ -153,7 +153,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Name, Operator: !=, Value: Ringo + // Filter: Name, Operator: !=, Value: Ringo. $filters['name']['group_info']['default_group'] = '2'; $view->set_display('page_1'); @@ -182,7 +182,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringContains() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'name' => array( 'id' => 'name', @@ -208,7 +208,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Name, Operator: contains, Value: ing + // Filter: Name, Operator: contains, Value: ing. $filters['name']['group_info']['default_group'] = '3'; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); @@ -228,7 +228,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringWord() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'description' => array( 'id' => 'description', @@ -254,7 +254,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'description' => array( 'id' => 'description', @@ -277,10 +277,10 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringGroupedExposedWord() { - $filters = $this->getGroupedExposedFilters(); + $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Name, Operator: contains, Value: ing + // Filter: Name, Operator: contains, Value: ing. $filters['name']['group_info']['default_group'] = '3'; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); @@ -299,7 +299,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Description, Operator: contains, Value: actor + // Filter: Description, Operator: contains, Value: actor. $filters['description']['group_info']['default_group'] = '1'; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); @@ -319,7 +319,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringStarts() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'description' => array( 'id' => 'description', @@ -344,7 +344,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Name, Operator: starts, Value: George + // Filter: Name, Operator: starts, Value: George. $filters['description']['group_info']['default_group'] = 2; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); @@ -362,7 +362,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringNotStarts() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'description' => array( 'id' => 'description', @@ -385,7 +385,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { array( 'name' => 'Paul', ), - // There is no Meredith returned because his description is empty + // There is no Meredith returned because his description is empty. ); $this->assertIdenticalResultset($view, $resultset, $this->column_map); } @@ -394,7 +394,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Name, Operator: not_starts, Value: George + // Filter: Name, Operator: not_starts, Value: George. $filters['description']['group_info']['default_group'] = 3; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); @@ -411,7 +411,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { array( 'name' => 'Paul', ), - // There is no Meredith returned because his description is empty + // There is no Meredith returned because his description is empty. ); $this->assertIdenticalResultset($view, $resultset, $this->column_map); } @@ -419,7 +419,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringEnds() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'description' => array( 'id' => 'description', @@ -447,7 +447,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Descriptino, Operator: ends, Value: Beatles + // Filter: Descriptino, Operator: ends, Value: Beatles. $filters['description']['group_info']['default_group'] = 4; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); @@ -468,7 +468,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringNotEnds() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'description' => array( 'id' => 'description', @@ -488,7 +488,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { array( 'name' => 'Paul', ), - // There is no Meredith returned because his description is empty + // There is no Meredith returned because his description is empty. ); $this->assertIdenticalResultset($view, $resultset, $this->column_map); } @@ -497,7 +497,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Description, Operator: not_ends, Value: Beatles + // Filter: Description, Operator: not_ends, Value: Beatles. $filters['description']['group_info']['default_group'] = 5; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); @@ -511,7 +511,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { array( 'name' => 'Paul', ), - // There is no Meredith returned because his description is empty + // There is no Meredith returned because his description is empty. ); $this->assertIdenticalResultset($view, $resultset, $this->column_map); } @@ -519,7 +519,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringNot() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'description' => array( 'id' => 'description', @@ -539,7 +539,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { array( 'name' => 'Paul', ), - // There is no Meredith returned because his description is empty + // There is no Meredith returned because his description is empty. ); $this->assertIdenticalResultset($view, $resultset, $this->column_map); } @@ -549,7 +549,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Description, Operator: not (does not contains), Value: Beatles + // Filter: Description, Operator: not (does not contains), Value: Beatles. $filters['description']['group_info']['default_group'] = 6; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); @@ -563,7 +563,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { array( 'name' => 'Paul', ), - // There is no Meredith returned because his description is empty + // There is no Meredith returned because his description is empty. ); $this->assertIdenticalResultset($view, $resultset, $this->column_map); @@ -572,7 +572,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringShorter() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'name' => array( 'id' => 'name', @@ -620,7 +620,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringLonger() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'name' => array( 'id' => 'name', @@ -663,7 +663,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { function testFilterStringEmpty() { $view = $this->getBasicView(); - // Change the filtering + // Change the filtering. $view->display['default']->handler->override_option('filters', array( 'description' => array( 'id' => 'description', @@ -687,7 +687,7 @@ class ViewsHandlerFilterStringTest extends ViewsSqlTest { $filters = $this->getGroupedExposedFilters(); $view = $this->getBasicPageView(); - // Filter: Description, Operator: empty, Value: + // Filter: Description, Operator: empty, Value. $filters['description']['group_info']['default_group'] = 7; $view->set_display('page_1'); $view->display['page_1']->handler->override_option('filters', $filters); diff --git a/sites/all/modules/views/tests/handlers/views_handler_manytoone.test b/sites/all/modules/views/tests/handlers/views_handler_manytoone.test new file mode 100644 index 0000000..fb06645 --- /dev/null +++ b/sites/all/modules/views/tests/handlers/views_handler_manytoone.test @@ -0,0 +1,1099 @@ + 'Handler: Many To One Helper', + 'description' => 'Tests the many to one helper handler', + 'group' => 'Views Handlers', + ); + } + + /** + * Clears views data cache. + */ + protected function clearViewsDataCache() { + drupal_static_reset('_views_fetch_data_cache'); + drupal_static_reset('_views_fetch_data_recursion_protected'); + drupal_static_reset('_views_fetch_data_fully_loaded'); + } + + /** + * Returns a new term with random properties. + * + * @param string $vocabulary + * Vocabulary ID to create term in. + * + * @return object + * Term with random properties. + */ + protected function createTerm($vocabulary) { + $term = new stdClass(); + $term->name = $this->randomName(); + $term->description = $this->randomName(); + // Use the first available text format. + $term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(); + $term->vid = $vocabulary->vid; + taxonomy_term_save($term); + return $term; + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + + // Create boolean field. + $this->fields[0] = array( + 'field_name' => 'field_bool', + 'type' => 'list_boolean', + 'cardinality' => 1, + 'settings' => array( + 'allowed_values' => array( + 0 => '', + 1 => '', + ), + ), + ); + $this->fields[0] = field_create_field($this->fields[0]); + + // Create text list field. + $this->fields[1] = array( + 'field_name' => 'field_list', + 'type' => 'list_text', + 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'settings' => array( + 'allowed_values' => array( + 1 => '1', + 2 => '2', + 3 => '3', + ), + ), + ); + $this->fields[1] = field_create_field($this->fields[1]); + + // Create boolean field instance for article nodes. + $instance = array( + 'field_name' => $this->fields[0]['field_name'], + 'entity_type' => 'node', + 'bundle' => 'article', + 'widget' => array( + 'type' => 'options_onoff', + ), + ); + $this->instances[0][] = field_create_instance($instance); + + // Create text list field instance for article nodes. + $instance = array( + 'field_name' => $this->fields[1]['field_name'], + 'entity_type' => 'node', + 'bundle' => 'article', + 'widget' => array( + 'type' => 'options_buttons', + ), + ); + $this->instances[1][] = field_create_instance($instance); + + // Create boolean field instance for users. + $instance = array( + 'field_name' => $this->fields[0]['field_name'], + 'entity_type' => 'user', + 'bundle' => 'user', + 'widget' => array( + 'type' => 'options_onoff', + ), + ); + $this->instances[0][] = field_create_instance($instance); + + // Create text list field instance for users. + $instance = array( + 'field_name' => $this->fields[1]['field_name'], + 'entity_type' => 'user', + 'bundle' => 'user', + 'widget' => array( + 'type' => 'options_buttons', + ), + ); + $this->instances[1][] = field_create_instance($instance); + + // Create tags field instance for users. + $instance = array( + 'field_name' => 'field_tags', + 'entity_type' => 'user', + 'bundle' => 'user', + ); + $this->instances[2][] = field_create_instance($instance); + + // Clear views data cache. + $this->clearViewsDataCache(); + + // Create 62 tags. + $vocabulary = taxonomy_vocabulary_machine_name_load('tags'); + for ($i = 0; $i < 62; $i++) { + $this->terms[] = $this->createTerm($vocabulary); + } + + // Create a node where the field_bool is checked, field_list is '1' and + // tag is term 2. + $node = array(); + $node['type'] = 'article'; + $node[$this->fields[0]['field_name']][LANGUAGE_NONE][]['value'] = '1'; + $node[$this->fields[1]['field_name']][LANGUAGE_NONE][]['value'] = '1'; + $node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->terms[1]->tid; + $this->nodes[0] = $this->drupalCreateNode($node); + + // Create a node where the field_bool is not checked, field_list is empty + // and tag is term 1. + $node = array(); + $node['type'] = 'article'; + $node[$this->fields[0]['field_name']] = array(); + $node[$this->fields[1]['field_name']] = array(); + $node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->terms[0]->tid; + $this->nodes[1] = $this->drupalCreateNode($node); + + // Create a node where the field_bool is not checked, field_list is empty + // and tag is term 1 and 2. + $node = array(); + $node['type'] = 'article'; + $node[$this->fields[0]['field_name']] = array(); + $node[$this->fields[1]['field_name']] = array(); + $node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->terms[0]->tid; + $node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->terms[1]->tid; + $this->nodes[2] = $this->drupalCreateNode($node); + + // Create a user where field_bool is checked, field_list is '1' and tag is + // term 1. + $permissions = array('access content'); + $account = $this->drupalCreateUser($permissions); + $account->{$this->fields[0]['field_name']}[LANGUAGE_NONE][]['value'] = '1'; + $account->{$this->fields[1]['field_name']}[LANGUAGE_NONE][]['value'] = '1'; + $account->field_tags[LANGUAGE_NONE][]['tid'] = $this->terms[0]->tid; + $this->accounts[0] = user_save($account); + } + + /** + * Tests "none of" filter with terms in excess of JOIN limit selected. + */ + public function testJoinLimitNoneOf() { + $view = $this->getJoinLimitNoneOfTestView(); + $this->executeView($view); + + // Assert that nodes have been created and have expected field values. + $value = field_get_items('node', $this->nodes[0], 'field_tags', LANGUAGE_NONE); + $value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0; + $this->assertIdentical($value, 2, 'First node has been created and tags field references term 2.'); + + $value = field_get_items('node', $this->nodes[1], 'field_tags', LANGUAGE_NONE); + $value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0; + $this->assertIdentical($value, 1, 'Second node has been created and tags field references term 1.'); + + // Assert that user has been created and has expected field values. + $value = field_get_items('user', $this->accounts[0], 'field_tags', LANGUAGE_NONE); + $value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0; + $this->assertIdentical($value, 1, 'User has been created and tags field references term 1.'); + + // Assert that node id with empty field value matches user id so that the + // node would be excluded from the result, if the joins are missing extras. + $this->assertIdentical((int) $this->accounts[0]->uid, (int) $this->nodes[1]->nid, 'Node id of second node matches uid of first user.'); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 1, 'View has one result.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $this->assertIdentical($nid, (int) $this->nodes[1]->nid, 'View result has correct node id.'); + } + + /** + * Tests duplicate grouped "none of" filters on boolean field. + */ + public function testGroupedNoneOf() { + $view = $this->getGroupedNoneOfTestView(); + $this->executeView($view); + + // Assert that nodes have been created and have expected field values. + $value = field_get_items('node', $this->nodes[0], $this->fields[0]['field_name'], LANGUAGE_NONE); + $value = isset($value[0]['value']) ? (int) $value[0]['value'] : 0; + $this->assertIdentical($value, 1, 'First node has been created and boolean field is checked.'); + + $value = field_get_items('node', $this->nodes[1], $this->fields[0]['field_name'], LANGUAGE_NONE); + $this->assertFalse($value, 'Second node has been created and boolean field is not checked.'); + + $value = field_get_items('node', $this->nodes[2], $this->fields[0]['field_name'], LANGUAGE_NONE); + $this->assertFalse($value, 'Third node has been created and boolean field is not checked.'); + + // Assert that user has been created and has expected field values. + $value = field_get_items('user', $this->accounts[0], $this->fields[0]['field_name'], LANGUAGE_NONE); + $value = isset($value[0]['value']) ? (int) $value[0]['value'] : 0; + $this->assertIdentical($value, 1, 'User has been created and boolean field is checked.'); + + // Assert that node ID with empty field value matches user ID so that the + // node would be excluded from the result, if the joins are missing extras. + $this->assertIdentical((int) $this->accounts[0]->uid, (int) $this->nodes[1]->nid, 'Node ID of second node matches UID of first user.'); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 2, 'View has two results.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $result1 = ($nid === (int) $this->nodes[1]->nid); + $nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0; + $result2 = ($nid === (int) $this->nodes[2]->nid); + $this->assertTrue($result1 && $result2, 'View result has correct node IDs.'); + } + + /** + * Tests duplicate grouped "one of" filters on taxonomy term field. + */ + public function testGroupedOneOf() { + $view = $this->getGroupedOneOfTestView(); + $this->executeView($view); + + // Assert that nodes have been created and have expected field values. + $value = field_get_items('node', $this->nodes[0], 'field_tags', LANGUAGE_NONE); + $value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0; + $this->assertIdentical($value, 2, 'First node has been created and tags field references term 2.'); + + $value = field_get_items('node', $this->nodes[1], 'field_tags', LANGUAGE_NONE); + $value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0; + $this->assertIdentical($value, 1, 'Second node has been created and tags field references term 1.'); + + $value = field_get_items('node', $this->nodes[2], 'field_tags', LANGUAGE_NONE); + $value = !empty($value[0]['tid']) && !empty($value[1]['tid']); + $this->assertTrue($value, 'Third node has been created and tags field references both terms 1 and 2.'); + + // Assert that user has been created and has expected field values. + $value = field_get_items('user', $this->accounts[0], 'field_tags', LANGUAGE_NONE); + $value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0; + $this->assertIdentical($value, 1, 'User has been created and tags field references term 1.'); + + // Assert that node ID with empty field value matches user ID so that the + // node would be excluded from the result, if the joins are missing extras. + $this->assertIdentical((int) $this->accounts[0]->uid, (int) $this->nodes[1]->nid, 'Node ID of second node matches UID of first user.'); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 2, 'View has two results.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $result1 = ($nid === (int) $this->nodes[1]->nid); + $nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0; + $result2 = ($nid === (int) $this->nodes[2]->nid); + $this->assertTrue($result1 && $result2, 'View result has correct node IDs.'); + } + + /** + * Tests exposed filter with "Reduce duplicates." and grouped options. + */ + public function testReducedExposedGroupedOptions() { + // Assert that nodes have been created and have expected field values. + $value = field_get_items('node', $this->nodes[0], 'field_list', LANGUAGE_NONE); + $value = isset($value[0]['value']) ? (int) $value[0]['value'] : 0; + $this->assertIdentical($value, 1, 'First node has been created and list field has value 1.'); + + $value = field_get_items('node', $this->nodes[1], 'field_list', LANGUAGE_NONE); + $this->assertFalse($value, 'Second node has been created and list field is empty.'); + + $value = field_get_items('node', $this->nodes[2], 'field_list', LANGUAGE_NONE); + $this->assertFalse($value, 'Third node has been created and list field is empty.'); + + // Assert that user has been created and has expected field values. + $value = field_get_items('user', $this->accounts[0], 'field_list', LANGUAGE_NONE); + $value = isset($value[0]['value']) ? (int) $value[0]['value'] : 0; + $this->assertIdentical($value, 1, 'User has been created and list field has value 1.'); + + // Assert that node ID with empty field value matches user ID so that the + // node would be excluded from the result option 1, if the joins are missing + // extras. + $this->assertIdentical((int) $this->accounts[0]->uid, (int) $this->nodes[1]->nid, 'Node ID of second node matches UID of first user.'); + + // Default option: Any. + $view = $this->getReducedExposedGroupedOptionsTestView(); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 3, 'Default option: View has three results.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $result1 = ($nid === (int) $this->nodes[0]->nid); + $nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0; + $result2 = ($nid === (int) $this->nodes[1]->nid); + $nid = isset($view->result[2]->nid) ? (int) $view->result[2]->nid : 0; + $result3 = ($nid === (int) $this->nodes[2]->nid); + $this->assertTrue($result1 && $result2 && $result3, 'Default option: View result has correct node ID.'); + + // Option 1: Is none of 1 or 2. + $view = $this->getReducedExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_list_value' => '1', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 2, 'Option 1: View has two results.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $result1 = ($nid === (int) $this->nodes[1]->nid); + $nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0; + $result2 = ($nid === (int) $this->nodes[2]->nid); + $this->assertTrue($result1 && $result2, 'Option 1: View result has correct node ID.'); + + // Option 2: Is one of 1. + $view = $this->getReducedExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_list_value' => '2', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 1, 'Option 2: View has one result.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $this->assertIdentical($nid, (int) $this->nodes[0]->nid, 'Option 2: View result has correct node ID.'); + + // Option 3: Is one of 1 or 2. + $view = $this->getReducedExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_list_value' => '3', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 1, 'Option 3: View has one result.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $this->assertIdentical($nid, (int) $this->nodes[0]->nid, 'Option 3: View result has correct node ID.'); + + /* @todo: Fix and uncomment in issue #3045168. + * // Option 4: Is all of 1 and 2. + * $view = $this->getReducedExposedGroupedOptionsTestView(); + * $view->set_exposed_input(array( + * 'field_list_value' => '4', + * )); + * $this->executeView($view); + * + * // Assert correct result set. + * $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 1; + * $this->assertEqual($result_count, 0, 'Option 4: View has empty result.'); + */ + + // Option 5: Is empty. + $view = $this->getReducedExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_list_value' => '5', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 2, 'Option 5: View has two results.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $result1 = ($nid === (int) $this->nodes[1]->nid); + $nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0; + $result2 = ($nid === (int) $this->nodes[2]->nid); + $this->assertTrue($result1 && $result2, 'Option 5: View result has correct node IDs.'); + + // Option 6: Is not empty. + $view = $this->getReducedExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_list_value' => '6', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 1, 'Option 6: View has one result.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $this->assertIdentical($nid, (int) $this->nodes[0]->nid, 'Option 6: View result has correct node ID.'); + } + + /** + * Tests exposed filter on term ID with grouped options. + */ + public function testTermIdExposedGroupedOptions() { + // Assert that nodes have been created and have expected field values. + $value = field_get_items('node', $this->nodes[0], 'field_tags', LANGUAGE_NONE); + $value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0; + $this->assertIdentical($value, 2, 'First node has been created and tags field references term 2.'); + + $value = field_get_items('node', $this->nodes[1], 'field_tags', LANGUAGE_NONE); + $value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0; + $this->assertIdentical($value, 1, 'Second node has been created and tags field references term 1.'); + + // Assert that user has been created and has expected field values. + $value = field_get_items('user', $this->accounts[0], 'field_tags', LANGUAGE_NONE); + $value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0; + $this->assertIdentical($value, 1, 'User has been created and tags field references term 1.'); + + // Assert that node ID with empty field value matches user ID so that the + // node would be excluded from the result option 1, if the joins are missing + // extras. + $this->assertIdentical((int) $this->accounts[0]->uid, (int) $this->nodes[1]->nid, 'Node ID of second node matches UID of first user.'); + + // Default option: Any. + $view = $this->getTermIdExposedGroupedOptionsTestView(); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 3, 'Default option: View has three results.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $result1 = ($nid === (int) $this->nodes[0]->nid); + $nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0; + $result2 = ($nid === (int) $this->nodes[1]->nid); + $nid = isset($view->result[2]->nid) ? (int) $view->result[2]->nid : 0; + $result3 = ($nid === (int) $this->nodes[2]->nid); + $this->assertTrue($result1 && $result2 && $result3, 'Default option: View result has correct node ID.'); + + // Option 1: Is none of 2. + $view = $this->getTermIdExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_tags_tid' => '1', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 1, 'Option 1: View has one result.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $this->assertIdentical($nid, (int) $this->nodes[1]->nid, 'Option 1: View result has correct node ID.'); + + // Option 2: Is none of 1 or 2. + $view = $this->getTermIdExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_tags_tid' => '2', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 1; + $this->assertEqual($result_count, 0, 'Option 2: View has empty result.'); + + // Option 3: Is one of 1. + $view = $this->getTermIdExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_tags_tid' => '3', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $this->assertEqual($result_count, 2, 'Option 3: View has two results.'); + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $result1 = ($nid === (int) $this->nodes[1]->nid); + $nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0; + $result2 = ($nid === (int) $this->nodes[2]->nid); + $this->assertTrue($result1 && $result2, 'Option 3: View result has correct node ID.'); + + // Option 4: Is one of 1 or 2. + $view = $this->getTermIdExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_tags_tid' => '4', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $result1 = ($nid === (int) $this->nodes[0]->nid); + $nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0; + $result2 = ($nid === (int) $this->nodes[1]->nid); + $nid = isset($view->result[2]->nid) ? (int) $view->result[2]->nid : 0; + $result3 = ($nid === (int) $this->nodes[2]->nid); + $nid = isset($view->result[3]->nid) ? (int) $view->result[3]->nid : 0; + $result4 = ($nid === (int) $this->nodes[2]->nid); + $this->assertTrue($result1 && $result2 && $result3 && $result4, 'Option 4: View result has correct node ID.'); + $this->verbose($view->result); + $this->assertEqual($result_count, 4, 'Option 4: View has four results.'); + + /* @todo: Fix and uncomment in issue #3045168. + * // Option 5: Is all of 1 and 2. + * $view = $this->getTermIdExposedGroupedOptionsTestView(); + * $view->set_exposed_input(array( + * 'field_tags_tid' => '5', + * )); + * $this->executeView($view); + * + * // Assert correct result set. + * $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + * $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + * $this->assertIdentical($nid, (int) $this->nodes[2]->nid, 'Option 5: View result has correct node ID.'); + * $this->assertIdentical($result_count, 1, 'Option 5: View has one result.'); + */ + + // Option 6: Is empty. + $view = $this->getTermIdExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_tags_tid' => '6', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 1; + $this->assertIdentical($result_count, 0, 'Option 6: View has empty result.'); + + // Option 7: Is not empty. + $view = $this->getTermIdExposedGroupedOptionsTestView(); + $view->set_exposed_input(array( + 'field_tags_tid' => '7', + )); + $this->executeView($view); + + // Assert correct result set. + $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0; + $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0; + $result1 = ($nid === (int) $this->nodes[0]->nid); + $nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0; + $result2 = ($nid === (int) $this->nodes[1]->nid); + $nid = isset($view->result[2]->nid) ? (int) $view->result[2]->nid : 0; + $result3 = ($nid === (int) $this->nodes[2]->nid); + $nid = isset($view->result[3]->nid) ? (int) $view->result[3]->nid : 0; + $result4 = ($nid === (int) $this->nodes[2]->nid); + $this->assertTrue($result1 && $result2 && $result3 && $result4, 'Option 7: View result has correct node ID.'); + $this->verbose($view->result); + $this->assertIdentical($result_count, 4, 'Option 7: View has four results.'); + } + + /** + * Generates test_not view. + */ + protected function getGroupedNoneOfTestView() { + $view = new view(); + $view->name = 'test_not'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->human_name = 'test_not'; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'perm'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'fields'; + /* Field: Content: Title */ + $handler->display->display_options['fields']['title']['id'] = 'title'; + $handler->display->display_options['fields']['title']['table'] = 'node'; + $handler->display->display_options['fields']['title']['field'] = 'title'; + $handler->display->display_options['fields']['title']['label'] = ''; + $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; + $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; + /* Sort criterion: Content: Nid */ + $handler->display->display_options['sorts']['nid']['id'] = 'nid'; + $handler->display->display_options['sorts']['nid']['table'] = 'node'; + $handler->display->display_options['sorts']['nid']['field'] = 'nid'; + $handler->display->display_options['filter_groups']['operator'] = 'OR'; + $handler->display->display_options['filter_groups']['groups'] = array( + 1 => 'AND', + 2 => 'AND', + ); + /* Filter criterion: Content: Published */ + $handler->display->display_options['filters']['status']['id'] = 'status'; + $handler->display->display_options['filters']['status']['table'] = 'node'; + $handler->display->display_options['filters']['status']['field'] = 'status'; + $handler->display->display_options['filters']['status']['value'] = 1; + $handler->display->display_options['filters']['status']['group'] = 1; + $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE; + /* Filter criterion: Content: Type */ + $handler->display->display_options['filters']['type']['id'] = 'type'; + $handler->display->display_options['filters']['type']['table'] = 'node'; + $handler->display->display_options['filters']['type']['field'] = 'type'; + $handler->display->display_options['filters']['type']['value'] = array( + 'article' => 'article', + ); + $handler->display->display_options['filters']['type']['group'] = 1; + /* Filter criterion: Field: field_bool (field_bool) */ + $handler->display->display_options['filters']['field_bool_value']['id'] = 'field_bool_value'; + $handler->display->display_options['filters']['field_bool_value']['table'] = 'field_data_field_bool'; + $handler->display->display_options['filters']['field_bool_value']['field'] = 'field_bool_value'; + $handler->display->display_options['filters']['field_bool_value']['operator'] = 'not'; + $handler->display->display_options['filters']['field_bool_value']['value'] = array( + 1 => '1', + ); + $handler->display->display_options['filters']['field_bool_value']['group'] = 1; + /* Filter criterion: Field: field_bool (field_bool) */ + $handler->display->display_options['filters']['field_bool_value_1']['id'] = 'field_bool_value_1'; + $handler->display->display_options['filters']['field_bool_value_1']['table'] = 'field_data_field_bool'; + $handler->display->display_options['filters']['field_bool_value_1']['field'] = 'field_bool_value'; + $handler->display->display_options['filters']['field_bool_value_1']['operator'] = 'not'; + $handler->display->display_options['filters']['field_bool_value_1']['value'] = array( + 1 => '1', + ); + $handler->display->display_options['filters']['field_bool_value_1']['group'] = 2; + /* Filter criterion: Content: Type */ + $handler->display->display_options['filters']['type_1']['id'] = 'type_1'; + $handler->display->display_options['filters']['type_1']['table'] = 'node'; + $handler->display->display_options['filters']['type_1']['field'] = 'type'; + $handler->display->display_options['filters']['type_1']['value'] = array( + 'article' => 'article', + ); + $handler->display->display_options['filters']['type_1']['group'] = 2; + /* Filter criterion: Content: Published */ + $handler->display->display_options['filters']['status_1']['id'] = 'status_1'; + $handler->display->display_options['filters']['status_1']['table'] = 'node'; + $handler->display->display_options['filters']['status_1']['field'] = 'status'; + $handler->display->display_options['filters']['status_1']['value'] = '1'; + $handler->display->display_options['filters']['status_1']['group'] = 2; + + return $view; + } + + /** + * Generates test_oneof view. + */ + protected function getGroupedOneOfTestView() { + $view = new view(); + $view->name = 'test_oneof'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->human_name = 'test_oneof'; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'perm'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'fields'; + /* Field: Content: Title */ + $handler->display->display_options['fields']['title']['id'] = 'title'; + $handler->display->display_options['fields']['title']['table'] = 'node'; + $handler->display->display_options['fields']['title']['field'] = 'title'; + $handler->display->display_options['fields']['title']['label'] = ''; + $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; + $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; + /* Sort criterion: Content: Nid */ + $handler->display->display_options['sorts']['nid']['id'] = 'nid'; + $handler->display->display_options['sorts']['nid']['table'] = 'node'; + $handler->display->display_options['sorts']['nid']['field'] = 'nid'; + $handler->display->display_options['filter_groups']['operator'] = 'OR'; + $handler->display->display_options['filter_groups']['groups'] = array( + 1 => 'AND', + 2 => 'AND', + ); + /* Filter criterion: Content: Tags (field_tags) */ + $handler->display->display_options['filters']['field_tags_tid']['id'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['table'] = 'field_data_field_tags'; + $handler->display->display_options['filters']['field_tags_tid']['field'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['value'] = array( + 1 => '1', + ); + $handler->display->display_options['filters']['field_tags_tid']['group'] = 2; + $handler->display->display_options['filters']['field_tags_tid']['reduce_duplicates'] = TRUE; + $handler->display->display_options['filters']['field_tags_tid']['type'] = 'select'; + $handler->display->display_options['filters']['field_tags_tid']['vocabulary'] = 'tags'; + /* Filter criterion: Content: Tags (field_tags) */ + $handler->display->display_options['filters']['field_tags_tid_1']['id'] = 'field_tags_tid_1'; + $handler->display->display_options['filters']['field_tags_tid_1']['table'] = 'field_data_field_tags'; + $handler->display->display_options['filters']['field_tags_tid_1']['field'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid_1']['value'] = array( + 1 => '1', + ); + $handler->display->display_options['filters']['field_tags_tid_1']['reduce_duplicates'] = TRUE; + $handler->display->display_options['filters']['field_tags_tid_1']['type'] = 'select'; + $handler->display->display_options['filters']['field_tags_tid_1']['vocabulary'] = 'tags'; + return $view; + } + + /** + * Generates test_reduced_exposed_grouped_options view. + */ + protected function getReducedExposedGroupedOptionsTestView() { + $view = new view(); + $view->name = 'test_reduced_exposed_grouped_options'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->human_name = 'test_reduced_exposed_grouped_options'; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'perm'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'fields'; + /* Field: Content: Title */ + $handler->display->display_options['fields']['title']['id'] = 'title'; + $handler->display->display_options['fields']['title']['table'] = 'node'; + $handler->display->display_options['fields']['title']['field'] = 'title'; + $handler->display->display_options['fields']['title']['label'] = ''; + $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; + $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; + /* Sort criterion: Content: Nid */ + $handler->display->display_options['sorts']['nid']['id'] = 'nid'; + $handler->display->display_options['sorts']['nid']['table'] = 'node'; + $handler->display->display_options['sorts']['nid']['field'] = 'nid'; + /* Filter criterion: Content: Published */ + $handler->display->display_options['filters']['status']['id'] = 'status'; + $handler->display->display_options['filters']['status']['table'] = 'node'; + $handler->display->display_options['filters']['status']['field'] = 'status'; + $handler->display->display_options['filters']['status']['value'] = 1; + $handler->display->display_options['filters']['status']['group'] = 1; + $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE; + /* Filter criterion: Content: list (field_list) */ + $handler->display->display_options['filters']['field_list_value']['id'] = 'field_list_value'; + $handler->display->display_options['filters']['field_list_value']['table'] = 'field_data_field_list'; + $handler->display->display_options['filters']['field_list_value']['field'] = 'field_list_value'; + $handler->display->display_options['filters']['field_list_value']['exposed'] = TRUE; + $handler->display->display_options['filters']['field_list_value']['expose']['operator_id'] = 'field_list_value_op'; + $handler->display->display_options['filters']['field_list_value']['expose']['label'] = 'list (field_list)'; + $handler->display->display_options['filters']['field_list_value']['expose']['operator'] = 'field_list_value_op'; + $handler->display->display_options['filters']['field_list_value']['expose']['identifier'] = 'field_list_value'; + $handler->display->display_options['filters']['field_list_value']['is_grouped'] = TRUE; + $handler->display->display_options['filters']['field_list_value']['group_info']['label'] = 'list (field_list)'; + $handler->display->display_options['filters']['field_list_value']['group_info']['identifier'] = 'field_list_value'; + $handler->display->display_options['filters']['field_list_value']['group_info']['group_items'] = array( + 1 => array( + 'title' => 'Not 1 or 2', + 'operator' => 'not', + 'value' => array( + 1 => '1', + 2 => '2', + ), + ), + 2 => array( + 'title' => '1', + 'operator' => 'or', + 'value' => array( + 1 => '1', + ), + ), + 3 => array( + 'title' => '1 or 2', + 'operator' => 'or', + 'value' => array( + 1 => '1', + 2 => '2', + ), + ), + 4 => array( + 'title' => '1 and 2', + 'operator' => 'and', + 'value' => array( + 1 => '1', + 2 => '2', + ), + ), + 5 => array( + 'title' => 'empty', + 'operator' => 'empty', + 'value' => array(), + ), + 6 => array( + 'title' => 'not empty', + 'operator' => 'not empty', + 'value' => array(), + ), + ); + return $view; + } + + /** + * Generates test_tid_exposed_grouped_options view. + */ + protected function getTermIdExposedGroupedOptionsTestView() { + $view = new view(); + $view->name = 'test_tid_exposed_grouped_options'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->human_name = 'test_tid_exposed_grouped_options'; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'perm'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'fields'; + /* Field: Content: Title */ + $handler->display->display_options['fields']['title']['id'] = 'title'; + $handler->display->display_options['fields']['title']['table'] = 'node'; + $handler->display->display_options['fields']['title']['field'] = 'title'; + $handler->display->display_options['fields']['title']['label'] = ''; + $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; + $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; + /* Sort criterion: Content: Nid */ + $handler->display->display_options['sorts']['nid']['id'] = 'nid'; + $handler->display->display_options['sorts']['nid']['table'] = 'node'; + $handler->display->display_options['sorts']['nid']['field'] = 'nid'; + /* Filter criterion: Content: Published */ + $handler->display->display_options['filters']['status']['id'] = 'status'; + $handler->display->display_options['filters']['status']['table'] = 'node'; + $handler->display->display_options['filters']['status']['field'] = 'status'; + $handler->display->display_options['filters']['status']['value'] = 1; + $handler->display->display_options['filters']['status']['group'] = 1; + $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE; + /* Filter criterion: Content: Tags (field_tags) */ + $handler->display->display_options['filters']['field_tags_tid']['id'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['table'] = 'field_data_field_tags'; + $handler->display->display_options['filters']['field_tags_tid']['field'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['value'] = array( + 1 => '1', + 2 => '2', + ); + $handler->display->display_options['filters']['field_tags_tid']['exposed'] = TRUE; + $handler->display->display_options['filters']['field_tags_tid']['expose']['operator_id'] = 'field_tags_tid_op'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['label'] = 'Tags (field_tags)'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['operator'] = 'field_tags_tid_op'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['identifier'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['remember_roles'] = array( + 2 => '2', + ); + $handler->display->display_options['filters']['field_tags_tid']['is_grouped'] = TRUE; + $handler->display->display_options['filters']['field_tags_tid']['group_info']['label'] = 'Tags (field_tags)'; + $handler->display->display_options['filters']['field_tags_tid']['group_info']['identifier'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['group_info']['group_items'] = array( + 1 => array( + 'title' => 'Is none of 2', + 'operator' => 'not', + 'value' => array( + 2 => '2', + ), + ), + 2 => array( + 'title' => 'Is none of 1 or 2', + 'operator' => 'not', + 'value' => array( + 1 => '1', + 2 => '2', + ), + ), + 3 => array( + 'title' => 'Is one of 1', + 'operator' => 'or', + 'value' => array( + 1 => '1', + ), + ), + 4 => array( + 'title' => 'Is one of 1 or 2', + 'operator' => 'or', + 'value' => array( + 1 => '1', + 2 => '2', + ), + ), + 5 => array( + 'title' => 'Is all of 1 and 2', + 'operator' => 'and', + 'value' => array( + 1 => '1', + 2 => '2', + ), + ), + 6 => array( + 'title' => 'Is empty', + 'operator' => 'empty', + 'value' => array( + 1 => '1', + 2 => '2', + ), + ), + 7 => array( + 'title' => 'Is not empty', + 'operator' => 'not empty', + 'value' => array( + 1 => '1', + 2 => '2', + ), + ), + ); + $handler->display->display_options['filters']['field_tags_tid']['type'] = 'select'; + $handler->display->display_options['filters']['field_tags_tid']['vocabulary'] = 'tags'; + return $view; + } + + /** + * Generates test_join_limit_none_of view. + */ + protected function getJoinLimitNoneOfTestView() { + $view = new view(); + $view->name = 'test_join_limit_none_of'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->human_name = 'test_join_limit_none_of'; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'perm'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'fields'; + /* Field: Content: Title */ + $handler->display->display_options['fields']['title']['id'] = 'title'; + $handler->display->display_options['fields']['title']['table'] = 'node'; + $handler->display->display_options['fields']['title']['field'] = 'title'; + $handler->display->display_options['fields']['title']['label'] = ''; + $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; + $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; + /* Sort criterion: Content: Post date */ + $handler->display->display_options['sorts']['created']['id'] = 'created'; + $handler->display->display_options['sorts']['created']['table'] = 'node'; + $handler->display->display_options['sorts']['created']['field'] = 'created'; + $handler->display->display_options['sorts']['created']['order'] = 'DESC'; + /* Filter criterion: Content: Published */ + $handler->display->display_options['filters']['status']['id'] = 'status'; + $handler->display->display_options['filters']['status']['table'] = 'node'; + $handler->display->display_options['filters']['status']['field'] = 'status'; + $handler->display->display_options['filters']['status']['value'] = 1; + $handler->display->display_options['filters']['status']['group'] = 1; + $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE; + /* Filter criterion: Content: Tags (field_tags) */ + $handler->display->display_options['filters']['field_tags_tid']['id'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['table'] = 'field_data_field_tags'; + $handler->display->display_options['filters']['field_tags_tid']['field'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['operator'] = 'not'; + $handler->display->display_options['filters']['field_tags_tid']['value'] = array( + 2 => '2', + 3 => '3', + 4 => '4', + 5 => '5', + 6 => '6', + 7 => '7', + 8 => '8', + 9 => '9', + 10 => '10', + 11 => '11', + 12 => '12', + 13 => '13', + 14 => '14', + 15 => '15', + 16 => '16', + 17 => '17', + 18 => '18', + 19 => '19', + 20 => '20', + 21 => '21', + 22 => '22', + 23 => '23', + 24 => '24', + 25 => '25', + 26 => '26', + 27 => '27', + 28 => '28', + 29 => '29', + 30 => '30', + 31 => '31', + 32 => '32', + 33 => '33', + 34 => '34', + 35 => '35', + 36 => '36', + 37 => '37', + 38 => '38', + 39 => '39', + 40 => '40', + 41 => '41', + 42 => '42', + 43 => '43', + 44 => '44', + 45 => '45', + 46 => '46', + 47 => '47', + 48 => '48', + 49 => '49', + 50 => '50', + 51 => '51', + 52 => '52', + 53 => '53', + 54 => '54', + 55 => '55', + 56 => '56', + 57 => '57', + 58 => '58', + 59 => '59', + 60 => '60', + 61 => '61', + 62 => '62', + 63 => '63', + 64 => '64', + 65 => '65', + 66 => '66', + 67 => '67', + 68 => '68', + 69 => '69', + 61 => '61', + 62 => '62', + ); + $handler->display->display_options['filters']['field_tags_tid']['type'] = 'select'; + $handler->display->display_options['filters']['field_tags_tid']['vocabulary'] = 'tags'; + return $view; + } + +} diff --git a/sites/all/modules/views/tests/handlers/views_handler_sort.test b/sites/all/modules/views/tests/handlers/views_handler_sort.test index 70f2aac..35708c1 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_sort.test +++ b/sites/all/modules/views/tests/handlers/views_handler_sort.test @@ -23,7 +23,7 @@ class ViewsHandlerSortTest extends ViewsSqlTest { public function testNumericOrdering() { $view = $this->getBasicView(); - // Change the ordering + // Change the ordering. $view->display['default']->handler->override_option('sorts', array( 'age' => array( 'order' => 'ASC', @@ -46,7 +46,7 @@ class ViewsHandlerSortTest extends ViewsSqlTest { $view = $this->getBasicView(); - // Reverse the ordering + // Reverse the ordering. $view->display['default']->handler->override_option('sorts', array( 'age' => array( 'order' => 'DESC', @@ -74,7 +74,7 @@ class ViewsHandlerSortTest extends ViewsSqlTest { public function testStringOrdering() { $view = $this->getBasicView(); - // Change the ordering + // Change the ordering. $view->display['default']->handler->override_option('sorts', array( 'name' => array( 'order' => 'ASC', @@ -97,7 +97,7 @@ class ViewsHandlerSortTest extends ViewsSqlTest { $view = $this->getBasicView(); - // Reverse the ordering + // Reverse the ordering. $view->display['default']->handler->override_option('sorts', array( 'name' => array( 'order' => 'DESC', @@ -118,4 +118,5 @@ class ViewsHandlerSortTest extends ViewsSqlTest { 'views_test_age' => 'age', )); } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_sort_date.test b/sites/all/modules/views/tests/handlers/views_handler_sort_date.test index 65a94e8..4a8c4ca 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_sort_date.test +++ b/sites/all/modules/views/tests/handlers/views_handler_sort_date.test @@ -21,61 +21,66 @@ class ViewsHandlerSortDateTest extends ViewsSqlTest { $expected = array(); if (!$reverse) { switch ($granularity) { - case 'second': - $expected = array( - array('name' => 'John'), - array('name' => 'Paul'), - array('name' => 'Meredith'), - array('name' => 'Ringo'), - array('name' => 'George'), - ); - break; - case 'minute': - $expected = array( - array('name' => 'John'), - array('name' => 'Paul'), - array('name' => 'Ringo'), - array('name' => 'Meredith'), - array('name' => 'George'), - ); - break; - case 'hour': - $expected = array( - array('name' => 'John'), - array('name' => 'Ringo'), - array('name' => 'Paul'), - array('name' => 'Meredith'), - array('name' => 'George'), - ); - break; - case 'day': - $expected = array( - array('name' => 'John'), - array('name' => 'Ringo'), - array('name' => 'Paul'), - array('name' => 'Meredith'), - array('name' => 'George'), - ); - break; - case 'month': - $expected = array( - array('name' => 'John'), - array('name' => 'George'), - array('name' => 'Ringo'), - array('name' => 'Paul'), - array('name' => 'Meredith'), - ); - break; - case 'year': - $expected = array( - array('name' => 'John'), - array('name' => 'George'), - array('name' => 'Ringo'), - array('name' => 'Paul'), - array('name' => 'Meredith'), - ); - break; - } + case 'second': + $expected = array( + array('name' => 'John'), + array('name' => 'Paul'), + array('name' => 'Meredith'), + array('name' => 'Ringo'), + array('name' => 'George'), + ); + break; + + case 'minute': + $expected = array( + array('name' => 'John'), + array('name' => 'Paul'), + array('name' => 'Ringo'), + array('name' => 'Meredith'), + array('name' => 'George'), + ); + break; + + case 'hour': + $expected = array( + array('name' => 'John'), + array('name' => 'Ringo'), + array('name' => 'Paul'), + array('name' => 'Meredith'), + array('name' => 'George'), + ); + break; + + case 'day': + $expected = array( + array('name' => 'John'), + array('name' => 'Ringo'), + array('name' => 'Paul'), + array('name' => 'Meredith'), + array('name' => 'George'), + ); + break; + + case 'month': + $expected = array( + array('name' => 'John'), + array('name' => 'George'), + array('name' => 'Ringo'), + array('name' => 'Paul'), + array('name' => 'Meredith'), + ); + break; + + case 'year': + $expected = array( + array('name' => 'John'), + array('name' => 'George'), + array('name' => 'Ringo'), + array('name' => 'Paul'), + array('name' => 'Meredith'), + ); + break; + } } else { switch ($granularity) { @@ -88,6 +93,7 @@ class ViewsHandlerSortDateTest extends ViewsSqlTest { array('name' => 'John'), ); break; + case 'minute': $expected = array( array('name' => 'George'), @@ -95,8 +101,9 @@ class ViewsHandlerSortDateTest extends ViewsSqlTest { array('name' => 'Meredith'), array('name' => 'Paul'), array('name' => 'John'), - ); + ); break; + case 'hour': $expected = array( array('name' => 'George'), @@ -106,6 +113,7 @@ class ViewsHandlerSortDateTest extends ViewsSqlTest { array('name' => 'John'), ); break; + case 'day': $expected = array( array('name' => 'George'), @@ -115,6 +123,7 @@ class ViewsHandlerSortDateTest extends ViewsSqlTest { array('name' => 'Meredith'), ); break; + case 'month': $expected = array( array('name' => 'John'), @@ -124,6 +133,7 @@ class ViewsHandlerSortDateTest extends ViewsSqlTest { array('name' => 'Meredith'), ); break; + case 'year': $expected = array( array('name' => 'John'), @@ -163,7 +173,7 @@ class ViewsHandlerSortDateTest extends ViewsSqlTest { ), )); - // Change the ordering + // Change the ordering. $view->display['default']->handler->override_option('sorts', array( 'created' => array( 'id' => 'created', @@ -195,4 +205,5 @@ class ViewsHandlerSortDateTest extends ViewsSqlTest { } } } + } diff --git a/sites/all/modules/views/tests/handlers/views_handler_sort_random.test b/sites/all/modules/views/tests/handlers/views_handler_sort_random.test index 19db8a9..b7a620d 100644 --- a/sites/all/modules/views/tests/handlers/views_handler_sort_random.test +++ b/sites/all/modules/views/tests/handlers/views_handler_sort_random.test @@ -9,6 +9,10 @@ * Tests for core views_handler_sort_random handler. */ class ViewsHandlerSortRandomTest extends ViewsSqlTest { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Sort: random', @@ -77,7 +81,8 @@ class ViewsHandlerSortRandomTest extends ViewsSqlTest { 'views_test_age' => 'views_test_name', )); - // Execute a second random view, we expect the result set to be different again. + // Execute a second random view, we expect the result set to be different + // again. $view_random_2 = $this->getBasicRandomView(); $this->executeView($view_random_2); $this->assertEqual(count($this->dataSet()), count($view_random_2->result), t('The number of returned rows match.')); @@ -86,4 +91,5 @@ class ViewsHandlerSortRandomTest extends ViewsSqlTest { 'views_test_age' => 'views_test_name', )); } + } diff --git a/sites/all/modules/views/tests/handlers/views_handlers.test b/sites/all/modules/views/tests/handlers/views_handlers.test index f2faee3..6f010ac 100644 --- a/sites/all/modules/views/tests/handlers/views_handlers.test +++ b/sites/all/modules/views/tests/handlers/views_handlers.test @@ -2,7 +2,7 @@ /** * @file - * Contains ViewsHandlerTest. + * Definition of ViewsHandlerTest. */ /** @@ -42,7 +42,7 @@ class ViewsHandlerTest extends ViewsSqlTest { public function testHandlerAccess() { $view = $this->getBasicView(); - // add a test area + // add a test area. $view->display['default']->handler->override_option('header', array( 'test_access' => array( 'id' => 'test_access', @@ -61,7 +61,7 @@ class ViewsHandlerTest extends ViewsSqlTest { $view = $this->getBasicView(); - // add a test area + // add a test area. $view->display['default']->handler->override_option('header', array( 'test_access' => array( 'id' => 'test_access', diff --git a/sites/all/modules/views/tests/node/views_node_revision_relations.test b/sites/all/modules/views/tests/node/views_node_revision_relations.test index 6b38396..e3a50c0 100644 --- a/sites/all/modules/views/tests/node/views_node_revision_relations.test +++ b/sites/all/modules/views/tests/node/views_node_revision_relations.test @@ -174,4 +174,5 @@ class ViewsNodeRevisionRelationsTestCase extends ViewsSqlTest { return $view; } + } diff --git a/sites/all/modules/views/tests/plugins/views_plugin_display.test b/sites/all/modules/views/tests/plugins/views_plugin_display.test index df33a34..7efb2e7 100644 --- a/sites/all/modules/views/tests/plugins/views_plugin_display.test +++ b/sites/all/modules/views/tests/plugins/views_plugin_display.test @@ -10,6 +10,9 @@ */ class ViewsPluginDisplayTestCase extends ViewsSqlTest { + /** + * + */ public static function getInfo() { return array( 'name' => 'Display plugin', @@ -35,6 +38,7 @@ class ViewsPluginDisplayTestCase extends ViewsSqlTest { * Returns a test view for testFilterGroupsOverriding. * * @see testFilterGroupsOverriding + * * @return view */ function viewFilterGroupsOverriding() { @@ -80,7 +84,9 @@ class ViewsPluginDisplayTestCase extends ViewsSqlTest { } /** - * Based on a bug some filter_groups landed in the overridden display, even the filters weren't overridden. + * Based on a bug some filter_groups landed in the overridden display. + * + * Even the filters weren't overridden. * This caused multiple issues. * Take sure that the value from the default display are used. * @@ -191,4 +197,5 @@ class ViewsPluginDisplayTestCase extends ViewsSqlTest { return $view; } + } diff --git a/sites/all/modules/views/tests/styles/views_plugin_style.test b/sites/all/modules/views/tests/styles/views_plugin_style.test index e915d3b..89d2816 100644 --- a/sites/all/modules/views/tests/styles/views_plugin_style.test +++ b/sites/all/modules/views/tests/styles/views_plugin_style.test @@ -78,6 +78,7 @@ class ViewsPluginStyleTestCase extends ViewsPluginStyleTestBase { $expected = array(); $expected['Job: Singer'] = array(); $expected['Job: Singer']['group'] = 'Job: Singer'; + $expected['Job: Singer']['level'] = '0'; $expected['Job: Singer']['rows'][0] = new StdClass(); $expected['Job: Singer']['rows'][0]->views_test_name = 'John'; $expected['Job: Singer']['rows'][0]->views_test_job = 'Singer'; @@ -88,6 +89,7 @@ class ViewsPluginStyleTestCase extends ViewsPluginStyleTestBase { $expected['Job: Singer']['rows'][1]->views_test_id = '2'; $expected['Job: Drummer'] = array(); $expected['Job: Drummer']['group'] = 'Job: Drummer'; + $expected['Job: Drummer']['level'] = '0'; $expected['Job: Drummer']['rows'][2] = new StdClass(); $expected['Job: Drummer']['rows'][2]->views_test_name = 'Ringo'; $expected['Job: Drummer']['rows'][2]->views_test_job = 'Drummer'; @@ -161,8 +163,10 @@ class ViewsPluginStyleTestCase extends ViewsPluginStyleTestBase { $expected = array(); $expected['Job: Singer'] = array(); $expected['Job: Singer']['group'] = 'Job: Singer'; + $expected['Job: Singer']['level'] = 0; $expected['Job: Singer']['rows']['Age: 25'] = array(); $expected['Job: Singer']['rows']['Age: 25']['group'] = 'Age: 25'; + $expected['Job: Singer']['rows']['Age: 25']['level'] = 1; $expected['Job: Singer']['rows']['Age: 25']['rows'][0] = new StdClass(); $expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_name = 'John'; $expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_job = 'Singer'; @@ -170,6 +174,7 @@ class ViewsPluginStyleTestCase extends ViewsPluginStyleTestBase { $expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_id = '1'; $expected['Job: Singer']['rows']['Age: 27'] = array(); $expected['Job: Singer']['rows']['Age: 27']['group'] = 'Age: 27'; + $expected['Job: Singer']['rows']['Age: 27']['level'] = 1; $expected['Job: Singer']['rows']['Age: 27']['rows'][1] = new StdClass(); $expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_name = 'George'; $expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_job = 'Singer'; @@ -177,15 +182,16 @@ class ViewsPluginStyleTestCase extends ViewsPluginStyleTestBase { $expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_id = '2'; $expected['Job: Drummer'] = array(); $expected['Job: Drummer']['group'] = 'Job: Drummer'; + $expected['Job: Drummer']['level'] = 0; $expected['Job: Drummer']['rows']['Age: 28'] = array(); $expected['Job: Drummer']['rows']['Age: 28']['group'] = 'Age: 28'; + $expected['Job: Drummer']['rows']['Age: 28']['level'] = 1; $expected['Job: Drummer']['rows']['Age: 28']['rows'][2] = new StdClass(); $expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_name = 'Ringo'; $expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_job = 'Drummer'; $expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_age = '28'; $expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_id = '3'; - // Alter the results to support the stripped case. if ($stripped) { @@ -206,7 +212,6 @@ class ViewsPluginStyleTestCase extends ViewsPluginStyleTestBase { $view->style_plugin->options['grouping'][1] = array('field' => 'age', 'rendered' => TRUE, 'rendered_strip' => TRUE); } - // The newer api passes the value of the grouping as well. $sets_new_rendered = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping'], TRUE); @@ -261,4 +266,5 @@ class ViewsPluginStyleTestCase extends ViewsPluginStyleTestBase { $count++; } } + } diff --git a/sites/all/modules/views/tests/styles/views_plugin_style_jump_menu.test b/sites/all/modules/views/tests/styles/views_plugin_style_jump_menu.test index dd4eca0..aadaa56 100644 --- a/sites/all/modules/views/tests/styles/views_plugin_style_jump_menu.test +++ b/sites/all/modules/views/tests/styles/views_plugin_style_jump_menu.test @@ -17,6 +17,9 @@ class viewsPluginStyleJumpMenuTest extends ViewsSqlTest { */ var $nodes; + /** + * + */ public static function getInfo() { return array( 'name' => 'Jump menu', @@ -25,7 +28,9 @@ class viewsPluginStyleJumpMenuTest extends ViewsSqlTest { ); } - + /** + * + */ public function setUp() { parent::setUp(); $this->nodes = array(); @@ -37,7 +42,6 @@ class viewsPluginStyleJumpMenuTest extends ViewsSqlTest { $this->nodeTitles = array($this->nodes['page'][0]->title, $this->nodes['page'][1]->title, $this->nodes['story'][0]->title, $this->nodes['story'][1]->title); } - /** * Tests jump menues with more then one same path but maybe differnet titles. */ @@ -46,7 +50,8 @@ class viewsPluginStyleJumpMenuTest extends ViewsSqlTest { $view->set_display(); $view->init_handlers(); - // Setup a [path] which would leed to "duplicate" paths, but still the shouldn't be used for grouping. + // Setup a [path] which would leed to "duplicate" paths, but still the + // shouldn't be used for grouping. $view->field['nothing']->options['alter']['text'] = '[path]'; $view->preview(); $form = $view->style_plugin->render($view->result); @@ -65,8 +70,11 @@ class viewsPluginStyleJumpMenuTest extends ViewsSqlTest { } } + /** + * + */ function getJumpMenuView() { - $view = new view; + $view = new view(); $view->name = 'test_jump_menu'; $view->description = ''; $view->tag = 'default'; @@ -148,4 +156,5 @@ class viewsPluginStyleJumpMenuTest extends ViewsSqlTest { return $view; } + } diff --git a/sites/all/modules/views/tests/styles/views_plugin_style_mapping.test b/sites/all/modules/views/tests/styles/views_plugin_style_mapping.test index 5785075..c73cb57 100644 --- a/sites/all/modules/views/tests/styles/views_plugin_style_mapping.test +++ b/sites/all/modules/views/tests/styles/views_plugin_style_mapping.test @@ -27,7 +27,7 @@ class ViewsPluginStyleMappingTest extends ViewsPluginStyleTestBase { protected function viewsPlugins() { return array( - 'style' => array( + 'style' => array( 'test_mapping' => array( 'title' => t('Field mapping'), 'help' => t('Maps specific fields to specific purposes.'), diff --git a/sites/all/modules/views/tests/styles/views_plugin_style_unformatted.test b/sites/all/modules/views/tests/styles/views_plugin_style_unformatted.test index 0c0e882..eb5cc99 100644 --- a/sites/all/modules/views/tests/styles/views_plugin_style_unformatted.test +++ b/sites/all/modules/views/tests/styles/views_plugin_style_unformatted.test @@ -42,7 +42,7 @@ class ViewsPluginStyleUnformattedTestCase extends ViewsPluginStyleTestBase { if ($count == 1) { $this->assertTrue(strpos($class, "views-row-first") !== FALSE, 'Take sure that the first class is set right.'); } - else if ($count == $count_result) { + elseif ($count == $count_result) { $this->assertTrue(strpos($class, "views-row-last") !== FALSE, 'Take sure that the last class is set right.'); } diff --git a/sites/all/modules/views/tests/taxonomy/views_handler_relationship_node_term_data.test b/sites/all/modules/views/tests/taxonomy/views_handler_relationship_node_term_data.test index 37e8aa6..7bce980 100644 --- a/sites/all/modules/views/tests/taxonomy/views_handler_relationship_node_term_data.test +++ b/sites/all/modules/views/tests/taxonomy/views_handler_relationship_node_term_data.test @@ -34,9 +34,8 @@ class ViewsHandlerRelationshipNodeTermDataTest extends ViewsSqlTest { function setUp() { parent::setUp(); - //$web_user = $this->drupalCreateUser(array('create article content')); - //$this->drupalLogin($web_user); - + // $web_user = $this->drupalCreateUser(array('create article content')); + // $this->drupalLogin($web_user); $vocabulary = taxonomy_vocabulary_machine_name_load('tags'); $this->term_1 = $this->createTerm($vocabulary); $this->term_2 = $this->createTerm($vocabulary); @@ -119,4 +118,5 @@ class ViewsHandlerRelationshipNodeTermDataTest extends ViewsSqlTest { return $view; } -} \ No newline at end of file + +} diff --git a/sites/all/modules/views/tests/test_handlers/views_test_area_access.inc b/sites/all/modules/views/tests/test_handlers/views_test_area_access.inc index 57a0014..268c675 100644 --- a/sites/all/modules/views/tests/test_handlers/views_test_area_access.inc +++ b/sites/all/modules/views/tests/test_handlers/views_test_area_access.inc @@ -2,22 +2,25 @@ /** * @file - * Contains views_test_area_access + * Definition of views_test_area_access. */ +/** + * A test access plugin. + */ class views_test_area_access extends views_handler_area { /** * {@inheritdoc} */ - function access() { + public function access() { return $this->options['custom_access']; - } + } /** * {@inheritdoc} */ - function option_definition() { + public function option_definition() { $options = parent::option_definition(); $options['custom_access'] = array('default' => TRUE, 'bool' => TRUE); diff --git a/sites/all/modules/views/tests/test_plugins/views_test_plugin_access_test_dynamic.inc b/sites/all/modules/views/tests/test_plugins/views_test_plugin_access_test_dynamic.inc index cecec2f..39f7600 100644 --- a/sites/all/modules/views/tests/test_plugins/views_test_plugin_access_test_dynamic.inc +++ b/sites/all/modules/views/tests/test_plugins/views_test_plugin_access_test_dynamic.inc @@ -9,18 +9,29 @@ * Tests a dynamic access plugin. */ class views_test_plugin_access_test_dynamic extends views_plugin_access { - function option_definition() { + + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['access'] = array('default' => FALSE, 'bool' => TRUE); return $options; } - function access($account) { + /** + * {@inheritdoc} + */ + public function access($account) { return !empty($this->options['access']) && isset($this->view->args[0]) && $this->view->args[0] == variable_get('test_dynamic_access_argument1', NULL) && isset($this->view->args[1]) && $this->view->args[1] == variable_get('test_dynamic_access_argument2', NULL); } - function get_access_callback() { + /** + * {@inheritdoc} + */ + public function get_access_callback() { return array('views_test_test_dynamic_access_callback', array(!empty($options['access']), 1, 2)); } + } diff --git a/sites/all/modules/views/tests/test_plugins/views_test_plugin_access_test_static.inc b/sites/all/modules/views/tests/test_plugins/views_test_plugin_access_test_static.inc index 187d6ea..eb6dde3 100644 --- a/sites/all/modules/views/tests/test_plugins/views_test_plugin_access_test_static.inc +++ b/sites/all/modules/views/tests/test_plugins/views_test_plugin_access_test_static.inc @@ -9,18 +9,29 @@ * Tests a static access plugin. */ class views_test_plugin_access_test_static extends views_plugin_access { - function option_definition() { + + /** + * {@inheritdoc} + */ + public function option_definition() { $options = parent::option_definition(); $options['access'] = array('default' => FALSE, 'bool' => TRUE); return $options; } - function access($account) { + /** + * {@inheritdoc} + */ + public function access($account) { return !empty($this->options['access']); } - function get_access_callback() { + /** + * {@inheritdoc} + */ + public function get_access_callback() { return array('views_test_test_static_access_callback', array(!empty($options['access']))); } + } diff --git a/sites/all/modules/views/tests/test_plugins/views_test_plugin_style_test_mapping.inc b/sites/all/modules/views/tests/test_plugins/views_test_plugin_style_test_mapping.inc index b926787..46d202a 100644 --- a/sites/all/modules/views/tests/test_plugins/views_test_plugin_style_test_mapping.inc +++ b/sites/all/modules/views/tests/test_plugins/views_test_plugin_style_test_mapping.inc @@ -11,7 +11,7 @@ class views_test_plugin_style_test_mapping extends views_plugin_style_mapping { /** - * Overrides views_plugin_style_mapping::define_mapping(). + * {@inheritdoc} */ protected function define_mapping() { return array( @@ -49,4 +49,5 @@ class views_test_plugin_style_test_mapping extends views_plugin_style_mapping { } } } + } diff --git a/sites/all/modules/views/tests/user/views_handler_field_user_name.test b/sites/all/modules/views/tests/user/views_handler_field_user_name.test index 6ace471..73a8ac1 100644 --- a/sites/all/modules/views/tests/user/views_handler_field_user_name.test +++ b/sites/all/modules/views/tests/user/views_handler_field_user_name.test @@ -43,17 +43,33 @@ class viewsHandlerFieldUserNameTest extends ViewsSqlTest { $anon_name = variable_get('anonymous', t('Anonymous')); $view->result[0]->users_name = ''; $render = $view->field['name']->advanced_render($view->result[0]); - $this->assertIdentical($render, $anon_name , 'For user0 it should use the default anonymous name by default.'); + $this->assertIdentical($render, $anon_name, 'For user0 it should use the default anonymous name by default.'); $view->field['name']->options['overwrite_anonymous'] = TRUE; $anon_name = $view->field['name']->options['anonymous_text'] = $this->randomName(); $render = $view->field['name']->advanced_render($view->result[0]); - $this->assertIdentical($render, $anon_name , 'For user0 it should use the configured anonymous text if overwrite_anonymous is checked.'); - + $this->assertIdentical($render, $anon_name, 'For user0 it should use the configured anonymous text if overwrite_anonymous is checked.'); } + + /** + * Tests that deselecting 'link_to_user' and 'format_username' works. + */ + public function testOptions() { + $view = $this->view_raw_user_name(); + $view->init_display(); + $this->executeView($view); + + $view->row_index = 0; + + $username = $view->result[0]->users_name = 'test'; + $view->result[0]->uid = 1; + $render = $view->field['name']->advanced_render($view->result[0]); + $this->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.'); + } + function view_user_name() { - $view = new view; + $view = new view(); $view->name = 'test_views_handler_field_user_name'; $view->description = ''; $view->tag = 'default'; @@ -93,4 +109,47 @@ class viewsHandlerFieldUserNameTest extends ViewsSqlTest { return $view; } + + function view_raw_user_name() { + $view = new view; + $view->name = 'test_views_handler_field_user_name'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'users'; + $view->human_name = 'test_views_handler_field_user_name'; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['access']['type'] = 'none'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['query']['options']['query_comment'] = FALSE; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'fields'; + /* Field: User: Name */ + $handler->display->display_options['fields']['name']['id'] = 'name'; + $handler->display->display_options['fields']['name']['table'] = 'users'; + $handler->display->display_options['fields']['name']['field'] = 'name'; + $handler->display->display_options['fields']['name']['label'] = ''; + $handler->display->display_options['fields']['name']['alter']['alter_text'] = 0; + $handler->display->display_options['fields']['name']['alter']['make_link'] = 0; + $handler->display->display_options['fields']['name']['alter']['absolute'] = 0; + $handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0; + $handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0; + $handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0; + $handler->display->display_options['fields']['name']['alter']['trim'] = 0; + $handler->display->display_options['fields']['name']['alter']['html'] = 0; + $handler->display->display_options['fields']['name']['hide_empty'] = 0; + $handler->display->display_options['fields']['name']['empty_zero'] = 0; + $handler->display->display_options['fields']['name']['link_to_user'] = 0; + $handler->display->display_options['fields']['name']['format_username'] = 0; + $handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0; + + return $view; + } } diff --git a/sites/all/modules/views/tests/user/views_user.test b/sites/all/modules/views/tests/user/views_user.test index 52c5026..2f0e2cd 100644 --- a/sites/all/modules/views/tests/user/views_user.test +++ b/sites/all/modules/views/tests/user/views_user.test @@ -9,9 +9,20 @@ * Tests basic user module integration into views. */ class ViewsUserTestCase extends ViewsSqlTest { + + /** + * + */ var $users = array(); + + /** + * + */ var $nodes = array(); + /** + * + */ public static function getInfo() { return array( 'name' => 'Tests basic user integration', @@ -20,7 +31,9 @@ class ViewsUserTestCase extends ViewsSqlTest { ); } - + /** + * + */ protected function setUp() { parent::setUp(); @@ -31,7 +44,7 @@ class ViewsUserTestCase extends ViewsSqlTest { } /** - * Add a view which has no explicit relationship to the author and check the result. + * Add a view which has no explicit relationship to the author. * * @todo: Remove the following comment once the relationship is required. * One day a view will require the relationship so it should still work @@ -51,8 +64,11 @@ class ViewsUserTestCase extends ViewsSqlTest { $this->assertIdenticalResultset($view, $expected); } + /** + * + */ function test_view_user_relationship() { - $view = new view; + $view = new view(); $view->name = 'test_user_relationship'; $view->description = ''; $view->tag = 'default'; @@ -140,4 +156,5 @@ class ViewsUserTestCase extends ViewsSqlTest { return $view; } + } diff --git a/sites/all/modules/views/tests/user/views_user_argument_default.test b/sites/all/modules/views/tests/user/views_user_argument_default.test index afb24d1..2888193 100644 --- a/sites/all/modules/views/tests/user/views_user_argument_default.test +++ b/sites/all/modules/views/tests/user/views_user_argument_default.test @@ -9,6 +9,10 @@ * Tests views user argument default plugin. */ class ViewsUserArgumentDefault extends ViewsSqlTest { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Tests user argument default plugin', @@ -17,11 +21,15 @@ class ViewsUserArgumentDefault extends ViewsSqlTest { ); } + /** + * + */ public function test_plugin_argument_default_current_user() { // Create a user to test. $account = $this->drupalCreateUser(); - // Switch the user, we have to check the global user too, because drupalLogin is only for the simpletest browser. + // Switch the user, we have to check the global user too, because + // drupalLogin is only for the simpletest browser. $this->drupalLogin($account); global $user; $admin = $user; @@ -40,8 +48,11 @@ class ViewsUserArgumentDefault extends ViewsSqlTest { drupal_save_session(TRUE); } + /** + * + */ function view_plugin_argument_default_current_user() { - $view = new view; + $view = new view(); $view->name = 'test_plugin_argument_default_current_user'; $view->description = ''; $view->tag = ''; @@ -87,4 +98,5 @@ class ViewsUserArgumentDefault extends ViewsSqlTest { return $view; } + } diff --git a/sites/all/modules/views/tests/user/views_user_argument_validate.test b/sites/all/modules/views/tests/user/views_user_argument_validate.test index 6e157bf..91aebba 100644 --- a/sites/all/modules/views/tests/user/views_user_argument_validate.test +++ b/sites/all/modules/views/tests/user/views_user_argument_validate.test @@ -24,7 +24,7 @@ class ViewsUserArgumentValidate extends ViewsSqlTest { function testArgumentValidateUserUid() { $account = $this->account; - // test 'uid' case + // test 'uid' case. $view = $this->view_argument_validate_user('uid'); $view->set_display('default'); $view->pre_execute(); @@ -36,13 +36,13 @@ class ViewsUserArgumentValidate extends ViewsSqlTest { $this->assertFalse($view->argument['null']->validate_arg($account->name)); // Reset safed argument validation. $view->argument['null']->argument_validated = NULL; - // Fail for a valid numeric, but for a user that doesn't exist + // Fail for a valid numeric, but for a user that doesn't exist. $this->assertFalse($view->argument['null']->validate_arg(32)); } function testArgumentValidateUserName() { $account = $this->account; - // test 'name' case + // test 'name' case. $view = $this->view_argument_validate_user('name'); $view->set_display('default'); $view->pre_execute(); @@ -54,13 +54,13 @@ class ViewsUserArgumentValidate extends ViewsSqlTest { $this->assertFalse($view->argument['null']->validate_arg($account->uid)); // Reset safed argument validation. $view->argument['null']->argument_validated = NULL; - // Fail for a valid string, but for a user that doesn't exist + // Fail for a valid string, but for a user that doesn't exist. $this->assertFalse($view->argument['null']->validate_arg($this->randomName())); } function testArgumentValidateUserEither() { $account = $this->account; - // test 'either' case + // test 'either' case. $view = $this->view_argument_validate_user('either'); $view->set_display('default'); $view->pre_execute(); @@ -72,16 +72,16 @@ class ViewsUserArgumentValidate extends ViewsSqlTest { $this->assertTrue($view->argument['null']->validate_arg($account->uid)); // Reset safed argument validation. $view->argument['null']->argument_validated = NULL; - // Fail for a valid string, but for a user that doesn't exist + // Fail for a valid string, but for a user that doesn't exist. $this->assertFalse($view->argument['null']->validate_arg($this->randomName())); // Reset safed argument validation. $view->argument['null']->argument_validated = NULL; - // Fail for a valid uid, but for a user that doesn't exist + // Fail for a valid uid, but for a user that doesn't exist. $this->assertFalse($view->argument['null']->validate_arg(32)); } function view_argument_validate_user($argtype) { - $view = new view; + $view = new view(); $view->name = 'view_argument_validate_user'; $view->description = ''; $view->tag = ''; diff --git a/sites/all/modules/views/tests/views_access.test b/sites/all/modules/views/tests/views_access.test index f02eca9..73b23ef 100644 --- a/sites/all/modules/views/tests/views_access.test +++ b/sites/all/modules/views/tests/views_access.test @@ -17,6 +17,9 @@ class ViewsAccessTest extends ViewsSqlTest { ); } + /** + * {@inheritdoc} + */ public function setUp() { parent::setUp(); diff --git a/sites/all/modules/views/tests/views_analyze.test b/sites/all/modules/views/tests/views_analyze.test index c21a4bb..d16103e 100644 --- a/sites/all/modules/views/tests/views_analyze.test +++ b/sites/all/modules/views/tests/views_analyze.test @@ -20,7 +20,7 @@ class ViewsAnalyzeTest extends ViewsSqlTest { public function setUp() { parent::setUp('views_ui'); module_enable(array('views_ui')); - // @TODO Figure out why it's required to clear the cache here. + // @todo Figure out why it's required to clear the cache here. views_module_include('views_default', TRUE); views_get_all_views(TRUE); menu_rebuild(); @@ -48,4 +48,5 @@ class ViewsAnalyzeTest extends ViewsSqlTest { // This redirects the user back to the main views edit page. $this->drupalPost(NULL, array(), t('Ok')); } + } diff --git a/sites/all/modules/views/tests/views_argument_default.test b/sites/all/modules/views/tests/views_argument_default.test index 9c0a7eb..f6e1282 100644 --- a/sites/all/modules/views/tests/views_argument_default.test +++ b/sites/all/modules/views/tests/views_argument_default.test @@ -13,7 +13,7 @@ class ViewsArgumentDefaultTest extends ViewsSqlTest { return array( 'name' => 'Argument_default', 'description' => 'Tests pluggable argument_default for views.', - 'group' => 'Views Plugins' + 'group' => 'Views Plugins', ); } @@ -62,7 +62,7 @@ class ViewsArgumentDefaultTest extends ViewsSqlTest { $view->destroy(); - // Make sure that a normal argument provided is used + // Make sure that a normal argument provided is used. $view = $this->view_argument_default_fixed(); $view->set_display('default'); @@ -87,7 +87,7 @@ class ViewsArgumentDefaultTest extends ViewsSqlTest { } function view_argument_default_fixed() { - $view = new view; + $view = new view(); $view->name = 'test_argument_default_fixed'; $view->description = ''; $view->tag = ''; @@ -134,4 +134,5 @@ class ViewsArgumentDefaultTest extends ViewsSqlTest { return $view; } + } diff --git a/sites/all/modules/views/tests/views_argument_validator.test b/sites/all/modules/views/tests/views_argument_validator.test index fb2e4f2..6927584 100644 --- a/sites/all/modules/views/tests/views_argument_validator.test +++ b/sites/all/modules/views/tests/views_argument_validator.test @@ -40,10 +40,27 @@ class ViewsArgumentValidatorTest extends ViewsSqlTest { $this->assertTrue($view->argument['null']->validate_arg(12)); } + /** + * Make sure argument validation works properly. + */ + function testArgumentValidatePhpFailure() { + $view = $this->view_test_argument_validate_php_failure(); + $view->save(); + $this->drupalGet('test-php-failure'); + + // This should return a 403, indicating that the arguments validation fails. + $this->assertResponse(403); + + $this->drupalGet('test-php-failure-feed'); + + // This should return a 403, indicating that the arguments validation fails. + $this->assertResponse(403); + } + function view_test_argument_validate_php($string) { - $code = 'return $argument == \''. $string .'\';'; - $view = new view; - $view->name = 'view_argument_validate_numeric'; + $code = 'return $argument == \'' . $string . '\';'; + $view = new view(); + $view->name = 'view_argument_validate_php'; $view->description = ''; $view->tag = ''; $view->view_php = ''; @@ -74,7 +91,7 @@ class ViewsArgumentValidatorTest extends ViewsSqlTest { } function view_argument_validate_numeric() { - $view = new view; + $view = new view(); $view->name = 'view_argument_validate_numeric'; $view->description = ''; $view->tag = ''; @@ -103,4 +120,69 @@ class ViewsArgumentValidatorTest extends ViewsSqlTest { return $view; } + + /** + * + * + * @return view $view + * The required view object. + */ + function view_test_argument_validate_php_failure() { + $view = new view(); + $view->name = 'view_argument_validate_php_failure'; + $view->description = ''; + $view->tag = ''; + $view->base_table = 'node'; + $view->human_name = ''; + $view->core = 0; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'none'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'none'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'fields'; + /* Field: Content: Title */ + $handler->display->display_options['fields']['title']['id'] = 'title'; + $handler->display->display_options['fields']['title']['table'] = 'node'; + $handler->display->display_options['fields']['title']['field'] = 'title'; + $handler->display->display_options['fields']['title']['label'] = ''; + $handler->display->display_options['fields']['title']['element_label_colon'] = FALSE; + $handler->display->display_options['fields']['title']['link_to_node'] = FALSE; + /* Contextual filter: Global: Null */ + $handler->display->display_options['arguments']['null']['id'] = 'null'; + $handler->display->display_options['arguments']['null']['table'] = 'views'; + $handler->display->display_options['arguments']['null']['field'] = 'null'; + $handler->display->display_options['arguments']['null']['default_action'] = 'default'; + $handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed'; + $handler->display->display_options['arguments']['null']['default_argument_options']['argument'] = 'No filter'; + $handler->display->display_options['arguments']['null']['summary']['number_of_records'] = '0'; + $handler->display->display_options['arguments']['null']['summary']['format'] = 'default_summary'; + $handler->display->display_options['arguments']['null']['summary_options']['items_per_page'] = '25'; + $handler->display->display_options['arguments']['null']['specify_validation'] = TRUE; + $handler->display->display_options['arguments']['null']['validate']['type'] = 'php'; + $handler->display->display_options['arguments']['null']['validate_options']['code'] = 'return FALSE;'; + $handler->display->display_options['arguments']['null']['validate']['fail'] = 'access denied'; + + /* Display: Page */ + $handler = $view->new_display('page', 'Page', 'page_1'); + $handler->display->display_options['path'] = 'test-php-failure'; + + /* Display: Feed */ + $handler = $view->new_display('feed', 'Feed', 'feed_1'); + $handler->display->display_options['path'] = 'test-php-failure-feed'; + $handler->display->display_options['pager']['type'] = 'none'; + $handler->display->display_options['pager']['options']['offset'] = '0'; + $handler->display->display_options['style_plugin'] = 'rss'; + $handler->display->display_options['row_plugin'] = 'node_rss'; + + return $view; + } + } diff --git a/sites/all/modules/views/tests/views_basic.test b/sites/all/modules/views/tests/views_basic.test index 5fc60d8..5d590f9 100644 --- a/sites/all/modules/views/tests/views_basic.test +++ b/sites/all/modules/views/tests/views_basic.test @@ -2,18 +2,20 @@ /** * @file - * Definition of ViewsBasicTest. */ /** * Basic test class for Views query builder tests. */ +/** + * + */ class ViewsBasicTest extends ViewsSqlTest { public static function getInfo() { return array( 'name' => 'Basic query test', 'description' => 'A basic query test for Views.', - 'group' => 'Views' + 'group' => 'Views', ); } @@ -137,12 +139,12 @@ class ViewsBasicTest extends ViewsSqlTest { 'validate_argument_transform' => 0, 'validate_user_restrict_roles' => 0, 'validate_argument_php' => '', - ) + ), )); $saved_view = clone $view; - // Execute with a view + // Execute with a view. $view->set_arguments(array(27)); $this->executeView($view); @@ -175,4 +177,5 @@ class ViewsBasicTest extends ViewsSqlTest { 'views_test_age' => 'age', )); } + } diff --git a/sites/all/modules/views/tests/views_cache.test b/sites/all/modules/views/tests/views_cache.test index 28534a2..cb1fdfb 100644 --- a/sites/all/modules/views/tests/views_cache.test +++ b/sites/all/modules/views/tests/views_cache.test @@ -11,11 +11,15 @@ * @see views_plugin_cache */ class ViewsCacheTest extends ViewsSqlTest { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Cache', 'description' => 'Tests pluggable caching for views.', - 'group' => 'Views Plugins' + 'group' => 'Views Plugins', ); } @@ -153,9 +157,9 @@ class ViewsCacheTest extends ViewsSqlTest { * Tests css/js storage and restoring mechanism. */ function testHeaderStorage() { - // Create a view with output caching enabled. - // Some hook_views_pre_render in views_test.module adds the test css/js file. - // so they should be added to the css/js storage. + // Create a view with output caching enabled. Some hook_views_pre_render in + // views_test.module adds the test css/js file, so they should be added to + // the css/js storage. $view = $this->getBasicView(); $view->init_display(); $view->name = 'test_cache_header_storage'; diff --git a/sites/all/modules/views/tests/views_cache.test.js b/sites/all/modules/views/tests/views_cache.test.js index 8dd17c1..26644cf 100644 --- a/sites/all/modules/views/tests/views_cache.test.js +++ b/sites/all/modules/views/tests/views_cache.test.js @@ -1,5 +1,6 @@ /** * @file * Just a placeholder file for the test. + * * @see ViewsCacheTest::testHeaderStorage */ diff --git a/sites/all/modules/views/tests/views_clone.test b/sites/all/modules/views/tests/views_clone.test new file mode 100644 index 0000000..7ac10ab --- /dev/null +++ b/sites/all/modules/views/tests/views_clone.test @@ -0,0 +1,277 @@ + 'Test cloning a view', + 'description' => 'Tests clone_view method of views class', + 'group' => 'Views', + ); + } + + /** + * Returns a new term with random properties in vocabulary $vocabulary. + */ + protected function createTerm($vocabulary) { + $term = new stdClass(); + $term->name = $this->randomName(); + $term->description = $this->randomName(); + // Use the first available text format. + $term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(); + $term->vid = $vocabulary->vid; + taxonomy_term_save($term); + return $term; + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + + $vocabulary = taxonomy_vocabulary_machine_name_load('tags'); + $this->term = $this->createTerm($vocabulary); + + $node = array(); + $node['type'] = 'article'; + $node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->term->tid; + $this->node = $this->drupalCreateNode($node); + } + + /** + * Test cloning a view. + */ + public function testClone() { + // Prepare view to be cloned. + $view = $this->getTestCloneView(); + $view->set_arguments(array( + 0 => $this->node->nid, + )); + $view->set_exposed_input(array( + 'field_tags_tid' => $this->term->tid, + )); + + // Execute view to be cloned. + $result = $view->execute(); + + // To make sure that we are properly testing removal of all properties, we + // first need to assert that they are actually present in the original view. + $keys = array( + 'current_display', + 'display_handler', + 'field', + 'argument', + 'filter', + 'sort', + 'relationship', + 'header', + 'footer', + 'empty', + 'query', + 'inited', + 'style_plugin', + 'plugin_name', + 'exposed_data', + 'exposed_input', + 'exposed_widgets', + 'many_to_one_aliases', + 'many_to_one_tables', + 'feed_icon', + ); + foreach ($keys as $key) { + $this->assertTrue(isset($view->{$key}), $key . 'is set in original view.'); + } + $this->assertTrue($view->built, 'Assert original view built.'); + $this->assertTrue($view->executed, 'Assert original view executed.'); + $this->assertNotEqual($view->build_info, array(), 'Assert original view has build_info.'); + $this->assertNotEqual($view->attachment_before, '', 'Assert original view has attachment_before.'); + $this->assertNotEqual($view->attachment_after, '', 'Assert original view has attachment_after.'); + $this->assertNotEqual($view->result, array(), 'Assert original view has result.'); + + // Clone view. + $clone = $view->clone_view(); + + // Assert that all relevant properties have been removed or reset. + $keys = array( + 'current_display', + 'display_handler', + 'field', + 'argument', + 'filter', + 'sort', + 'relationship', + 'header', + 'footer', + 'empty', + 'query', + 'inited', + 'style_plugin', + 'plugin_name', + 'exposed_data', + 'exposed_input', + 'exposed_widgets', + 'many_to_one_aliases', + 'many_to_one_tables', + 'feed_icon', + ); + foreach ($keys as $key) { + $this->assertFalse(isset($clone->{$key}), $key . ' has been removed in cloned view.'); + } + foreach ($clone->display as $id => $display) { + $this->assertFalse(isset($clone->display[$id]->handler), 'Make sure all display handlers have been destroyed.'); + } + $this->assertFalse($clone->built, 'Assert cloned view not built.'); + $this->assertFalse($clone->executed, 'Assert cloned view not executed.'); + $this->assertEqual($clone->build_info, array(), 'Assert cloned view has empty build_info.'); + $this->assertEqual($clone->attachment_before, '', 'Assert cloned view has empty attachment_before.'); + $this->assertEqual($clone->attachment_after, '', 'Assert cloned view has empty attachment_after.'); + $this->assertEqual($clone->result, array(), 'Assert cloned view has empty result.'); + + // Execute cloned view. + $clone->execute(); + + // Assert result sets are equal. + $this->assertEqual($view->result, $clone->result, 'Result sets of cloned view and original view match.'); + } + + /** + * Generate test_clone view. + */ + protected function getTestCloneView() { + $view = new view(); + $view->name = 'test_clone'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->human_name = 'test_clone'; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['title'] = 'test_clone'; + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'perm'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['pager']['options']['items_per_page'] = '10'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'node'; + /* Header: Global: Text area */ + $handler->display->display_options['header']['area']['id'] = 'area'; + $handler->display->display_options['header']['area']['table'] = 'views'; + $handler->display->display_options['header']['area']['field'] = 'area'; + $handler->display->display_options['header']['area']['label'] = 'Header'; + $handler->display->display_options['header']['area']['content'] = 'Header'; + $handler->display->display_options['header']['area']['format'] = 'filtered_html'; + /* Footer: Global: Text area */ + $handler->display->display_options['footer']['area']['id'] = 'area'; + $handler->display->display_options['footer']['area']['table'] = 'views'; + $handler->display->display_options['footer']['area']['field'] = 'area'; + $handler->display->display_options['footer']['area']['label'] = 'Footer'; + $handler->display->display_options['footer']['area']['content'] = 'Footer'; + $handler->display->display_options['footer']['area']['format'] = 'filtered_html'; + /* No results behavior: Global: Text area */ + $handler->display->display_options['empty']['area']['id'] = 'area'; + $handler->display->display_options['empty']['area']['table'] = 'views'; + $handler->display->display_options['empty']['area']['field'] = 'area'; + $handler->display->display_options['empty']['area']['label'] = 'Empty'; + $handler->display->display_options['empty']['area']['empty'] = TRUE; + $handler->display->display_options['empty']['area']['content'] = 'Empty'; + $handler->display->display_options['empty']['area']['format'] = 'filtered_html'; + /* Relationship: Comment: Last Comment */ + $handler->display->display_options['relationships']['cid']['id'] = 'cid'; + $handler->display->display_options['relationships']['cid']['table'] = 'node_comment_statistics'; + $handler->display->display_options['relationships']['cid']['field'] = 'cid'; + /* Field: Content: Title */ + $handler->display->display_options['fields']['title']['id'] = 'title'; + $handler->display->display_options['fields']['title']['table'] = 'node'; + $handler->display->display_options['fields']['title']['field'] = 'title'; + $handler->display->display_options['fields']['title']['label'] = ''; + $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; + $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; + /* Sort criterion: Content: Post date */ + $handler->display->display_options['sorts']['created']['id'] = 'created'; + $handler->display->display_options['sorts']['created']['table'] = 'node'; + $handler->display->display_options['sorts']['created']['field'] = 'created'; + $handler->display->display_options['sorts']['created']['order'] = 'DESC'; + /* Contextual filter: Content: Nid */ + $handler->display->display_options['arguments']['nid']['id'] = 'nid'; + $handler->display->display_options['arguments']['nid']['table'] = 'node'; + $handler->display->display_options['arguments']['nid']['field'] = 'nid'; + $handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed'; + $handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0'; + $handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary'; + $handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25'; + /* Filter criterion: Content: Published */ + $handler->display->display_options['filters']['status']['id'] = 'status'; + $handler->display->display_options['filters']['status']['table'] = 'node'; + $handler->display->display_options['filters']['status']['field'] = 'status'; + $handler->display->display_options['filters']['status']['value'] = 'All'; + $handler->display->display_options['filters']['status']['group'] = 1; + $handler->display->display_options['filters']['status']['exposed'] = TRUE; + $handler->display->display_options['filters']['status']['expose']['operator_id'] = ''; + $handler->display->display_options['filters']['status']['expose']['label'] = 'Published'; + $handler->display->display_options['filters']['status']['expose']['operator'] = 'status_op'; + $handler->display->display_options['filters']['status']['expose']['identifier'] = 'status'; + $handler->display->display_options['filters']['status']['expose']['remember_roles'] = array( + 2 => '2', + ); + /* Filter criterion: Content: Tags (field_tags) */ + $handler->display->display_options['filters']['field_tags_tid']['id'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['table'] = 'field_data_field_tags'; + $handler->display->display_options['filters']['field_tags_tid']['field'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['exposed'] = TRUE; + $handler->display->display_options['filters']['field_tags_tid']['expose']['operator_id'] = 'field_tags_tid_op'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['label'] = 'Tags (field_tags)'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['operator'] = 'field_tags_tid_op'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['identifier'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['remember_roles'] = array( + 2 => '2', + ); + $handler->display->display_options['filters']['field_tags_tid']['reduce_duplicates'] = TRUE; + $handler->display->display_options['filters']['field_tags_tid']['type'] = 'select'; + $handler->display->display_options['filters']['field_tags_tid']['vocabulary'] = 'tags'; + /* Display: Page */ + $handler = $view->new_display('page', 'Page', 'page'); + $handler->display->display_options['path'] = 'test-clone'; + /* Display: attachment_before */ + $handler = $view->new_display('attachment', 'attachment_before', 'attachment_1'); + $handler->display->display_options['pager']['type'] = 'some'; + $handler->display->display_options['displays'] = array( + 'default' => 'default', + 'page' => 'page', + ); + $handler->display->display_options['inherit_exposed_filters'] = TRUE; + /* Display: attachment_after */ + $handler = $view->new_display('attachment', 'attachment_after', 'attachment_2'); + $handler->display->display_options['pager']['type'] = 'some'; + $handler->display->display_options['displays'] = array( + 'default' => 'default', + 'page' => 'page', + ); + $handler->display->display_options['attachment_position'] = 'after'; + $handler->display->display_options['inherit_exposed_filters'] = TRUE; + /* Display: Feed */ + $handler = $view->new_display('feed', 'Feed', 'feed_1'); + $handler->display->display_options['pager']['type'] = 'some'; + $handler->display->display_options['style_plugin'] = 'rss'; + $handler->display->display_options['row_plugin'] = 'node_rss'; + $handler->display->display_options['path'] = 'test_clone/rss'; + $handler->display->display_options['displays'] = array( + 'default' => 'default', + 'page' => 'page', + ); + return $view; + } + +} diff --git a/sites/all/modules/views/tests/views_exposed_form.test b/sites/all/modules/views/tests/views_exposed_form.test index afa4f42..b202564 100644 --- a/sites/all/modules/views/tests/views_exposed_form.test +++ b/sites/all/modules/views/tests/views_exposed_form.test @@ -9,6 +9,10 @@ * Tests exposed forms. */ class ViewsExposedFormTest extends ViewsSqlTest { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Exposed forms', @@ -17,10 +21,13 @@ class ViewsExposedFormTest extends ViewsSqlTest { ); } + /** + * + */ public function setUp() { parent::setUp('views_ui'); module_enable(array('views_ui')); - // @TODO Figure out why it's required to clear the cache here. + // @todo Figure out why it's required to clear the cache here. views_module_include('views_default', TRUE); views_get_all_views(TRUE); menu_rebuild(); @@ -75,7 +82,8 @@ class ViewsExposedFormTest extends ViewsSqlTest { $this->drupalGet('test_exposed_remember'); $this->assertFieldByName('type', 'page'); - // Request the page with an unrelated GET argument, filter should still be set. + // Request the page with an unrelated GET argument, filter should still be + // set. $this->drupalGet('test_exposed_remember', array('query' => array('argument' => 'value'))); $this->assertFieldByName('type', 'page'); @@ -101,8 +109,8 @@ class ViewsExposedFormTest extends ViewsSqlTest { // Be sure that the button is called exposed. $this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose filter')); - // The first time the filter UI is displayed, the operator and the - // value forms should be shown. + // The first time the filter UI is displayed, the operator and the value + // forms should be shown. $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists'); $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists'); $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists'); @@ -112,10 +120,10 @@ class ViewsExposedFormTest extends ViewsSqlTest { $this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type', $edit, t('Expose filter')); // Check the label of the expose button. $this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide filter')); - // Check the label of the grouped exposed button + // Check the label of the grouped exposed button. $this->helperButtonHasLabel('edit-options-group-button-button', t('Grouped filters')); - // After Expose the filter, Operator and Value should be still here + // After Expose the filter, Operator and Value should be still here. $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists'); $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists'); $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists'); @@ -141,18 +149,18 @@ class ViewsExposedFormTest extends ViewsSqlTest { $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type'); $this->drupalPost(NULL, array(), t('Grouped filters')); - // After click on 'Grouped Filters' standard operator and value should not be displayed + // After click on 'Grouped Filters' standard operator and value should not + // be displayed. $this->assertNoFieldById('edit-options-operator-in', '', 'Operator In not exists'); $this->assertNoFieldById('edit-options-operator-not-in', '', 'Operator Not In not exists'); $this->assertNoFieldById('edit-options-value-page', '', 'Checkbox for Page not exists'); $this->assertNoFieldById('edit-options-value-article', '', 'Checkbox for Article not exists'); - // Check that after click on 'Grouped Filters', a new button is shown to // add more items to the list. $this->helperButtonHasLabel('edit-options-group-info-add-group', t('Add another item')); - // Create a grouped filter + // Create a grouped filter. $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type'); $edit = array(); $edit["options[group_info][group_items][1][title]"] = 'Is Article'; @@ -166,13 +174,13 @@ class ViewsExposedFormTest extends ViewsSqlTest { $edit["options[group_info][group_items][3][value][page]"] = TRUE; $this->drupalPost(NULL, $edit, t('Apply')); - // Validate that all the titles are defined for each group + // Validate that all the titles are defined for each group. $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type'); $edit = array(); $edit["options[group_info][group_items][1][title]"] = 'Is Article'; $edit["options[group_info][group_items][1][value][article]"] = TRUE; - // This should trigger an error + // This should trigger an error. $edit["options[group_info][group_items][2][title]"] = ''; $edit["options[group_info][group_items][2][value][page]"] = TRUE; @@ -182,11 +190,11 @@ class ViewsExposedFormTest extends ViewsSqlTest { $this->drupalPost(NULL, $edit, t('Apply')); $this->assertRaw(t('The title is required if value for this item is defined.'), t('Group items should have a title')); - // Un-Expose the filter + // Un-Expose the filter. $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type'); $this->drupalPost(NULL, array(), t('Hide filter')); - // After Un-Expose the filter, Operator and Value should be shown again + // After Un-Expose the filter, Operator and Value should be shown again. $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists after hide filter'); $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists after hide filter'); $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists after hide filter'); @@ -199,4 +207,5 @@ class ViewsExposedFormTest extends ViewsSqlTest { $this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide sort')); $this->assertFieldById('edit-options-expose-label', '', t('Make sure a label field is shown')); } + } diff --git a/sites/all/modules/views/tests/views_glossary.test b/sites/all/modules/views/tests/views_glossary.test index 0fe0fba..d7d7c64 100644 --- a/sites/all/modules/views/tests/views_glossary.test +++ b/sites/all/modules/views/tests/views_glossary.test @@ -37,7 +37,7 @@ class ViewsGlossaryTestCase extends ViewsSqlTest { ); foreach ($nodes_per_char as $char => $count) { $setting = array( - 'type' => $type->type + 'type' => $type->type, ); for ($i = 0; $i < $count; $i++) { $node = $setting; @@ -46,7 +46,7 @@ class ViewsGlossaryTestCase extends ViewsSqlTest { } } - // Execute glossary view + // Execute glossary view. $view = views_get_view('glossary'); $view->set_display('attachment'); $view->execute_display('attachment'); @@ -57,4 +57,5 @@ class ViewsGlossaryTestCase extends ViewsSqlTest { $this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records); } } + } diff --git a/sites/all/modules/views/tests/views_groupby.test b/sites/all/modules/views/tests/views_groupby.test index 4e09256..364e61b 100644 --- a/sites/all/modules/views/tests/views_groupby.test +++ b/sites/all/modules/views/tests/views_groupby.test @@ -2,20 +2,103 @@ /** * @file - * Tests aggregate functionality of Views. + * Definitions of ViewsQueryGroupByTest and ViewsUiGroupbyTestCase. */ /** * Tests aggregate functionality of views, for example count. */ class ViewsQueryGroupByTest extends ViewsSqlTest { + + /** + * Test meta data. + */ public static function getInfo() { return array( 'name' => 'Groupby', 'description' => 'Tests aggregate functionality of views, for example count.', 'group' => 'Views', ); + } + // tests ambiguous group by column error (postgresql) + public function testAggregateAmbiguity() { + // Create 4 nodes of type1 + $type1 = $this->drupalCreateContentType(); + + $node_1 = array( + 'type' => $type1->type, + ); + $this->drupalCreateNode($node_1); + $this->drupalCreateNode($node_1); + $this->drupalCreateNode($node_1); + $this->drupalCreateNode($node_1); + + $view = $this->viewsAggregateAmbiguityView(); + $output = $view->execute_display(); + + $this->assertEqual(count($view->result), 1, 'Make sure there are no ambiguity problems with the group by operation.'); + } + + public function viewsAggregateAmbiguityView() { + $view = new view(); + $view->name = 'aggregate_ambiguity'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->human_name = ''; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['group_by'] = TRUE; + $handler->display->display_options['access']['type'] = 'none'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'fields'; + /* Field: COUNT(Content revision: Nid) */ + $handler->display->display_options['fields']['nid']['id'] = 'nid'; + $handler->display->display_options['fields']['nid']['table'] = 'node_revision'; + $handler->display->display_options['fields']['nid']['field'] = 'nid'; + $handler->display->display_options['fields']['nid']['group_type'] = 'count'; + $handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0; + $handler->display->display_options['fields']['nid']['alter']['make_link'] = 0; + $handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1; + $handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1; + $handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0; + $handler->display->display_options['fields']['nid']['alter']['trim'] = 0; + $handler->display->display_options['fields']['nid']['alter']['html'] = 0; + $handler->display->display_options['fields']['nid']['hide_empty'] = 0; + $handler->display->display_options['fields']['nid']['empty_zero'] = 0; + /* Field: Content: Nid */ + $handler->display->display_options['fields']['nid_1']['id'] = 'nid_1'; + $handler->display->display_options['fields']['nid_1']['table'] = 'node'; + $handler->display->display_options['fields']['nid_1']['field'] = 'nid'; + $handler->display->display_options['fields']['nid_1']['alter']['alter_text'] = 0; + $handler->display->display_options['fields']['nid_1']['alter']['make_link'] = 0; + $handler->display->display_options['fields']['nid_1']['alter']['word_boundary'] = 1; + $handler->display->display_options['fields']['nid_1']['alter']['ellipsis'] = 1; + $handler->display->display_options['fields']['nid_1']['alter']['strip_tags'] = 0; + $handler->display->display_options['fields']['nid_1']['alter']['trim'] = 0; + $handler->display->display_options['fields']['nid_1']['alter']['html'] = 0; + $handler->display->display_options['fields']['nid_1']['hide_empty'] = 0; + $handler->display->display_options['fields']['nid_1']['empty_zero'] = 0; + /* Contextual filter: Content: Type */ + $handler->display->display_options['arguments']['type']['id'] = 'type'; + $handler->display->display_options['arguments']['type']['table'] = 'node'; + $handler->display->display_options['arguments']['type']['field'] = 'type'; + $handler->display->display_options['arguments']['type']['default_action'] = 'summary'; + $handler->display->display_options['arguments']['type']['default_argument_type'] = 'fixed'; + $handler->display->display_options['arguments']['type']['summary']['format'] = 'default_summary'; + + + return $view; } /** @@ -48,7 +131,7 @@ class ViewsQueryGroupByTest extends ViewsSqlTest { $types = array(); foreach ($view->result as $item) { - // num_records is a alias for nid. + // 'num_records' is a alias for nid. $types[$item->node_type] = $item->num_records; } @@ -56,9 +139,15 @@ class ViewsQueryGroupByTest extends ViewsSqlTest { $this->assertEqual($types[$type2->type], 3); } - //public function testAggregateSum() { - //} + /** + * + */ + // public function testAggregateSum() { + // } + /** + * + */ public function viewsAggregateCountView() { $view = new view; $view->name = 'aggregate_count'; @@ -103,7 +192,6 @@ class ViewsQueryGroupByTest extends ViewsSqlTest { $handler->display->display_options['arguments']['type']['default_argument_type'] = 'fixed'; $handler->display->display_options['arguments']['type']['summary']['format'] = 'default_summary'; - return $view; } @@ -144,7 +232,9 @@ class ViewsQueryGroupByTest extends ViewsSqlTest { // There's no need for a function in order to have aggregation. if (empty($group_by)) { $types = array($type1->type, $type2->type); - $results = array_map(function ($item) { return $item->node_type; }, $view->result); + $results = array_map(function ($item) { + return $item->node_type; + }, $view->result); sort($types); sort($results); $this->assertIdentical($results, $types); @@ -160,6 +250,9 @@ class ViewsQueryGroupByTest extends ViewsSqlTest { $this->assertEqual($results[$type2->type], $values[1]); } + /** + * + */ function viewsGroupByViewHelper($group_by = NULL) { $view = new view; $view->name = 'group_by_count'; @@ -219,31 +312,51 @@ class ViewsQueryGroupByTest extends ViewsSqlTest { return $view; } + /** + * + */ public function testGroupByCount() { $this->GroupByTestHelper('count', array(4, 3)); } - function testGroupBySum() { + /** + * + */ + public function testGroupBySum() { $this->GroupByTestHelper('sum', array(10, 18)); } - - function testGroupByAverage() { + /** + * + */ + public function testGroupByAverage() { $this->GroupByTestHelper('avg', array(2.5, 6)); } - function testGroupByMin() { + /** + * + */ + public function testGroupByMin() { $this->GroupByTestHelper('min', array(1, 5)); } - function testGroupByMax() { + /** + * {@inheritdoc} + */ + public function testGroupByMax() { $this->GroupByTestHelper('max', array(4, 7)); } - function testGroupByNone() { + /** + * + */ + public function testGroupByNone() { $this->GroupByTestHelper(); } + /** + * + */ public function testGroupByCountOnlyFilters() { // Check if GROUP BY and HAVING are included when a view // Doesn't display SUM, COUNT, MAX... functions in SELECT statment @@ -264,6 +377,9 @@ class ViewsQueryGroupByTest extends ViewsSqlTest { $this->assertTrue(strpos($view->build_info['query'], 'HAVING'), t('Make sure that HAVING is in the query')); } + /** + * + */ function viewsGroupByCountViewOnlyFilters() { $view = new view; $view->name = 'group_by_in_filters'; @@ -308,12 +424,17 @@ class ViewsQueryGroupByTest extends ViewsSqlTest { return $view; } + } /** - * Tests UI of aggregate functionality.. + * Tests UI of aggregate functionality. */ -class viewsUiGroupbyTestCase extends DrupalWebTestCase { +class ViewsUiGroupbyTestCase extends DrupalWebTestCase { + + /** + * {@inheritdoc} + */ function setUp() { // Enable views_ui. parent::setUp('views_ui', 'views_test'); @@ -323,6 +444,9 @@ class viewsUiGroupbyTestCase extends DrupalWebTestCase { $this->drupalLogin($views_admin); } + /** + * Test meta data. + */ public static function getInfo() { return array( 'name' => 'Groupby UI', @@ -349,4 +473,5 @@ class viewsUiGroupbyTestCase extends DrupalWebTestCase { $this->drupalGet('admin/structure/views/nojs/display/test_views_groupby_save/default/group_by'); } + } diff --git a/sites/all/modules/views/tests/views_handler_filter.test b/sites/all/modules/views/tests/views_handler_filter.test new file mode 100644 index 0000000..e41b35a --- /dev/null +++ b/sites/all/modules/views/tests/views_handler_filter.test @@ -0,0 +1,161 @@ + 'Handler filter test', + 'description' => 'test filter handler definitions', + 'group' => 'Views', + ); + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + // The Views and Views UI modules will be enabled with this. + parent::setUp(); + + // Assign vocabulary 'tag' to user entity. + $field_definition = field_read_field('field_tags'); + $instance_definition = array( + 'field_name' => $field_definition['field_name'], + 'entity_type' => 'user', + 'bundle' => 'user', + 'widget' => array( + 'type' => 'taxonomy_autocomplete', + ), + 'display' => array( + 'default' => array( + 'type' => 'taxonomy_term_reference_link', + 'weight' => 10, + ), + 'teaser' => array( + 'type' => 'taxonomy_term_reference_link', + 'weight' => 10, + ), + ), + ); + field_create_instance($instance_definition); + } + + /** + * Tests "is all of" of filter operation. + */ + function testFilterInOperatorUi() { + $term = $this->drupalCreateTerm(1); + + $node1 = $this->drupalCreateNode(array('type' => 'article','field_tags_tid' => $term->tid, 'created' => REQUEST_TIME)); + $node2 = $this->drupalCreateNode(array('type' => 'article', 'created' => REQUEST_TIME + 1)); + $user2 = $this->drupalCreateUser(array('access content')); + // $this->drupalLogin($this->drupalCreateUser(array('administer users')); + $this->drupalLogin($this->drupalCreateUser(array('administer users', 'access administration pages', 'administer site configuration', 'administer nodes', 'bypass node access'))); + + $this->drupalGet('node/1/edit'); + $edit['field_tags' . '[' . LANGUAGE_NONE . ']'] = $term->name; + $this->drupalPost('node/' . $node1->nid . '/edit', $edit, t('Save')); + + $edit['field_tags' . '[' . LANGUAGE_NONE . ']'] = $term->name; + $this->drupalPost('user/' . $user2->uid . '/edit', $edit, t('Save')); + + $result[] = array('nid' => $node1->nid); + $view = $this->get_sample_view(); + $this->executeView($view); + $this->assertIdenticalResultset($view, $result); + } + + /** + * Sample view. + * + * @return \view + */ + protected function get_sample_view() { + $view = new view(); + $view->name = 'article'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->human_name = 'Article'; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['title'] = 'Article'; + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'perm'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['pager']['options']['items_per_page'] = '10'; + $handler->display->display_options['style_plugin'] = 'table'; + $handler->display->display_options['style_options']['columns'] = array( + 'title' => 'title', + ); + $handler->display->display_options['style_options']['default'] = '-1'; + $handler->display->display_options['style_options']['info'] = array( + 'title' => array( + 'sortable' => 0, + 'default_sort_order' => 'asc', + 'align' => '', + 'separator' => '', + 'empty_column' => 0, + ), + ); + /* Field: Content: Nid */ + $handler->display->display_options['fields']['nid']['id'] = 'nid'; + $handler->display->display_options['fields']['nid']['table'] = 'node'; + $handler->display->display_options['fields']['nid']['field'] = 'nid'; + $handler->display->display_options['fields']['nid']['label'] = ''; + $handler->display->display_options['fields']['nid']['element_label_colon'] = FALSE; + /* Sort criterion: Content: Post date */ + $handler->display->display_options['sorts']['created']['id'] = 'created'; + $handler->display->display_options['sorts']['created']['table'] = 'node'; + $handler->display->display_options['sorts']['created']['field'] = 'created'; + $handler->display->display_options['sorts']['created']['order'] = 'DESC'; + /* Filter criterion: Content: Published */ + $handler->display->display_options['filters']['status']['id'] = 'status'; + $handler->display->display_options['filters']['status']['table'] = 'node'; + $handler->display->display_options['filters']['status']['field'] = 'status'; + $handler->display->display_options['filters']['status']['value'] = 1; + $handler->display->display_options['filters']['status']['group'] = 1; + $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE; + /* Filter criterion: Field: Tags (field_tags) */ + $handler->display->display_options['filters']['field_tags_tid']['id'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['table'] = 'field_data_field_tags'; + $handler->display->display_options['filters']['field_tags_tid']['field'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['operator'] = 'and'; + $handler->display->display_options['filters']['field_tags_tid']['value'] = array( + 0 => '1', + ); + $handler->display->display_options['filters']['field_tags_tid']['expose']['operator_id'] = 'field_tags_tid_op'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['label'] = 'Tags (field_tags)'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['operator'] = 'field_tags_tid_op'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['identifier'] = 'field_tags_tid'; + $handler->display->display_options['filters']['field_tags_tid']['expose']['remember_roles'] = array( + 2 => '2', + ); + $handler->display->display_options['filters']['field_tags_tid']['vocabulary'] = 'tags'; + + /* Display: Page */ + $handler = $view->new_display('page', 'Page', 'page'); + $handler->display->display_options['path'] = 'article'; + + return $view; + } + +} diff --git a/sites/all/modules/views/tests/views_handlers.test b/sites/all/modules/views/tests/views_handlers.test index d54a7df..e0ace98 100644 --- a/sites/all/modules/views/tests/views_handlers.test +++ b/sites/all/modules/views/tests/views_handlers.test @@ -48,13 +48,13 @@ class ViewsHandlersTest extends ViewsSqlTest { $empty_stdclass->value = array(); $null = NULL; - // check defaults + // check defaults. $this->assertEqual($empty_stdclass, views_break_phrase_string('', $null)); $handler = views_get_handler('node', 'title', 'argument'); $this->assertEqual($handler, views_break_phrase_string('', $handler)); - // test ors + // test ors. $handler = views_break_phrase_string('word1 word2+word'); $this->assertEqualValue(array('word1', 'word2', 'word'), $handler); $this->assertEqual('or', $handler->operator); @@ -88,7 +88,7 @@ class ViewsHandlersTest extends ViewsSqlTest { $this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler); $this->assertEqual('and', $handler->operator); - // test a single word + // test a single word. $handler = views_break_phrase_string('word'); $this->assertEqualValue(array('word'), $handler); $this->assertEqual('and', $handler->operator); @@ -103,7 +103,7 @@ class ViewsHandlersTest extends ViewsSqlTest { $empty_stdclass->value = array(); $null = NULL; - // check defaults + // check defaults. $this->assertEqual($empty_stdclass, views_break_phrase('', $null)); $handler = views_get_handler('node', 'title', 'argument'); @@ -113,7 +113,7 @@ class ViewsHandlersTest extends ViewsSqlTest { $n1 = rand(0, 100); $n2 = rand(0, 100); $n3 = rand(0, 100); - // test ors + // test ors. $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2+$n3", $handler)); $this->assertEqual('or', $handler->operator); $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1+$n2+$n3", $handler)); @@ -133,7 +133,7 @@ class ViewsHandlersTest extends ViewsSqlTest { /** * Check to see if two values are equal. * - * @param $first + * @param string $first * The first value to check. * @param views_handler $handler * @param string $message @@ -147,4 +147,5 @@ class ViewsHandlersTest extends ViewsSqlTest { protected function assertEqualValue($first, $handler, $message = '', $group = 'Other') { return $this->assert($first == $handler->value, $message ? $message : t('First value is equal to second value'), $group); } + } diff --git a/sites/all/modules/views/tests/views_module.test b/sites/all/modules/views/tests/views_module.test index e160964..c3dd994 100644 --- a/sites/all/modules/views/tests/views_module.test +++ b/sites/all/modules/views/tests/views_module.test @@ -45,7 +45,7 @@ class ViewsModuleTest extends ViewsSqlTest { 'khoảng cách từ đại lí đến', 'của hãng bao gồm ba dòng', 'сд асд асд ас', - 'асд асд асд ас' + 'асд асд асд ас', ); // Just test maxlength without word boundry. $alter = array( @@ -91,7 +91,8 @@ class ViewsModuleTest extends ViewsSqlTest { */ function testModuleTemplates() { $views_status = variable_get('views_defaults', array()); - $views_status['frontpage'] = FALSE; // false is enabled + $views_status['frontpage'] = FALSE; + // false is enabled. variable_set('views_defaults', $views_status); $existing = array(); @@ -127,7 +128,6 @@ class ViewsModuleTest extends ViewsSqlTest { } // Test the automatic conversion feature. - // Test the automatic table renaming. $handler = views_get_handler('views_test_previous', 'id', 'field'); $this->assertInstanceHandler($handler, 'views_test', 'id', 'field'); @@ -194,7 +194,6 @@ class ViewsModuleTest extends ViewsSqlTest { $this->assertEqual(variable_get('views_test_views_data_count', 0), 1, 'Views data rebuilt once'); $this->assertFalse(drupal_static('_views_fetch_data_fully_loaded'), 'Views data is not fully loaded'); - // Test if the cache consistency is ensured. There was an issue where // calling _views_fetch_data() first with a table would prevent the function // from properly rebuilt a missing the general cache entry. @@ -238,4 +237,5 @@ class ViewsModuleTest extends ViewsSqlTest { drupal_static_reset('_views_fetch_data_recursion_protected'); drupal_static_reset('_views_fetch_data_fully_loaded'); } + } diff --git a/sites/all/modules/views/tests/views_pager.test b/sites/all/modules/views/tests/views_pager.test index fef4915..7a99fb6 100644 --- a/sites/all/modules/views/tests/views_pager.test +++ b/sites/all/modules/views/tests/views_pager.test @@ -9,6 +9,10 @@ * Tests the pluggable pager system. */ class ViewsPagerTest extends ViewsSqlTest { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Pager', @@ -17,6 +21,9 @@ class ViewsPagerTest extends ViewsSqlTest { ); } + /** + * + */ public function setUp() { parent::setUp('views', 'views_ui', 'views_test'); } @@ -29,11 +36,10 @@ class ViewsPagerTest extends ViewsSqlTest { public function testStorePagerSettings() { $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration')); $this->drupalLogin($admin_user); - // Test behaviour described in http://drupal.org/node/652712#comment-2354918. - + // Test behaviour described in + // http://drupal.org/node/652712#comment-2354918. $this->drupalGet('admin/structure/views/view/frontpage/edit'); - $edit = array( 'pager_options[items_per_page]' => 20, ); @@ -70,8 +76,8 @@ class ViewsPagerTest extends ViewsSqlTest { $this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options', $edit, t('Apply')); $this->assertText('20 items'); - // add new display and test the settings again, by override it. - $edit = array( ); + // Add new display and test the settings again, by override it. + $edit = array(); // Add a display and override the pager settings. $this->drupalPost('admin/structure/views/view/test_store_pager_settings/edit', $edit, t('Add Page')); $edit = array( @@ -91,11 +97,13 @@ class ViewsPagerTest extends ViewsSqlTest { ); $this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options', $edit, t('Apply')); $this->assertText('20 items'); - } + /** + * + */ public function viewsStorePagerSettings() { - $view = new view; + $view = new view(); $view->name = 'test_store_pager_settings'; $view->description = ''; $view->tag = ''; @@ -120,8 +128,8 @@ class ViewsPagerTest extends ViewsSqlTest { * Tests the none-pager-query. */ public function testNoLimit() { - // Create 11 nodes and make sure that everyone is returned. - // We create 11 nodes, because the default pager plugin had 10 items per page. + // Create 11 nodes and make sure that everyone is returned. We create 11 + // nodes, because the default pager plugin had 10 items per page. for ($i = 0; $i < 11; $i++) { $this->drupalCreateNode(); } @@ -153,15 +161,18 @@ class ViewsPagerTest extends ViewsSqlTest { $this->assertEqual($view->query->pager->get_items_per_page(), 0); } + /** + * + */ public function viewsPagerNoLimit() { - $view = new view; + $view = new view(); $view->name = 'test_pager_none'; $view->description = ''; $view->tag = ''; $view->view_php = ''; $view->base_table = 'node'; $view->is_cacheable = FALSE; - $view->api_version =3; + $view->api_version = 3; $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ /* Display: Master */ @@ -175,6 +186,9 @@ class ViewsPagerTest extends ViewsSqlTest { return $view; } + /** + * + */ public function testViewTotalRowsWithoutPager() { $this->createNodes(23); @@ -186,6 +200,9 @@ class ViewsPagerTest extends ViewsSqlTest { $this->assertEqual($view->total_rows, 23, "'total_rows' is calculated when pager type is 'none' and 'get_total_rows' is TRUE."); } + /** + * + */ public function createNodes($count) { if ($count >= 0) { for ($i = 0; $i < $count; $i++) { @@ -198,8 +215,8 @@ class ViewsPagerTest extends ViewsSqlTest { * Tests the some pager plugin. */ public function testLimit() { - // Create 11 nodes and make sure that everyone is returned. - // We create 11 nodes, because the default pager plugin had 10 items per page. + // Create 11 nodes and make sure that everyone is returned. We create 11 + // nodes, because the default pager plugin had 10 items per page. for ($i = 0; $i < 11; $i++) { $this->drupalCreateNode(); } @@ -229,8 +246,11 @@ class ViewsPagerTest extends ViewsSqlTest { $this->assertFalse($view->query->pager->use_count_query()); } + /** + * + */ public function viewsPagerLimit() { - $view = new view; + $view = new view(); $view->name = 'test_pager_some'; $view->description = ''; $view->tag = ''; @@ -257,8 +277,8 @@ class ViewsPagerTest extends ViewsSqlTest { * Tests the normal pager. */ public function testNormalPager() { - // Create 11 nodes and make sure that everyone is returned. - // We create 11 nodes, because the default pager plugin had 10 items per page. + // Create 11 nodes and make sure that everyone is returned. We create 11 + // nodes, because the default pager plugin had 10 items per page. for ($i = 0; $i < 11; $i++) { $this->drupalCreateNode(); } @@ -290,8 +310,7 @@ class ViewsPagerTest extends ViewsSqlTest { $this->assertEqual(count($view->result), 11, 'All items are return'); - // TODO test number of pages. - + // @todo test number of pages. // Test items per page = 0. $view->destroy(); @@ -313,8 +332,11 @@ class ViewsPagerTest extends ViewsSqlTest { $this->assertEqual(count($view->result), 11); } + /** + * + */ function viewPagerFullZeroItemsPerPage() { - $view = new view; + $view = new view(); $view->name = 'view_pager_full_zero_items_per_page'; $view->description = ''; $view->tag = ''; @@ -353,8 +375,11 @@ class ViewsPagerTest extends ViewsSqlTest { return $view; } + /** + * + */ function viewsPagerFull() { - $view = new view; + $view = new view(); $view->name = 'test_pager_full'; $view->description = ''; $view->tag = ''; @@ -379,8 +404,11 @@ class ViewsPagerTest extends ViewsSqlTest { return $view; } + /** + * + */ function viewsPagerFullFields() { - $view = new view; + $view = new view(); $view->name = 'test_pager_full'; $view->description = ''; $view->tag = ''; @@ -421,22 +449,24 @@ class ViewsPagerTest extends ViewsSqlTest { * Tests the minipager. */ public function testMiniPager() { - // the functionality is the same as the normal pager, so i don't know what to test here. + // The functionality is the same as the normal pager, so i don't know what + // to test here. } /** * Tests rendering with NULL pager. */ public function testRenderNullPager() { - // Create 11 nodes and make sure that everyone is returned. - // We create 11 nodes, because the default pager plugin had 10 items per page. + // Create 11 nodes and make sure that everyone is returned. We create 11 + // nodes, because the default pager plugin had 10 items per page. for ($i = 0; $i < 11; $i++) { $this->drupalCreateNode(); } $view = $this->viewsPagerFullFields(); $view->set_display('default'); $this->executeView($view); - $view->use_ajax = TRUE; // force the value again here + $view->use_ajax = TRUE; + // force the value again here. $view->query->pager = NULL; $output = $view->render(); $this->assertEqual(preg_match('//', $output), 0, t('The pager is not rendered.')); @@ -448,7 +478,6 @@ class ViewsPagerTest extends ViewsSqlTest { function testPagerApi() { $view = $this->viewsPagerFull(); // On the first round don't initialize the pager. - $this->assertEqual($view->get_items_per_page(), NULL, 'If the pager is not initialized and no manual override there is no items per page.'); $rand_number = rand(1, 5); $view->set_items_per_page($rand_number); @@ -491,6 +520,6 @@ class ViewsPagerTest extends ViewsSqlTest { $rand_number = rand(6, 11); $view->query->pager->set_current_page($rand_number); $this->assertEqual($view->get_current_page(), $rand_number, 'Make sure get_current_page uses the settings of set_current_page.'); - } + } diff --git a/sites/all/modules/views/tests/views_plugin_localization_test.inc b/sites/all/modules/views/tests/views_plugin_localization_test.inc index 1987fd8..ce90dff 100644 --- a/sites/all/modules/views/tests/views_plugin_localization_test.inc +++ b/sites/all/modules/views/tests/views_plugin_localization_test.inc @@ -9,15 +9,17 @@ * A stump localisation plugin which has static variables to cache the input. */ class views_plugin_localization_test extends views_plugin_localization { + /** * Store the strings which was translated. */ - var $translated_strings; + public $translated_strings; + /** * Return the string and take sure that the test can find out whether the * string got translated. */ - function translate_string($string, $keys = array(), $format = '') { + public function translate_string($string, $keys = array(), $format = '') { $this->translated_strings[] = $string; return $string . "-translated"; } @@ -25,7 +27,7 @@ class views_plugin_localization_test extends views_plugin_localization { /** * Store the export strings. */ - function export($source) { + public function export($source) { if (!empty($source['value'])) { $this->export_strings[] = $source['value']; } @@ -34,7 +36,8 @@ class views_plugin_localization_test extends views_plugin_localization { /** * Return the stored strings for the simpletest. */ - function get_export_strings() { + public function get_export_strings() { return $this->export_strings; } + } diff --git a/sites/all/modules/views/tests/views_query.test b/sites/all/modules/views/tests/views_query.test index db7d656..ed10f3b 100644 --- a/sites/all/modules/views/tests/views_query.test +++ b/sites/all/modules/views/tests/views_query.test @@ -2,13 +2,24 @@ /** * @file - * Tests for Views query features. + * Abstract class for views testing. */ /** - * Abstract class for views testing. + * */ abstract class ViewsTestCase extends DrupalWebTestCase { + + /** + * + */ + protected $sort_column = NULL; + + /** + * + */ + protected $sort_order = 1; + /** * Helper function: verify a result set returned by view. * @@ -16,13 +27,13 @@ abstract class ViewsTestCase extends DrupalWebTestCase { * column map, taking the order of the rows into account, but not the order * of the columns. * - * @param $view - * An executed View. - * @param $expected_result - * An expected result set. - * @param $column_map - * An associative array mapping the columns of the result set from the view - * (as keys) and the expected result set (as values). + * @param view $view + * An executed View. + * @param array $expected_result + * An expected result set. + * @param array $column_map + * An associative array mapping the columns of the result set from the view + * (as keys) and the expected result set (as values). */ protected function assertIdenticalResultset($view, $expected_result, $column_map = array(), $message = 'Identical result set') { return $this->assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, 'assertIdentical'); @@ -33,25 +44,29 @@ abstract class ViewsTestCase extends DrupalWebTestCase { * * Inverse of ViewsTestCase::assertIdenticalResultset(). * - * @param $view - * An executed View. - * @param $expected_result - * An expected result set. - * @param $column_map - * An associative array mapping the columns of the result set from the view - * (as keys) and the expected result set (as values). + * @param view $view + * An executed View. + * @param array $expected_result + * An expected result set. + * @param array $column_map + * An associative array mapping the columns of the result set from the view + * (as keys) and the expected result set (as values). */ protected function assertNotIdenticalResultset($view, $expected_result, $column_map = array(), $message = 'Identical result set') { return $this->assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, 'assertNotIdentical'); } + /** + * + */ protected function assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, $assert_method) { // Convert $view->result to an array of arrays. $result = array(); foreach ($view->result as $key => $value) { $row = array(); foreach ($column_map as $view_column => $expected_column) { - // The comparison will be done on the string representation of the value. + // The comparison will be done on the string representation of the + // value. $row[$expected_column] = (string) $value->$view_column; } $result[$key] = $row; @@ -61,7 +76,8 @@ abstract class ViewsTestCase extends DrupalWebTestCase { foreach ($expected_result as $key => $value) { $row = array(); foreach ($column_map as $expected_column) { - // The comparison will be done on the string representation of the value. + // The comparison will be done on the string representation of the + // value. $row[$expected_column] = (string) (is_object($value) ? $value->$expected_column : $value[$expected_column]); } $expected_result[$key] = $row; @@ -71,14 +87,14 @@ abstract class ViewsTestCase extends DrupalWebTestCase { $result = array_values($result); $expected_result = array_values($expected_result); - $this->verbose('
Returned data set: ' . print_r($result, TRUE) . "\n\nExpected: ". print_r($expected_result, TRUE)); + $this->verbose('Returned data set: ' . print_r($result, TRUE) . "\n\nExpected: " . print_r($expected_result, TRUE)); // Do the actual comparison. return $this->$assert_method($result, $expected_result, $message); } /** - * Helper function: order an array of array based on a column. + * Order an array of array based on a column. */ protected function orderResultSet($result_set, $column, $reverse = FALSE) { $this->sort_column = $column; @@ -87,9 +103,6 @@ abstract class ViewsTestCase extends DrupalWebTestCase { return $result_set; } - protected $sort_column = NULL; - protected $sort_order = 1; - /** * Helper comparison function for orderResultSet(). */ @@ -97,20 +110,20 @@ abstract class ViewsTestCase extends DrupalWebTestCase { $value1 = $a[$this->sort_column]; $value2 = $b[$this->sort_column]; if ($value1 == $value2) { - return 0; + return 0; } return $this->sort_order * (($value1 < $value2) ? -1 : 1); } /** - * Helper function to check whether a button with a certain id exists and has a certain label. + * Check whether a button with a certain id exists and has a certain label. */ protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') { return $this->assertFieldById($id, $expected_label, t($message, array('%label' => $expected_label))); } /** - * Helper function to execute a view with debugging. + * Execute a view with debugging. * * @param view $view * @param array $args @@ -121,14 +134,56 @@ abstract class ViewsTestCase extends DrupalWebTestCase { $view->execute(); $this->verbose('Executed view: ' . ((string) $view->build_info['query']) . ''); } + + /** + * Log in as user 1. + */ + protected function loginUser1() { + $password = user_password(); + // Reset the user 1 password. + $account = user_load(1); + $edit = array( + 'pass' => $password, + ); + $account = user_save($account, $edit); + $account->pass_raw = $password; + + // Log in as user 1. + $this->drupalLogin($account); + } + + /** + * {@inheritdoc} + */ + protected function verbose($message, $title = NULL) { + // Handle arrays, objects, etc. + if (!is_string($message)) { + $message = "\n" . print_r($message, TRUE) . "\n\n"; + } + + // Optional title to go before the output. + if (!empty($title)) { + $title = '' . check_plain($title) . "
\n"; + } + + parent::verbose($title . $message); + } + } +/** + * + */ abstract class ViewsSqlTest extends ViewsTestCase { + /** + * {@inheritdoc} + */ protected function setUp() { parent::setUp('views', 'views_ui'); - // Define the schema and views data variable before enabling the test module. + // Define the schema and views data variable before enabling the test + // module. variable_set('views_test_schema', $this->schemaDefinition()); variable_set('views_test_views_data', $this->viewsData()); variable_set('views_test_views_plugins', $this->viewsPlugins()); @@ -147,14 +202,32 @@ abstract class ViewsSqlTest extends ViewsTestCase { } /** - * This function allows to enable views ui from a higher class which can't change the setup function anymore. + * Create a term. * - * @TODO - * Convert existing setUp functions. + * @param int $vid + * The vocabulary ID that the term is to be added to. + * + * @return object + * A full term object with a random name. + */ + protected function drupalCreateTerm($vid) { + $term = new stdClass(); + $term->name = $this->randomName(); + $term->description = $this->randomName(); + $term->vid = $vid; + taxonomy_term_save($term); + return $term; + } + + /** + * This function allows to enable views ui from a higher class which can't + * change the setup function anymore. + * + * @todo Convert existing setUp functions. */ function enableViewsUi() { module_enable(array('views_ui')); - // @TODO Figure out why it's required to clear the cache here. + // @todo Figure out why it's required to clear the cache here. views_module_include('views_default', TRUE); views_get_all_views(TRUE); menu_rebuild(); @@ -202,7 +275,7 @@ abstract class ViewsSqlTest extends ViewsTestCase { ), 'primary key' => array('id'), 'unique keys' => array( - 'name' => array('name') + 'name' => array('name'), ), 'indexes' => array( 'ages' => array('age'), @@ -314,6 +387,9 @@ abstract class ViewsSqlTest extends ViewsTestCase { return $data; } + /** + * + */ protected function viewsPlugins() { return array(); } @@ -422,11 +498,12 @@ abstract class ViewsSqlTest extends ViewsTestCase { views_include('view'); $view = $this->getBasicView(); - // In order to test exposed filters, we have to disable - // the exposed forms cache. + // In order to test exposed filters, we have to disable the exposed forms + // cache. drupal_static_reset('views_exposed_form_cache'); $display = $view->new_display('page', 'Page', 'page_1'); return $view; } + } diff --git a/sites/all/modules/views/tests/views_test.info b/sites/all/modules/views/tests/views_test.info index c23f6c0..d7e7921 100644 --- a/sites/all/modules/views/tests/views_test.info +++ b/sites/all/modules/views/tests/views_test.info @@ -5,9 +5,8 @@ core = 7.x dependencies[] = views hidden = TRUE -; Information added by Drupal.org packaging script on 2017-08-23 -version = "7.x-3.18" +; Information added by Drupal.org packaging script on 2019-05-10 +version = "7.x-3.23" core = "7.x" project = "views" -datestamp = "1503495103" - +datestamp = "1557505389" diff --git a/sites/all/modules/views/tests/views_test.module b/sites/all/modules/views/tests/views_test.module index be533e0..caa87b9 100644 --- a/sites/all/modules/views/tests/views_test.module +++ b/sites/all/modules/views/tests/views_test.module @@ -35,7 +35,7 @@ function views_test_views_data() { $count = variable_get('views_test_views_data_count', 0); $count++; variable_set('views_test_views_data_count', $count); - return variable_get('views_test_views_data', array()); + return variable_get('views_test_views_data', array()); } /** diff --git a/sites/all/modules/views/tests/views_test.views_default.inc b/sites/all/modules/views/tests/views_test.views_default.inc index fa49acb..a494a4e 100644 --- a/sites/all/modules/views/tests/views_test.views_default.inc +++ b/sites/all/modules/views/tests/views_test.views_default.inc @@ -9,7 +9,7 @@ * Implements hook_views_default_views(). */ function views_test_views_default_views() { - $view = new view; + $view = new view(); $view->name = 'test_views_groupby_save'; $view->description = ''; $view->tag = ''; @@ -31,7 +31,7 @@ function views_test_views_default_views() { $views[$view->name] = $view; - $view = new view; + $view = new view(); $view->name = 'test_rename_reset_button'; $view->description = ''; $view->tag = ''; @@ -70,7 +70,7 @@ function views_test_views_default_views() { $views[$view->name] = $view; - $view = new view; + $view = new view(); $view->name = 'test_exposed_admin_ui'; $view->description = ''; $view->tag = ''; @@ -110,7 +110,7 @@ function views_test_views_default_views() { $views[$view->name] = $view; - $view = new view; + $view = new view(); $view->name = 'test_filter_in_operator_ui'; $view->description = ''; $view->tag = ''; @@ -142,7 +142,7 @@ function views_test_views_default_views() { $views[$view->name] = $view; - $view = new view; + $view = new view(); $view->name = 'test_argument_default_current_user'; $view->description = ''; $view->tag = ''; diff --git a/sites/all/modules/views/tests/views_translatable.test b/sites/all/modules/views/tests/views_translatable.test index 983a97e..9c3422c 100644 --- a/sites/all/modules/views/tests/views_translatable.test +++ b/sites/all/modules/views/tests/views_translatable.test @@ -31,7 +31,7 @@ class ViewsTranslatableTest extends ViewsSqlTest { 'help' => t('This is a test description.'), 'handler' => 'views_plugin_localization_test', 'parent' => 'parent', - 'path' => drupal_get_path('module', 'views') .'/tests', + 'path' => drupal_get_path('module', 'views') . '/tests', ), ), ); @@ -100,7 +100,6 @@ class ViewsTranslatableTest extends ViewsSqlTest { $view->init_display(); // Don't run translation. We just want to get the right keys. - foreach ($view->display as $display_id => $display) { $translatables = array(); $display->handler->unpack_translatables($translatables); @@ -145,7 +144,7 @@ class ViewsTranslatableTest extends ViewsSqlTest { } public function view_unpack_translatable() { - $view = new view; + $view = new view(); $view->name = 'view_unpack_translatable'; $view->description = ''; $view->tag = ''; @@ -218,4 +217,5 @@ class ViewsTranslatableTest extends ViewsSqlTest { return $view; } + } diff --git a/sites/all/modules/views/tests/views_ui.test b/sites/all/modules/views/tests/views_ui.test index 8785539..8a7e0e1 100644 --- a/sites/all/modules/views/tests/views_ui.test +++ b/sites/all/modules/views/tests/views_ui.test @@ -9,6 +9,10 @@ * Views UI wizard tests. */ class ViewsUIWizardHelper extends DrupalWebTestCase { + + /** + * + */ function setUp() { // Enable views_ui. parent::setUp('views_ui'); @@ -17,12 +21,17 @@ class ViewsUIWizardHelper extends DrupalWebTestCase { $views_admin = $this->drupalCreateUser(array('administer views', 'administer blocks', 'bypass node access', 'access user profiles', 'view revisions')); $this->drupalLogin($views_admin); } + } /** * Tests creating views with the wizard and viewing them on the listing page. */ class ViewsUIWizardBasicTestCase extends ViewsUIWizardHelper { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Views UI wizard basic functionality', @@ -31,6 +40,9 @@ class ViewsUIWizardBasicTestCase extends ViewsUIWizardHelper { ); } + /** + * + */ function testViewsWizardAndListing() { // Check if we can access the main views admin page. $this->drupalGet('admin/structure/views'); @@ -46,7 +58,7 @@ class ViewsUIWizardBasicTestCase extends ViewsUIWizardHelper { $this->assertText(t('Your view was saved. You may edit it from the list below.')); $this->assertText($view1['human_name']); $this->assertText($view1['description']); - foreach(array('delete', 'clone', 'edit') as $operation) { + foreach (array('delete', 'clone', 'edit') as $operation) { $this->assertLinkByHref(url('admin/structure/views/view/' . $view1['name'] . '/' . $operation)); } @@ -146,12 +158,17 @@ class ViewsUIWizardBasicTestCase extends ViewsUIWizardHelper { // Make sure the listing page doesn't show disabled default views. $this->assertNoText('tracker', t('Default tracker view does not show on the listing page.')); } + } /** * Tests enabling, disabling, and reverting default views via the listing page. */ class ViewsUIWizardDefaultViewsTestCase extends ViewsUIWizardHelper { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Views UI default views functionality', @@ -168,10 +185,9 @@ class ViewsUIWizardDefaultViewsTestCase extends ViewsUIWizardHelper { // the listing page). $edit_href = 'admin/structure/views/view/frontpage/edit'; $this->drupalGet('admin/structure/views'); - // TODO: Disabled default views do now appear on the front page. Test this + // @todo Disabled default views do now appear on the front page. Test this // behavior with templates instead. // $this->assertNoLinkByHref($edit_href); - // Enable the front page view, and make sure it is now visible on the main // listing page. $this->drupalGet('admin/structure/views/templates'); @@ -205,7 +221,7 @@ class ViewsUIWizardDefaultViewsTestCase extends ViewsUIWizardHelper { // Now disable the view, and make sure it stops appearing on the main view // listing page but instead goes back to displaying on the disabled views // listing page. - // TODO: Test this behavior with templates instead. + // @todo Test this behavior with templates instead. $this->drupalGet('admin/structure/views'); $this->clickViewsOperationLink(t('Disable'), '/frontpage/'); // $this->assertUrl('admin/structure/views'); @@ -225,15 +241,15 @@ class ViewsUIWizardDefaultViewsTestCase extends ViewsUIWizardHelper { * various views listing pages, and they might have tokens in them. So we * need special code to find the correct one to click. * - * @param $label + * @param string $label * Text between the anchor tags of the desired link. - * @param $unique_href_part + * @param string $unique_href_part * A unique string that is expected to occur within the href of the desired * link. For example, if the link URL is expected to look like * "admin/structure/views/view/frontpage/...", then "/frontpage/" could be * passed as the expected unique string. * - * @return + * @return string * The page content that results from clicking on the link, or FALSE on * failure. Failure also results in a failed assertion. */ @@ -254,18 +270,42 @@ class ViewsUIWizardDefaultViewsTestCase extends ViewsUIWizardHelper { return FALSE; } } + } /** * Tests the ability of the views wizard to create views filtered by taxonomy. */ class ViewsUIWizardTaggedWithTestCase extends ViewsUIWizardHelper { + + /** + * + */ protected $node_type_with_tags; + + /** + * + */ protected $node_type_without_tags; + + /** + * + */ protected $tag_vocabulary; + + /** + * + */ protected $tag_field; + + /** + * + */ protected $tag_instance; + /** + * + */ public static function getInfo() { return array( 'name' => 'Views UI wizard taxonomy functionality', @@ -274,6 +314,9 @@ class ViewsUIWizardTaggedWithTestCase extends ViewsUIWizardHelper { ); } + /** + * {@inheritdoc} + */ function setUp() { parent::setUp(); @@ -392,7 +435,7 @@ class ViewsUIWizardTaggedWithTestCase extends ViewsUIWizardHelper { } /** - * Tests that the "tagged with" form element only shows for node types that support it. + * Test the "tagged with" form element only shows for node types that support it. */ function testTaggedWithByNodeType() { // The tagging field is associated with one of our node types only. So the @@ -422,12 +465,17 @@ class ViewsUIWizardTaggedWithTestCase extends ViewsUIWizardHelper { $this->drupalPost(NULL, $view, t('Update "of type" choice')); $this->assertFieldByXpath($tags_xpath); } + } /** * Tests the ability of the views wizard to create views with sorts. */ class ViewsUIWizardSortingTestCase extends ViewsUIWizardHelper { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Views UI wizard sorting functionality', @@ -492,12 +540,17 @@ class ViewsUIWizardSortingTestCase extends ViewsUIWizardHelper { $pos1 = strpos($content, $node1->title); $this->assertTrue($pos3 < $pos2 && $pos2 < $pos1, t('The nodes appear in the expected order in a view that sorts by newest first.')); } + } /** - * Tests the ability of the views wizard to specify the number of items per page. + * Tests the ability of the wizard to specify the number of items per page. */ class ViewsUIWizardItemsPerPageTestCase extends ViewsUIWizardHelper { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Views UI wizard items per page functionality', @@ -577,12 +630,17 @@ class ViewsUIWizardItemsPerPageTestCase extends ViewsUIWizardHelper { $pos3 = strpos($content, $node3->title); $this->assertTrue($pos5 < $pos4 && $pos4 < $pos3, t('The nodes appear in the expected order in the block display.')); } + } /** * Tests the ability of the views wizard to put views in a menu. */ class ViewsUIWizardMenuTestCase extends ViewsUIWizardHelper { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Views UI wizard menu functionality', @@ -625,12 +683,17 @@ class ViewsUIWizardMenuTestCase extends ViewsUIWizardHelper { } $this->assertTrue($found, t('Found a link to %path in the main menu', array('%path' => $view['page[path]']))); } + } /** - * Tests the ability of the views wizard to create views with a jump menu style plugin. + * Tests the ability of the wizard to create views with a jump menu style. */ class ViewsUIWizardJumpMenuTestCase extends ViewsUIWizardHelper { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Views UI wizard jump menu functionality', @@ -683,7 +746,6 @@ class ViewsUIWizardJumpMenuTestCase extends ViewsUIWizardHelper { // Submit the jump menu form, and check that we are redirected to the // expected URL. - $edit = array(); $edit['jump'] = url($path, $options); @@ -786,12 +848,17 @@ class ViewsUIWizardJumpMenuTestCase extends ViewsUIWizardHelper { node_save($node); return 'node/' . $node->nid . '/revisions/' . $node->vid . '/view'; } + } /** * Tests that displays can be correctly overridden via the user interface. */ class ViewsUIWizardOverrideDisplaysTestCase extends ViewsUIWizardHelper { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Views UI overridden displays', @@ -948,9 +1015,8 @@ class ViewsUIWizardOverrideDisplaysTestCase extends ViewsUIWizardHelper { * Tests that the revert to all displays select-option works as expected. */ function testRevertAllDisplays() { - // Create a basic view with a page, block. - // Because there is both a title on page and block we expect the title on - // the block be overriden. + // Create a basic view with a page, block. Because there is both a title on + // page and block we expect the title on the block be overriden. $view['human_name'] = $this->randomName(16); $view['name'] = strtolower($this->randomName(16)); $view['page[create]'] = 1; @@ -970,4 +1036,5 @@ class ViewsUIWizardOverrideDisplaysTestCase extends ViewsUIWizardHelper { $this->drupalPost("admin/structure/views/view/{$view['name']}/edit/block", array(), t('Save')); $this->assertText($view['page[title]']); } + } diff --git a/sites/all/modules/views/tests/views_upgrade.test b/sites/all/modules/views/tests/views_upgrade.test index 3f453db..0c4da8f 100644 --- a/sites/all/modules/views/tests/views_upgrade.test +++ b/sites/all/modules/views/tests/views_upgrade.test @@ -11,6 +11,10 @@ * You can find all conversions by searching for "moved to". */ class ViewsUpgradeTestCase extends ViewsSqlTest { + + /** + * + */ public static function getInfo() { return array( 'name' => 'Views Upgrade test', @@ -19,14 +23,21 @@ class ViewsUpgradeTestCase extends ViewsSqlTest { ); } + /** + * {@inheritdoc} + */ protected function setUp() { -// // To import a view the user needs use PHP for settings rights, so enable php module. + // To import a view the user needs use PHP for settings rights, so enable + // PHP module. parent::setUp(); module_enable(array('php')); $this->resetAll(); } + /** + * + */ function viewsData() { $data = parent::viewsData(); $data['views_test']['old_field_1']['moved to'] = array('views_test', 'id'); @@ -41,6 +52,9 @@ class ViewsUpgradeTestCase extends ViewsSqlTest { return $data; } + /** + * + */ function debugField($field) { $keys = array('id', 'table', 'field', 'actual_field', 'original_field', 'real_field'); $info = array(); @@ -59,8 +73,11 @@ class ViewsUpgradeTestCase extends ViewsSqlTest { $view->update(); $view->build(); -// $this->assertEqual('old_field_1', $view->field['old_field_1']->options['id'], "Id shouldn't change during conversion"); -// $this->assertEqual('id', $view->field['old_field_1']->field, 'The field should change during conversion'); + // $this->assertEqual('old_field_1', + // $view->field['old_field_1']->options['id'], + // "Id shouldn't change during conversion"); + // $this->assertEqual('id', $view->field['old_field_1']->field, + // 'The field should change during conversion'); $this->assertEqual('id', $view->field['old_field_1']->real_field); $this->assertEqual('views_test', $view->field['old_field_1']->table); $this->assertEqual('old_field_1', $view->field['old_field_1']->original_field, 'The field should have stored the original_field'); @@ -70,11 +87,13 @@ class ViewsUpgradeTestCase extends ViewsSqlTest { $view->update(); $view->build(); -// $this->assertEqual('old_field_2', $view->field['old_field_2']->options['id']); + // $this->assertEqual('old_field_2', + // $view->field['old_field_2']->options['id']); $this->assertEqual('name', $view->field['old_field_2']->real_field); $this->assertEqual('views_test', $view->field['old_field_2']->table); -// $this->assertEqual('old_field_3', $view->filter['old_field_3']->options['id']); + // $this->assertEqual('old_field_3', + // $view->filter['old_field_3']->options['id']); $this->assertEqual('age', $view->filter['old_field_3']->real_field); $this->assertEqual('views_test', $view->filter['old_field_3']->table); @@ -84,7 +103,8 @@ class ViewsUpgradeTestCase extends ViewsSqlTest { $view->build(); $this->assertEqual('views_test', $view->base_table, 'Make sure that view->base_table gets automatically converted.'); -// $this->assertEqual('id', $view->field['id']->field, 'If we move a whole table fields of this table should work, too.'); + // $this->assertEqual('id', $view->field['id']->field, + // 'If we move a whole table fields of this table should work, too.'); $this->assertEqual('id', $view->field['id']->real_field, 'To run the query right the real_field has to be set right.'); $this->assertEqual('views_test', $view->field['id']->table); } @@ -106,8 +126,11 @@ class ViewsUpgradeTestCase extends ViewsSqlTest { $this->assertText('Recent comments'); } + /** + * + */ public function viewsMovedToField() { - $view = new view; + $view = new view(); $view->name = 'test_views_move_to_field'; $view->description = ''; $view->tag = ''; @@ -127,8 +150,11 @@ class ViewsUpgradeTestCase extends ViewsSqlTest { return $view; } + /** + * + */ public function viewsMovedToHandler() { - $view = new view; + $view = new view(); $view->name = 'test_views_move_to_handler'; $view->description = ''; $view->tag = ''; @@ -152,8 +178,11 @@ class ViewsUpgradeTestCase extends ViewsSqlTest { return $view; } + /** + * + */ public function viewsMovedToTable() { - $view = new view; + $view = new view(); $view->name = 'test_views_move_to_table'; $view->description = ''; $view->tag = ''; @@ -173,6 +202,9 @@ class ViewsUpgradeTestCase extends ViewsSqlTest { return $view; } + /** + * + */ protected function viewUpgradeImport() { $import = ' $view = new view; @@ -272,6 +304,7 @@ class ViewsUpgradeTestCase extends ViewsSqlTest { $handler->display->display_options["block_description"] = "Recent comments view" ;'; - return $import; + return $import; } + } diff --git a/sites/all/modules/views/tests/views_view.test b/sites/all/modules/views/tests/views_view.test index e72e811..489864a 100644 --- a/sites/all/modules/views/tests/views_view.test +++ b/sites/all/modules/views/tests/views_view.test @@ -2,26 +2,27 @@ /** * @file - * Definition of ViewsViewTest. + * Views class tests. */ /** - * Views class tests. * - * @codingStandardsIgnoreStart */ class ViewsViewTest extends ViewsSqlTest { - // @codingStandardsIgnoreEnd + + /** + * Provide the test's meta information. + */ public static function getInfo() { return array( 'name' => 'Test the view class', - 'description' => 'Tests some functionality of the view class', + 'description' => 'Tests some functionality of the view class', 'group' => 'Views', ); } /** - * Tests the deconstructor to be sure that every kind of heavy objects are removed. + * Ensure that every kind of heavy objects are removed by the destructor. */ function testDestroy() { $view = $this->view_test_destroy(); @@ -39,6 +40,12 @@ class ViewsViewTest extends ViewsSqlTest { $this->assertViewDestroy($view); } + /** + * Assert that a given view is destroyed properly. + * + * @param object $view + * The view to destroy. + */ function assertViewDestroy($view) { $this->assertFalse(isset($view->display['default']->handler), 'Make sure all displays are destroyed.'); $this->assertFalse(isset($view->display['attachment_1']->handler), 'Make sure all displays are destroyed.'); @@ -61,8 +68,11 @@ class ViewsViewTest extends ViewsSqlTest { $this->assertEqual($view->attachment_after, ''); } + /** + * Test deleting a view. + */ function testDelete() { - // Delete a database view + // Delete a database view. $view = $this->view_test_delete(); $view->save(); $view = views_get_view($view->name); @@ -75,10 +85,13 @@ class ViewsViewTest extends ViewsSqlTest { $this->assertNull($view, "Make sure that the old view gets cleared by the reset parameter."); } + /** + * Test validation. + */ function testValidate() { // Test a view with multiple displays. // Validating a view shouldn't change the active display. - // @todo: Create an extra validation view. + // @todo Create an extra validation view. $view = $this->view_test_destroy(); $view->set_display('page_1'); @@ -86,17 +99,20 @@ class ViewsViewTest extends ViewsSqlTest { $this->assertEqual('page_1', $view->current_display, "The display should be constant while validating"); - // @todo: Write real tests for the validation. + // @todo Write real tests for the validation. // In general the following things could be tested: - // - Deleted displays shouldn't be validated + // - Deleted displays shouldn't be validated. // - Multiple displays are validating and the errors are merged together. } /** - * This view provides some filters, fields, arguments, relationships, sorts, areas and attachments. + * Generate an example view. + * + * Includes: + * filters, fields, arguments, relationships, sorts, areas and attachments. */ function view_test_destroy() { - $view = new view; + $view = new view(); $view->name = 'test_destroy'; $view->description = ''; $view->tag = ''; @@ -257,8 +273,12 @@ class ViewsViewTest extends ViewsSqlTest { return $view; } + + /** + * Creates a test view. + */ function view_test_delete() { - $view = new view; + $view = new view(); $view->name = 'test_view_delete'; $view->description = ''; $view->tag = ''; @@ -294,4 +314,5 @@ class ViewsViewTest extends ViewsSqlTest { return $view; } + } diff --git a/sites/all/modules/views/theme/theme.inc b/sites/all/modules/views/theme/theme.inc index befd4d1..99b8efe 100644 --- a/sites/all/modules/views/theme/theme.inc +++ b/sites/all/modules/views/theme/theme.inc @@ -8,11 +8,11 @@ /** * Provide a full array of possible themes to try for a given hook. * - * @param $hook + * @param string $hook * The hook to use. This is the base theme/template name. - * @param $view + * @param object $view * The view being rendered. - * @param $display + * @param object $display * The display being rendered, if applicable. */ function _views_theme_functions($hook, $view, $display = NULL) { @@ -52,7 +52,7 @@ function template_preprocess_views_view(&$vars) { $vars['name'] = $view->name; $vars['display_id'] = $view->current_display; - // Basic classes + // Basic classes. $vars['css_class'] = ''; $vars['classes_array'] = array(); @@ -81,7 +81,7 @@ function template_preprocess_views_view(&$vars) { $vars['pager'] = ''; - // @todo: Figure out whether this belongs into views_ui_preprocess_views_view. + // @todo Figure out whether this belongs into views_ui_preprocess_views_view. // Render title for the admin preview. $vars['title'] = !empty($view->views_ui_context) ? filter_xss_admin($view->get_title()) : ''; @@ -104,15 +104,15 @@ function template_preprocess_views_view(&$vars) { // Attachments are always updated with the outer view, never by themselves, // so they do not have dom ids. if (empty($view->is_attachment)) { - // Our JavaScript needs to have some means to find the HTML belonging to this - // view. + // Our JavaScript needs to have some means to find the HTML belonging to + // this view. // // It is true that the DIV wrapper has classes denoting the name of the view // and its display ID, but this is not enough to unequivocally match a view // with its HTML, because one view may appear several times on the page. So - // we set up a hash with the current time, $dom_id, to issue a "unique" identifier for - // each view. This identifier is written to both Drupal.settings and the DIV - // wrapper. + // we set up a hash with the current time, $dom_id, to issue a "unique" + // identifier for each view. This identifier is written to both + // Drupal.settings and the DIV wrapper. $vars['dom_id'] = $view->dom_id; $vars['classes_array'][] = 'view-dom-id-' . $vars['dom_id']; } @@ -129,7 +129,9 @@ function template_preprocess_views_view(&$vars) { 'view_args' => check_plain(implode('/', $view->args)), 'view_path' => check_plain($_GET['q']), // Pass through URL to ensure we get e.g. language prefixes. -// 'view_base_path' => isset($view->display['page']) ? substr(url($view->display['page']->display_options['path']), strlen($base_path)) : '', + // 'view_base_path' => isset($view->display['page']) ? + // substr(url($view->display['page']->display_options['path']), + // strlen($base_path)) : '', 'view_base_path' => $view->get_path(), 'view_dom_id' => $vars['dom_id'], // To fit multiple views on a page, the programmer may have @@ -179,16 +181,17 @@ function template_process_views_view(&$vars) { } /** - * Preprocess theme function to print a single record from a row, with fields + * Preprocess theme function to print a single record from a row, with fields. */ function template_preprocess_views_view_fields(&$vars) { $view = $vars['view']; // Loop through the fields for this view. $previous_inline = FALSE; - $vars['fields'] = array(); // ensure it's at least an empty array. + $vars['fields'] = array(); + // Ensure it's at least an empty array. foreach ($view->field as $id => $field) { - // render this even if set to exclude so it can be used elsewhere. + // Render this even if set to exclude so it can be used elsewhere. $field_output = $view->style_plugin->get_field($view->row_index, $id); $empty = $field->is_value_empty($field_output, $field->options['empty_zero']); if (empty($field->options['exclude']) && (!$empty || (empty($field->options['hide_empty']) && empty($vars['options']['hide_empty'])))) { @@ -207,7 +210,7 @@ function template_preprocess_views_view_fields(&$vars) { if ($class) { $class .= ' '; } - $class .= $classes; + $class .= $classes; } $pre = '<' . $object->element_type; @@ -218,7 +221,8 @@ function template_preprocess_views_view_fields(&$vars) { } // Protect ourself somewhat for backward compatibility. This will prevent - // old templates from producing invalid HTML when no element type is selected. + // old templates from producing invalid HTML when no element type is + // selected. if (empty($object->element_type)) { $object->element_type = 'span'; } @@ -228,7 +232,8 @@ function template_preprocess_views_view_fields(&$vars) { $object->raw = $vars['row']->{$view->field[$id]->field_alias}; } else { - $object->raw = NULL; // make sure it exists to reduce NOTICE + // Make sure it exists to reduce NOTICE. + $object->raw = NULL; } if (!empty($vars['options']['separator']) && $previous_inline && $object->inline && $object->content) { @@ -268,8 +273,8 @@ function template_preprocess_views_view_fields(&$vars) { $object->wrapper_suffix = '' . $object->inline_html . '>'; } - // Set up the label for the value and the HTML to make it easier - // on the template. + // Set up the label for the value and the HTML to make it easier on the + // template. $object->label = check_plain($view->field[$id]->label()); $object->label_html = ''; if ($object->label) { @@ -307,7 +312,6 @@ function template_preprocess_views_view_fields(&$vars) { $vars['fields'][$id] = $object; } } - } /** @@ -320,7 +324,7 @@ function theme_views_view_grouping($vars) { $output = ''; $output .= ''; return $output; @@ -338,7 +342,7 @@ function template_preprocess_views_view_grouping(&$vars) { * * Interesting bits of info: * $field->field_alias says what the raw value in $row will be. Reach it like - * this: @code { $row->{$field->field_alias} @endcode + * this: @code { $row->{$field->field_alias} @endcode. */ function theme_views_view_field($vars) { $view = $vars['view']; @@ -359,7 +363,7 @@ function template_preprocess_views_view_field(&$vars) { } /** - * Preprocess theme function to print a single record from a row, with fields + * Preprocess theme function to print a single record from a row, with fields. */ function template_preprocess_views_view_summary(&$vars) { $view = $vars['view']; @@ -373,12 +377,17 @@ function template_preprocess_views_view_summary(&$vars) { } $active_urls = drupal_map_assoc(array( - url($_GET['q'], array('alias' => TRUE)), // force system path - url($_GET['q']), // could be an alias + // Force system path. + url($_GET['q'], array('alias' => TRUE)), + url($_GET['q'], $url_options + array('alias' => TRUE)), + // Could be an alias. + url($_GET['q']), + url($_GET['q'], $url_options), )); - // Collect all arguments foreach row, to be able to alter them for example by the validator. - // This is not done per single argument value, because this could cause performance problems. + // Collect all arguments foreach row, to be able to alter them for example by + // the validator. This is not done per single argument value, because this + // could cause performance problems. $row_args = array(); foreach ($vars['rows'] as $id => $row) { @@ -406,8 +415,7 @@ function template_preprocess_views_view_summary(&$vars) { } /** - * Template preprocess theme function to print summary basically - * unformatted. + * Template preprocess theme function to print summary basically unformatted. */ function template_preprocess_views_view_summary_unformatted(&$vars) { $view = $vars['view']; @@ -422,12 +430,17 @@ function template_preprocess_views_view_summary_unformatted(&$vars) { $count = 0; $active_urls = drupal_map_assoc(array( - url($_GET['q'], array('alias' => TRUE)), // force system path - url($_GET['q']), // could be an alias + // Force system path. + url($_GET['q'], array('alias' => TRUE)), + url($_GET['q'], $url_options + array('alias' => TRUE)), + // Could be an alias. + url($_GET['q']), + url($_GET['q'], $url_options), )); - // Collect all arguments foreach row, to be able to alter them for example by the validator. - // This is not done per single argument value, because this could cause performance problems. + // Collect all arguments foreach row, to be able to alter them for example by + // the validator. This is not done per single argument value, because this + // could cause performance problems. $row_args = array(); foreach ($vars['rows'] as $id => $row) { $row_args[$id] = $argument->summary_argument($row); @@ -435,7 +448,7 @@ function template_preprocess_views_view_summary_unformatted(&$vars) { $argument->process_summary_arguments($row_args); foreach ($vars['rows'] as $id => $row) { - // only false on first time: + // Only false on first time. if ($count++) { $vars['rows'][$id]->separator = filter_xss_admin($vars['options']['separator']); } @@ -461,18 +474,33 @@ function template_preprocess_views_view_summary_unformatted(&$vars) { function template_preprocess_views_view_table(&$vars) { $view = $vars['view']; - // We need the raw data for this grouping, which is passed in as $vars['rows']. - // However, the template also needs to use for the rendered fields. We - // therefore swap the raw data out to a new variable and reset $vars['rows'] - // so that it can get rebuilt. - // Store rows so that they may be used by further preprocess functions. + // We need the raw data for this grouping, which is passed in as + // $vars['rows']. However, the template also needs to use for the rendered + // fields. We therefore swap the raw data out to a new variable and reset + // $vars['rows'] so that it can get rebuilt. Store rows so that they may be + // used by further preprocess functions. $result = $vars['result'] = $vars['rows']; $vars['rows'] = array(); $vars['field_classes'] = array(); $vars['header'] = array(); + $vars['classes_array'] = array(); $options = $view->style_plugin->options; $handler = $view->style_plugin; + + if (!empty($handler->options['class'])) { + $classes = explode(' ', $handler->options['class']); + $classes = array_map('views_clean_css_identifier', $classes); + + if (!empty($classes)) { + // Trim empty class entries. + foreach ($classes as $key => $class) { + if (!empty($class)) { + $vars['classes_array'][] = $class; + } + } + } + } $default_row_class = isset($options['default_row_class']) ? $options['default_row_class'] : TRUE; $row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : TRUE; @@ -493,14 +521,14 @@ function template_preprocess_views_view_table(&$vars) { $renders = $handler->render_fields($result); foreach ($columns as $field => $column) { - // Create a second variable so we can easily find what fields we have and what the - // CSS classes should be. + // Create a second variable so we can easily find what fields we have and + // what the CSS classes should be. $vars['fields'][$field] = drupal_clean_css_identifier($field); if ($active == $field) { $vars['fields'][$field] .= ' active'; } - // render the header labels + // Render the header labels. if ($field == $column && empty($fields[$field]->options['exclude'])) { $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : ''); if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) { @@ -540,7 +568,7 @@ function template_preprocess_views_view_table(&$vars) { } $vars['header_classes'][$field] .= $class; } - // Add a CSS align class to each field if one was set + // Add a CSS align class to each field if one was set. if (!empty($options['info'][$field]['align'])) { $vars['header_classes'][$field] .= ' ' . drupal_clean_css_identifier($options['info'][$field]['align']); } @@ -552,17 +580,16 @@ function template_preprocess_views_view_table(&$vars) { $vars['header'][$field] = '<' . $element_label_type . '>' . $vars['header'][$field] . '' . $element_label_type . '>'; } } - } - // Add a CSS align class to each field if one was set + // Add a CSS align class to each field if one was set. if (!empty($options['info'][$field]['align'])) { $vars['fields'][$field] .= ' ' . drupal_clean_css_identifier($options['info'][$field]['align']); } // Render each field into its appropriate column. foreach ($result as $num => $row) { - // Add field classes + // Add field classes. $vars['field_classes'][$field][$num] = ''; if ($fields[$field]->options['element_default_classes']) { $vars['field_classes'][$field][$num] = "views-field views-field-" . $vars['fields'][$field]; @@ -602,7 +629,8 @@ function template_preprocess_views_view_table(&$vars) { } } - // Remove columns if the option is hide empty column is checked and the field is not empty. + // Remove columns if the option is hide empty column is checked and the + // field is not empty. if (!empty($options['info'][$field]['empty_column'])) { $empty = TRUE; foreach ($vars['rows'] as $num => $columns) { @@ -638,7 +666,7 @@ function template_preprocess_views_view_table(&$vars) { $vars['row_classes'][count($vars['row_classes']) - 1][] = 'views-row-last'; } - $vars['classes_array'] = array('views-table'); + $vars['classes_array'][] = 'views-table'; if (empty($vars['rows']) && !empty($options['empty_table'])) { $vars['rows'][0][0] = $view->display_handler->render_area('empty'); // Calculate the amounts of rows with output. @@ -646,12 +674,11 @@ function template_preprocess_views_view_table(&$vars) { $vars['field_classes'][0][0] = 'views-empty'; } - if (!empty($options['sticky'])) { drupal_add_js('misc/tableheader.js'); $vars['classes_array'][] = "sticky-enabled"; } - $vars['classes_array'][] = 'cols-'. count($vars['header']); + $vars['classes_array'][] = 'cols-' . count($vars['header']); // Add the summary to the list if set. if (!empty($handler->options['summary'])) { @@ -702,7 +729,7 @@ function template_preprocess_views_view_grid(&$vars) { } if ($row) { // Fill up the last line only if it's configured, but this is default. - if (!empty($handler->options['fill_single_line']) && count($rows)) { + if (!empty($handler->options['fill_single_line'])) { for ($i = 0; $i < ($columns - $col_count); $i++) { $row[] = ''; } @@ -731,33 +758,40 @@ function template_preprocess_views_view_grid(&$vars) { $remainders--; } } - for ($i = 0; $i < count($rows[0]); $i++) { - // This should be string so that's okay :) + + // Fill out the row with empty values, if needed. + if (!empty($handler->options['fill_single_line'])) { + $column_fill = $columns; + } + else { + $column_fill = count($rows[0]); + } + for ($i = 0; $i < $column_fill; $i++) { if (!isset($rows[count($rows) - 1][$i])) { $rows[count($rows) - 1][$i] = ''; } } } - // Apply the row classes + // Apply the row classes. foreach ($rows as $row_number => $row) { $row_classes = array(); if ($default_row_class) { - $row_classes[] = 'row-' . ($row_number + 1); + $row_classes[] = 'row-' . ($row_number + 1); } if ($row_class_special) { if ($row_number == 0) { - $row_classes[] = 'row-first'; + $row_classes[] = 'row-first'; } if (count($rows) == ($row_number + 1)) { - $row_classes[] = 'row-last'; + $row_classes[] = 'row-last'; } } $vars['row_classes'][$row_number] = implode(' ', $row_classes); foreach ($rows[$row_number] as $column_number => $item) { $column_classes = array(); if ($default_row_class) { - $column_classes[] = 'col-'. ($column_number + 1); + $column_classes[] = 'col-' . ($column_number + 1); } if ($row_class_special) { if ($column_number == 0) { @@ -791,7 +825,7 @@ function template_preprocess_views_view_grid(&$vars) { } /** - * Display the simple view of rows one after another + * Display the simple view of rows one after another. */ function template_preprocess_views_view_unformatted(&$vars) { $view = $vars['view']; @@ -832,7 +866,7 @@ function template_preprocess_views_view_unformatted(&$vars) { } /** - * Display the view as an HTML list element + * Display the view as an HTML list element. */ function template_preprocess_views_view_list(&$vars) { $handler = $vars['view']->style_plugin; @@ -861,7 +895,7 @@ function template_preprocess_views_view_list(&$vars) { } /** - * Preprocess an RSS feed + * Preprocess an RSS feed. */ function template_preprocess_views_view_rss(&$vars) { global $base_url; @@ -889,8 +923,8 @@ function template_preprocess_views_view_rss(&$vars) { } $vars['title'] = check_plain($title); - // Figure out which display which has a path we're using for this feed. If there isn't - // one, use the global $base_url + // Figure out which display which has a path we're using for this feed. If + // there isn't one, use the global $base_url. $link_display_id = $view->display_handler->get_link_display(); if ($link_display_id && !empty($view->display[$link_display_id])) { $path = $view->display[$link_display_id]->handler->get_path(); @@ -903,7 +937,8 @@ function template_preprocess_views_view_rss(&$vars) { $url_options['query'] = $view->exposed_raw_input; } - // Compare the link to the default home page; if it's the default home page, just use $base_url. + // Compare the link to the default home page; if it's the default home + // page, just use $base_url. if ($path == variable_get('site_frontpage', 'node')) { $path = ''; } @@ -957,8 +992,8 @@ function template_preprocess_views_exposed_form(&$vars) { $checkboxes .= drupal_render($form[$info['value']]); continue; } - $widget = new stdClass; - // set up defaults so that there's always something there. + $widget = new stdClass(); + // Set up defaults so that there's always something there. $widget->label = $widget->operator = $widget->widget = $widget->description = NULL; $widget->id = isset($form[$info['value']]['#id']) ? $form[$info['value']]['#id'] : ''; @@ -981,8 +1016,8 @@ function template_preprocess_views_exposed_form(&$vars) { // Wrap up all the checkboxes we set aside into a widget. if ($checkboxes) { - $widget = new stdClass; - // set up defaults so that there's always something there. + $widget = new stdClass(); + // Set up defaults so that there's always something there. $widget->label = $widget->operator = $widget->widget = NULL; $widget->id = 'checkboxes'; $widget->widget = $checkboxes; @@ -1038,6 +1073,9 @@ function theme_views_form_views_form($variables) { return drupal_render_children($form); } +/** + * theme function for a mini pager. + */ function theme_views_mini_pager($vars) { global $pager_page_array, $pager_total; @@ -1045,12 +1083,11 @@ function theme_views_mini_pager($vars) { $element = $vars['element']; $parameters = $vars['parameters']; - // current is the page we are currently paged to + // Current is the page we are currently paged to. $pager_current = $pager_page_array[$element] + 1; - // max is the maximum page number + // Max is the maximum page number. $pager_max = $pager_total[$element]; // End of marker calculations. - if ($pager_total[$element] > 1) { $li_previous = theme('pager_previous', @@ -1092,6 +1129,7 @@ function theme_views_mini_pager($vars) { 'class' => array('pager-next'), 'data' => $li_next, ); + return theme('item_list', array( 'items' => $items, diff --git a/sites/all/modules/views/theme/views-more.tpl.php b/sites/all/modules/views/theme/views-more.tpl.php index a2e1703..1adfa3e 100644 --- a/sites/all/modules/views/theme/views-more.tpl.php +++ b/sites/all/modules/views/theme/views-more.tpl.php @@ -15,8 +15,7 @@ ?> diff --git a/sites/all/modules/views/theme/views-ui-display-tab-bucket.tpl.php b/sites/all/modules/views/theme/views-ui-display-tab-bucket.tpl.php index 6d51a1d..079f579 100644 --- a/sites/all/modules/views/theme/views-ui-display-tab-bucket.tpl.php +++ b/sites/all/modules/views/theme/views-ui-display-tab-bucket.tpl.php @@ -7,7 +7,7 @@ ?>' . $title . ''; - $output .= '' . $content . '' ; + $output .= '' . $content . ''; $output .= '> - + diff --git a/sites/all/modules/views/theme/views-ui-edit-view.tpl.php b/sites/all/modules/views/theme/views-ui-edit-view.tpl.php deleted file mode 100644 index 5c3732c..0000000 --- a/sites/all/modules/views/theme/views-ui-edit-view.tpl.php +++ /dev/null @@ -1,46 +0,0 @@ - -- -diff --git a/sites/all/modules/views/theme/views-view-grid.tpl.php b/sites/all/modules/views/theme/views-view-grid.tpl.php index 09f807a..f56bd61 100644 --- a/sites/all/modules/views/theme/views-view-grid.tpl.php +++ b/sites/all/modules/views/theme/views-view-grid.tpl.php @@ -20,9 +20,9 @@ $columns): ?> -- break this lock.', array('!user' => $locked, '!age' => $lock_age, '!break' => $break)); ?> -- -"> - vid)): ?> - - - - -- - - -- -- @base.', - array('%name' => $view->name, '@base' => $base_table)); ?> --- - - - -- --- - --- --> + class=""> $item): ?> - > + class=""> diff --git a/sites/all/modules/views/theme/views-view-list.tpl.php b/sites/all/modules/views/theme/views-view-list.tpl.php index 601279a..27e2736 100644 --- a/sites/all/modules/views/theme/views-view-list.tpl.php +++ b/sites/all/modules/views/theme/views-view-list.tpl.php @@ -6,6 +6,7 @@ * * - $title : The title of this group of rows. May be empty. * - $options['type'] will either be ul or ol. + * * @ingroup views_templates */ ?> diff --git a/sites/all/modules/views/theme/views-view-row-comment.tpl.php b/sites/all/modules/views/theme/views-view-row-comment.tpl.php index 7fe2e81..dc1aa39 100644 --- a/sites/all/modules/views/theme/views-view-row-comment.tpl.php +++ b/sites/all/modules/views/theme/views-view-row-comment.tpl.php @@ -10,7 +10,7 @@ * a views template, which is why it's not used here, but is a template * 'suggestion' given to the comment template, and is used exactly * the same as any other variant of the comment template file, such as - * node-nodeTYPE.tpl.php + * node-nodeTYPE.tpl.php. * * @ingroup views_templates */ diff --git a/sites/all/modules/views/theme/views-view-summary-unformatted.tpl.php b/sites/all/modules/views/theme/views-view-summary-unformatted.tpl.php index 306d76f..e200893 100644 --- a/sites/all/modules/views/theme/views-view-summary-unformatted.tpl.php +++ b/sites/all/modules/views/theme/views-view-summary-unformatted.tpl.php @@ -11,7 +11,7 @@ ?> $row): ?> '; ?> - separator)) { print $row->separator; } ?> + separator)):?>separator; ?> >link; ?> (count; ?>) diff --git a/sites/all/modules/views/theme/views-view-summary.tpl.php b/sites/all/modules/views/theme/views-view-summary.tpl.php index 22969eb..2b61f2d 100644 --- a/sites/all/modules/views/theme/views-view-summary.tpl.php +++ b/sites/all/modules/views/theme/views-view-summary.tpl.php @@ -10,7 +10,7 @@$row): ?> -
- >link; ?> +
- >link; ?> (count?>) diff --git a/sites/all/modules/views/theme/views-view-table.tpl.php b/sites/all/modules/views/theme/views-view-table.tpl.php index b3443fc..370ecd7 100644 --- a/sites/all/modules/views/theme/views-view-table.tpl.php +++ b/sites/all/modules/views/theme/views-view-table.tpl.php @@ -16,18 +16,19 @@ * $rows are keyed by row number, fields within rows are keyed by field ID. * - $field_classes: An array of classes to apply to each field, indexed by * field id, then row number. This matches the index in $rows. + * * @ingroup views_templates */ ?> -
> - +
class=""> +
$label): ?> - $row): ?> -scope="col"> + class="" scope="col"> @@ -36,9 +37,9 @@> + class=""> $content): ?> - > + class=""> diff --git a/sites/all/modules/views/theme/views-view-unformatted.tpl.php b/sites/all/modules/views/theme/views-view-unformatted.tpl.php index f1cccb8..fc8cfc4 100644 --- a/sites/all/modules/views/theme/views-view-unformatted.tpl.php +++ b/sites/all/modules/views/theme/views-view-unformatted.tpl.php @@ -11,7 +11,7 @@ $row): ?> -> +class="">diff --git a/sites/all/modules/views/theme/views-view.tpl.php b/sites/all/modules/views/theme/views-view.tpl.php index 579cf12..96edaab 100644 --- a/sites/all/modules/views/theme/views-view.tpl.php +++ b/sites/all/modules/views/theme/views-view.tpl.php @@ -22,7 +22,7 @@ * - $pager: The pager next/prev links to display, if any * - $exposed: Exposed widget form/info to display * - $feed_icon: Feed icon to display, if any - * - $more: A link to view more, if any + * - $more: A link to view more, if any. * * @ingroup views_templates */ diff --git a/sites/all/modules/views/views.api.php b/sites/all/modules/views/views.api.php index edbb03f..dcf8019 100644 --- a/sites/all/modules/views/views.api.php +++ b/sites/all/modules/views/views.api.php @@ -244,9 +244,11 @@ * 'title' => t('Node'), * 'help' => t('Display the node with standard node view.'), * 'handler' => 'views_plugin_row_node_view', - * 'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules + * // Not necessary for most modules. + * 'path' => drupal_get_path('module', 'views') . '/modules/node', * 'theme' => 'views_view_row_node', - * 'base' => array('node'), // only works with 'node' as base. + * // Only works with 'node' as base. + * 'base' => array('node'), * 'uses options' => TRUE, * 'type' => 'normal', * ), @@ -292,12 +294,12 @@ /** * Describes data tables (or the equivalent) to Views. * - * This hook should be placed in MODULENAME.views.inc and it will be - * auto-loaded. MODULENAME.views.inc must be in the directory specified by the - * 'path' key returned by MODULENAME_views_api(), or the same directory as the - * .module file, if 'path' is unspecified. + * This hook should be placed in MODULENAME.views.inc and it will be auto + * loaded. MODULENAME.views.inc must be in the directory specified by the 'path' + * key returned by MODULENAME_views_api(), or the same directory as the .module + * file, if 'path' is unspecified. * - * @return + * @return array * An associative array describing the data structure. Primary key is the * name used internally by Views for the table(s) – usually the actual table * name. The values for the key entries are described in detail below. @@ -307,17 +309,15 @@ function hook_views_data() { // table: // // CREATE TABLE example_table ( - // nid INT(11) NOT NULL COMMENT 'Primary key; refers to {node}.nid.', + // nid INT(11) NOT NULL COMMENT 'Primary key; refers to {node}.nid.', // plain_text_field VARCHAR(32) COMMENT 'Just a plain text field.', - // numeric_field INT(11) COMMENT 'Just a numeric field.', - // boolean_field INT(1) COMMENT 'Just an on/off field.', - // timestamp_field INT(8) COMMENT 'Just a timestamp field.', + // numeric_field INT(11) COMMENT 'Just a numeric field.', + // boolean_field INT(1) COMMENT 'Just an on/off field.', + // timestamp_field INT(8) COMMENT 'Just a timestamp field.', // PRIMARY KEY(nid) // ); - // First, the entry $data['example_table']['table'] describes properties of // the actual table – not its content. - // The 'group' index will be used as a prefix in the UI for any of this // table's fields, sort criteria, etc. so it's easy to tell where they came // from. @@ -328,7 +328,8 @@ function hook_views_data() { // is not very useful for this table, as it isn't really a distinct object of // its own, but it makes a good example. $data['example_table']['table']['base'] = array( - 'field' => 'nid', // This is the identifier field for the view. + // This is the identifier field for the view. + 'field' => 'nid', 'title' => t('Example table'), 'help' => t('Example table contains example content and can be related to nodes.'), 'weight' => -10, @@ -339,10 +340,10 @@ function hook_views_data() { // table, the fields are automatically available. $data['example_table']['table']['join'] = array( // Index this array by the table name to which this table refers. - // 'left_field' is the primary key in the referenced table. - // 'field' is the foreign key in this table. 'node' => array( + // The primary key in the referenced table. 'left_field' => 'nid', + // The foreign key in this table. 'field' => 'nid', ), ); @@ -362,7 +363,6 @@ function hook_views_data() { // footer or as no result behaviour. // // The handler descriptions are described with examples below. - // Node ID table field. $data['example_table']['nid'] = array( 'title' => t('Example content'), @@ -372,8 +372,10 @@ function hook_views_data() { // other direction, use hook_views_data_alter(), or use the 'implicit' join // method described above. 'relationship' => array( - 'base' => 'node', // The name of the table to join with. - 'base field' => 'nid', // The name of the field on the joined table. + // The name of the table to join with. + 'base' => 'node', + // The name of the field on the joined table. + 'base field' => 'nid', // 'field' => 'nid' -- see hook_views_data_alter(); not needed here. 'handler' => 'views_handler_relationship', 'label' => t('Default label for the relationship'), @@ -388,7 +390,8 @@ function hook_views_data() { 'help' => t('Just a plain text field.'), 'field' => array( 'handler' => 'views_handler_field', - 'click sortable' => TRUE, // This is use by the table display plugin. + // This is use by the table display plugin. + 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort', @@ -408,7 +411,7 @@ function hook_views_data() { 'field' => array( 'handler' => 'views_handler_field_numeric', 'click sortable' => TRUE, - ), + ), 'filter' => array( 'handler' => 'views_handler_filter_numeric', ), @@ -427,7 +430,7 @@ function hook_views_data() { ), 'filter' => array( 'handler' => 'views_handler_filter_boolean_operator', - // Note that you can override the field-wide label: + // Note that you can override the field-wide label. 'label' => t('Published'), // This setting is used by the boolean filter handler, as possible option. 'type' => 'yes-no', @@ -468,7 +471,7 @@ function hook_views_data() { * 'path' key returned by MODULENAME_views_api(), or the same directory as the * .module file, if 'path' is unspecified. * - * @param $data + * @param array $data * An array of all Views data, passed by reference. See hook_views_data() for * structure. * @@ -500,9 +503,12 @@ function hook_views_data_alter(&$data) { 'title' => t('Example relationship'), 'help' => t('Example help'), 'relationship' => array( - 'base' => 'example_table', // Table we're joining to. - 'base field' => 'eid', // Field on the joined table. - 'field' => 'fid', // Real field name on the 'foo' table. + // Table we're joining to. + 'base' => 'example_table', + // Field on the joined table. + 'base field' => 'eid', + // Real field name on the 'foo' table. + 'field' => 'fid', 'handler' => 'views_handler_relationship', 'label' => t('Default label for relationship'), 'title' => t('Title seen when adding relationship'), @@ -516,26 +522,26 @@ function hook_views_data_alter(&$data) { /** * Override the default data for a Field API field. * - * Field module's implementation of hook_views_data() invokes this for each + * Field module's Implements hook_views_data() invokes this for each * field in the module that defines the field type (as declared in the field * array). It is not invoked in other modules. * * If no hook implementation exists, hook_views_data() falls back to * field_views_field_default_views_data(). * + * @param array $field + * A field definition array, as returned by field_info_fields(). + * + * @return array + * An array of views data, in the same format as the return value of + * hook_views_data(). + * * @see field_views_data() * @see hook_field_views_data_alter() * @see hook_field_views_data_views_data_alter() - * - * @param $field - * A field definition array, as returned by field_info_fields(). - * - * @return - * An array of views data, in the same format as the return value of - * hook_views_data(). */ function hook_field_views_data($field) { - + return array(); } /** @@ -545,13 +551,13 @@ function hook_field_views_data($field) { * the field, and therefore may be used to alter the default data that * field_views_field_default_views_data() supplies for the field. * - * @param $result - * An array of views table data provided for a single field. This has the same - * format as the return value of hook_views_data(). - * @param $field - * A field definition array, as returned by field_info_fields(). - * @param $module - * The module that defines the field type. + * @param array $result + * An array of views table data provided for a single field. This has the same + * format as the return value of hook_views_data(). + * @param array $field + * A field definition array, as returned by field_info_fields(). + * @param string $module + * The module that defines the field type. * * @see field_views_data() * @see hook_field_views_data() @@ -564,7 +570,7 @@ function hook_field_views_data_alter(&$result, $field, $module) { /** * Alter the views data on a per field basis. * - * Field module's implementation of hook_views_data_alter() invokes this for + * Field module's Implements hook_views_data_alter() invokes this for * each field in the module that defines the field type (as declared in the * field array). It is not invoked in other modules. * @@ -597,7 +603,7 @@ function hook_field_views_data_views_data_alter(&$data, $field) { * .module file, if 'path' is unspecified. All plugin files need to be * referenced in MODULENAME.info with the files[] directive. * - * @return + * @return array * An array on the form $plugins['PLUGIN TYPE']['PLUGIN NAME']. The plugin * must be one of row, display, display_extender, style, argument default, * argument validator, access, query, cache, pager, exposed_form or @@ -619,7 +625,8 @@ function hook_field_views_data_views_data_alter(&$data, $field) { * selectable in the ui, though on the api side they still exists. * - uses options: Set to TRUE to denote that the plugin has an additional * options form. - * - help: A short help text, wrapped in t() used as description on the plugin settings form. + * - help: A short help text, wrapped in t() used as description on the + * plugin settings form. * - help topic: The name of an entry by advanced help for the plugin. * - theme: The name of a theme suggestion to use for the display. * - js: An array with paths to js files that should be included for the @@ -646,8 +653,8 @@ function hook_field_views_data_views_data_alter(&$data, $field) { * should be added. Can for example be 'page' or 'block'. If you don't * specify it there will be contextual links around the rendered view. If * this is not set or regions have been specified, views will display an - * option to 'hide contextual links'. Use an empty array if you do not want - * this. + * option to 'hide contextual links'. Use an empty array if you do not + * want this. * - uses hook menu: Set to TRUE to have the display included by * views_menu_alter(). views_menu_alter executes then execute_hook_menu * on the display object. @@ -664,8 +671,8 @@ function hook_field_views_data_views_data_alter(&$data, $field) { * - uses fields: Set to TRUE to have the style plugin accept field * handlers. * - uses grouping: Set to TRUE to allow the grouping settings for rows. - * - even empty: May have the value 'even empty' to tell Views that the style - * should be rendered even if there are no results. + * - even empty: May have the value 'even empty' to tell Views that the + * style should be rendered even if there are no results. * * - Used by row plugins: * - uses fields: Set to TRUE to have the row plugin accept field handlers. @@ -682,12 +689,14 @@ function hook_views_plugins() { ); return array( - 'module' => 'views', // This just tells our themes are elsewhere. + // This just tells our themes are elsewhere. + 'module' => 'views', 'argument validator' => array( 'taxonomy_term' => array( 'title' => t('Taxonomy term'), 'handler' => 'views_plugin_argument_validate_taxonomy_term', - 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy', // not necessary for most modules + // Declaring path explicitly not necessary for most modules. + 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy', ), ), 'argument default' => array( @@ -711,18 +720,74 @@ function hook_views_plugins_alter(&$plugins) { $plugins['row']['node']['base'][] = 'apachesolr'; } +/** + * Alter existing plugin option definitions. + * + * This can be used to edit default or add new option definitions to existing + * plugins. The reason for doing this is that only overriding the relevent form + * with hook_form_alter() is insufficent because submitted form values will be + * ignored if they haven't been declared as an available option. + * + * An alternative approach you could also take is to extend each plugin + * individually. However if your goal is to override many, or even all plugins, + * this results in a lot of additional code and files. This makes it a lot more + * troublesome to maintain the codebase, as well as interoperability with other + * modules. + * + * @param array $options + * The option definitions to be altered. + * @param $plugin + * A views object of the plugin where the default options are defined. + * + * @see views_object::option_definition() + * @see hook_views_handler_option_definition_alter() + * @see hook_form_alter() + */ +function hook_views_plugin_option_definition_alter(&$options, $plugin) { + // Add a new option definition. + $options['option_name'] = array('default' => ''); +} + +/** + * Alter existing handler option definitions. + * + * This can be used to edit default or add new option definitions to existing + * handlers. The reason for doing this is that only overriding the relevent form + * with hook_form_alter() is insufficent because submitted form values will be + * ignored if they haven't been declared as an available option. + * + * An alternative approach you could also take is to extend each handler + * individually. However if your goal is to override many, or even all handlers, + * this results in a lot of additional code and files. This makes it a lot more + * troublesome to maintain the codebase, as well as interoperability with other + * modules. + * + * @param array $options + * The option definitions to be altered. + * @param $handler + * A views object of the handler where the default options are defined. + * + * @see views_handler::option_definition() + * @see hook_views_plugin_option_definition_alter() + * @see hook_form_alter() + */ +function hook_views_handler_option_definition_alter(&$options, $handler) { + // Add a new option definition. + $options['option_name'] = array('default' => ''); +} + /** * Register View API information. * * This is required for your module to have its include files loaded; for * example, when implementing hook_views_default_views(). * - * @return + * @return array * An array with the following possible keys: * - api: (required) The version of the Views API the module implements. * - path: (optional) If includes are stored somewhere other than within the * root module directory, specify its path here. - * - template path: (optional) A path where the module has stored it's views + * - template path: (optional) A path where the module has stored its views * template files. When you have specified this key views automatically * uses the template files for the views. You can use the same naming * conventions like for normal views template files. @@ -736,8 +801,9 @@ function hook_views_api() { } /** - * This hook allows modules to provide their own views which can either be used - * as-is or as a "starter" for users to build from. + * Allows modules to provide their own views. + * + * These can either be used as-is or as a "starter" for users to build from. * * This hook should be placed in MODULENAME.views_default.inc and it will be * auto-loaded. MODULENAME.views_default.inc must be in the directory specified @@ -747,7 +813,7 @@ function hook_views_api() { * The $view->disabled boolean flag indicates whether the View should be * enabled (FALSE) or disabled (TRUE) by default. * - * @return + * @return array * An associative array containing the structures of views, as generated from * the Export tab, keyed by the view name. A best practice is to go through * and add t() to all title and label strings, with the exception of menu @@ -755,7 +821,7 @@ function hook_views_api() { */ function hook_views_default_views() { // Begin copy and paste of output from the Export tab of a view. - $view = new view; + $view = new view(); $view->name = 'frontpage'; $view->description = 'Emulates the default Drupal front page; you may set the default home page path to this view to make it your front page.'; $view->tag = 'default'; @@ -819,13 +885,11 @@ function hook_views_default_views() { $handler->display->display_options['sitename_title'] = '1'; // (Export ends here.) - // Add view to list of views to provide. $views[$view->name] = $view; - // ...Repeat all of the above for each view the module should provide. - - // At the end, return array of default views. + // Repeat all of the above for each view the module should provide. At the + // end, return array of default views. return $views; } @@ -855,9 +919,10 @@ function hook_views_default_views_alter(&$views) { /** * Performs replacements in the query before being performed. * - * @param $view + * @param object $view * The View being executed. - * @return + * + * @return array * An array with keys being the strings to replace, and the values the strings * to replace them with. The strings to replace are often surrounded with * '***', as illustrated in the example implementation. @@ -874,10 +939,11 @@ function hook_views_query_substitutions($view) { } /** - * This hook is called to get a list of placeholders and their substitutions, - * used when preprocessing a View with form elements. + * This hook is called to get a list of placeholders and their substitutions. * - * @return + * Used when preprocessing a View with form elements. + * + * @return array * An array with keys being the strings to replace, and the values the strings * to replace them with. */ @@ -888,16 +954,31 @@ function hook_views_form_substitutions() { } /** - * Allows altering a view at the very beginning of views processing, before - * anything is done. + * Allows altering a view at the very beginning of processing a preview. + * + * Occurs before anything is done. + * + * This hook is only triggered when the one of the following are invoked: + * - $view->execute_display() + * - $view->preview() + * + * As such code placed in this hook will not fire during: + * - $view->build() + * - $view->execute() + * - $view->render() + * + * Likely, hook_views_pre_build() or hook_views_pre_execute() are much better + * choices for most use cases since they are always invoked, not just when + * previewing a display. * * Adding output to the view can be accomplished by placing text on * $view->attachment_before and $view->attachment_after. - * @param $view + * + * @param object $view * The view object about to be processed. - * @param $display_id + * @param string $display_id * The machine name of the active display. - * @param $args + * @param array $args * An array of arguments passed into the view. */ function hook_views_pre_view(&$view, &$display_id, &$args) { @@ -906,21 +987,21 @@ function hook_views_pre_view(&$view, &$display_id, &$args) { // (Note that this is not necessarily the best way to solve that task. Feel // free to contribute another example!) if ( - $view->name == 'my_special_view' && - user_access('administer site configuration') && - $display_id == 'public_display' + $view->name == 'my_special_view' + && user_access('administer site configuration') + && $display_id == 'public_display' ) { $view->set_display('private_display'); } } /** - * This hook is called right before the build process, but after displays - * are attached and the display performs its pre_execute phase. + * Called after the display's pre_execute phase but before the build process. * * Adding output to the view can be accomplished by placing text on * $view->attachment_before and $view->attachment_after. - * @param $view + * + * @param object $view * The view object about to be processed. */ function hook_views_pre_build(&$view) { @@ -934,12 +1015,15 @@ function hook_views_pre_build(&$view) { } /** - * This hook is called right after the build process. The query is now fully - * built, but it has not yet been run through db_rewrite_sql. + * This hook is called right after the build process. + * + * The query is now fully built, but it has not yet been run through + * db_rewrite_sql. * * Adding output to the view can be accomplished by placing text on * $view->attachment_before and $view->attachment_after. - * @param $view + * + * @param object $view * The view object about to be processed. */ function hook_views_post_build(&$view) { @@ -957,12 +1041,15 @@ function hook_views_post_build(&$view) { } /** - * This hook is called right before the execute process. The query is now fully - * built, but it has not yet been run through db_rewrite_sql. + * This hook is called right before the execute process. + * + * The query is now fully built, but it has not yet been run through + * db_rewrite_sql. * * Adding output to the view can be accomplished by placing text on * $view->attachment_before and $view->attachment_after. - * @param $view + * + * @param object $view * The view object about to be processed. */ function hook_views_pre_execute(&$view) { @@ -976,14 +1063,16 @@ function hook_views_pre_execute(&$view) { } /** - * This hook is called right after the execute process. The query has - * been executed, but the pre_render() phase has not yet happened for - * handlers. + * This hook is called right after the execute process. + * + * The query has been executed, but the pre_render() phase has not yet happened + * for handlers. * * Adding output to the view can be accomplished by placing text on - * $view->attachment_before and $view->attachment_after. Altering the - * content can be achieved by editing the items of $view->result. - * @param $view + * $view->attachment_before and $view->attachment_after. Altering the content + * can be achieved by editing the items of $view->result. + * + * @param object $view * The view object about to be processed. */ function hook_views_post_execute(&$view) { @@ -997,16 +1086,18 @@ function hook_views_post_execute(&$view) { } /** - * This hook is called right before the render process. The query has been - * executed, and the pre_render() phase has already happened for handlers, so - * all data should be available. + * This hook is called right before the render process. + * + * The query has been executed, and the pre_render() phase has already happened + * for handlers, so all data should be available. * * Adding output to the view can be accomplished by placing text on * $view->attachment_before and $view->attachment_after. Altering the content * can be achieved by editing the items of $view->result. * * This hook can be utilized by themes. - * @param $view + * + * @param object $view * The view object about to be processed. */ function hook_views_pre_render(&$view) { @@ -1037,11 +1128,12 @@ function hook_views_pre_render(&$view) { * so all ids used in the query should be discoverable. * * This hook can be utilized by themes. - * @param $view + * + * @param object $view * The view object about to be processed. - * @param $output + * @param string $output * A flat string with the rendered output of the view. - * @param $cache + * @param array $cache * The cache settings. */ function hook_views_post_render(&$view, &$output, &$cache) { @@ -1061,10 +1153,11 @@ function hook_views_post_render(&$view, &$output, &$cache) { * 'path' key returned by MODULENAME_views_api(), or the same directory as the * .module file, if 'path' is unspecified. * - * @param $view + * @param object $view * The view object about to be processed. - * @param $query + * @param object $query * An object describing the query. + * * @see hook_views_query_substitutions() */ function hook_views_query_alter(&$view, &$query) { @@ -1090,8 +1183,9 @@ function hook_views_query_alter(&$view, &$query) { } /** - * Alter the information box that (optionally) appears with a view preview, - * including query and performance statistics. + * Alter the information box that (optionally) appears with a view preview. + * + * Includes query and performance statistics. * * This hook should be placed in MODULENAME.views.inc and it will be * auto-loaded. MODULENAME.views.inc must be in the directory specified by the @@ -1101,14 +1195,15 @@ function hook_views_query_alter(&$view, &$query) { * Warning: $view is not a reference in PHP4 and cannot be modified here. But it * IS a reference in PHP5, and can be modified. Please be careful with it. * - * @param $rows + * @param array $rows * An associative array with two keys: * - query: An array of rows suitable for theme('table'), containing * information about the query and the display title and path. * - statistics: An array of rows suitable for theme('table'), containing * performance statistics. - * @param $view + * @param object $view * The view object. + * * @see theme_table() */ function hook_views_preview_info_alter(&$rows, $view) { @@ -1121,15 +1216,16 @@ function hook_views_preview_info_alter(&$rows, $view) { } /** - * This hooks allows to alter the links at the top of the view edit form. Some - * modules might want to add links there. + * This hooks allows to alter the links at the top of the view edit form. * - * @param $links + * Some modules might want to add links there. + * + * @param array $links * An array of links which will be displayed at the top of the view edit form. * Each entry should be on a form suitable for theme('link'). - * @param view $view + * @param object $view * The full view object which is currently edited. - * @param $display_id + * @param string $display_id * The current display id which is edited. For example that's 'default' or * 'page_1'. */ @@ -1141,12 +1237,11 @@ function hook_views_ui_display_top_links_alter(&$links, $view, $display_id) { } /** - * This hook allows to alter the commands which are used on a views ajax - * request. + * Allows altering the commands which are used on a views AJAX request. * - * @param $commands - * An array of ajax commands - * @param $view view + * @param array $commands + * An array of ajax commands. + * @param object $view * The view which is requested. */ function hook_views_ajax_data_alter(&$commands, $view) { @@ -1165,9 +1260,12 @@ function hook_views_ajax_data_alter(&$commands, $view) { * This hook should fire whenever a view is enabled, disabled, created, * updated, or deleted. * + * @param string $cid + * The cache identifier that is being cleared. + * * @see views_invalidate_cache() */ -function hook_views_invalidate_cache() { +function hook_views_invalidate_cache($cid) { cache_clear_all('views:*', 'cache_mymodule', TRUE); } diff --git a/sites/all/modules/views/views.info b/sites/all/modules/views/views.info index 021c64e..a857b23 100644 --- a/sites/all/modules/views/views.info +++ b/sites/all/modules/views/views.info @@ -285,6 +285,7 @@ files[] = tests/handlers/views_handler_filter_equality.test files[] = tests/handlers/views_handler_filter_in_operator.test files[] = tests/handlers/views_handler_filter_numeric.test files[] = tests/handlers/views_handler_filter_string.test +files[] = tests/handlers/views_handler_manytoone.test files[] = tests/handlers/views_handler_sort_random.test files[] = tests/handlers/views_handler_sort_date.test files[] = tests/handlers/views_handler_sort.test @@ -308,6 +309,7 @@ files[] = tests/views_exposed_form.test files[] = tests/field/views_fieldapi.test files[] = tests/views_glossary.test files[] = tests/views_groupby.test +files[] = tests/views_handler_filter.test files[] = tests/views_handlers.test files[] = tests/views_module.test files[] = tests/views_pager.test @@ -325,12 +327,12 @@ files[] = tests/user/views_user_argument_default.test files[] = tests/user/views_user_argument_validate.test files[] = tests/user/views_user.test files[] = tests/views_cache.test +files[] = tests/views_clone.test files[] = tests/views_view.test files[] = tests/views_ui.test -; Information added by Drupal.org packaging script on 2017-08-23 -version = "7.x-3.18" +; Information added by Drupal.org packaging script on 2019-05-10 +version = "7.x-3.23" core = "7.x" project = "views" -datestamp = "1503495103" - +datestamp = "1557505389" diff --git a/sites/all/modules/views/views.install b/sites/all/modules/views/views.install index 35c570c..92c7abc 100644 --- a/sites/all/modules/views/views.install +++ b/sites/all/modules/views/views.install @@ -19,20 +19,18 @@ function views_install() { /** * Implements hook_schema(). - * - * Generate the current version of the database schema from - * the sequence of schema update functions. Uses a similar - * method to install.inc's drupal_get_schema_versions() to - * establish the update sequence. - * - * To change the schema, add a new views_schema_N() - * function to match the associated views_update_N() - * - * @param $caller_function - * The name of the function that called us. - * Used internally, if requesting a specific schema version. */ -function views_schema($caller_function = FALSE) { +function views_schema($caller_function = NULL) { + // Generate the current version of the database schema from the sequence of + // schema update functions. Uses a similar method to install.inc's + // drupal_get_schema_versions() to establish the update sequence. + // + // To change the schema, add a new views_schema_N() function to match the + // associated views_update_N(). + // + // @param string $caller_function + // The name of the function that called us. Used internally, if requesting a + // specific schema version. static $get_current; static $schemas = array(); @@ -55,19 +53,19 @@ function views_schema($caller_function = FALSE) { if ($schemas) { sort($schemas, SORT_NUMERIC); - // If a specific version was requested, drop any later - // updates from the sequence. + // If a specific version was requested, drop any later updates from the + // sequence. if ($caller_function) { do { $schema = array_pop($schemas); - } while ($schemas && $caller_function != 'views_schema_'. $schema); + } while ($schemas && $caller_function != 'views_schema_' . $schema); } } } // Call views_schema_, for the highest available . if ($schema = array_pop($schemas)) { - $function = 'views_schema_'. $schema; + $function = 'views_schema_' . $schema; return $function(); } @@ -76,12 +74,14 @@ function views_schema($caller_function = FALSE) { /** * Views 2's initial schema. + * * Called directly by views_update_6000() for updates from Drupal 5. * * Important: Do not edit this schema! * - * Updates to the views schema must be provided as views_schema_6xxx() functions, - * which views_schema() automatically sees and applies. See below for examples. + * Updates to the views schema must be provided as views_schema_6xxx() + * functions, which views_schema() automatically sees and applies. See below for + * examples. * * Please do document updates with comments in this function, however. */ @@ -102,11 +102,11 @@ function views_schema_6000() { 'current_version' => '3.0', ), 'object' => 'view', - // the callback to load the displays + // the callback to load the displays. 'subrecords callback' => 'views_load_display_records', - // the variable that holds enabled/disabled status + // the variable that holds enabled/disabled status. 'status' => 'views_defaults', - // CRUD callbacks + // CRUD callbacks. 'create callback' => 'views_new_view', 'save callback' => 'views_save_view', 'delete callback' => 'views_delete_view', @@ -148,7 +148,8 @@ function views_schema_6000() { ), 'base_table' => array( 'type' => 'varchar', - 'length' => '32', // Updated to '64' in views_schema_6005() + 'length' => '32', + // Updated to '64' in views_schema_6005() 'default' => '', 'not null' => TRUE, 'description' => 'What table this view is based on, such as node, user, comment, or term.', @@ -161,7 +162,8 @@ function views_schema_6000() { ), ), 'primary key' => array('vid'), - 'unique key' => array('name' => array('name')), // Updated to 'unique keys' in views_schema_6003() + 'unique key' => array('name' => array('name')), + // Updated to 'unique keys' in views_schema_6003() ); $schema['views_display'] = array( @@ -241,7 +243,8 @@ function views_schema_6000() { 'description' => 'The time this cache was created or updated.', ), 'data' => array( - 'type' => 'blob', // Updated to 'text' (with size => 'big') in views_schema_6004() + 'type' => 'blob', + // Updated to 'text' (with size => 'big') in views_schema_6004() 'description' => 'Serialized data being stored.', 'serialize' => TRUE, ), @@ -294,7 +297,7 @@ function views_update_6001() { update_sql("UPDATE {blocks} SET delta = CONCAT(delta, '-block_1') WHERE module = 'views'"); } -/* +/** * NOTE: Update 6002 removed because it did not always work. * Update 6004 implements the change correctly. */ @@ -337,7 +340,7 @@ function views_update_6004() { } /** - * Enlarge the base_table column + * Enlarge the base_table column. */ function views_schema_6005() { $schema = views_schema(__FUNCTION__); @@ -444,7 +447,7 @@ function views_update_6009() { } /** - * Remove the view_php field + * Remove the view_php field. */ function views_schema_6010() { $schema = views_schema(__FUNCTION__); @@ -454,7 +457,7 @@ function views_schema_6010() { } /** - * Remove the view_php and is_cacheable field + * Remove the view_php and is_cacheable field. */ function views_update_6010() { db_drop_field('views_view', 'view_php'); @@ -578,7 +581,7 @@ function views_update_7000() { } /** - * Fix missing items from Views administrative breadcrumb + * Fix missing items from Views administrative breadcrumb. */ function views_update_7001() { $depth = db_select('menu_links') @@ -619,7 +622,7 @@ function views_schema_7301() { } /** - * Enlarge the name column + * Enlarge the name column. */ function views_update_7301() { $new_field = array( @@ -633,9 +636,9 @@ function views_update_7301() { } /** - * Remove headers field from cache tables + * Remove headers field from cache tables. * - * @see system_update_7054(). + * @see system_update_7054() */ function views_update_7302() { if (db_field_exists('cache_views', 'headers')) { diff --git a/sites/all/modules/views/views.module b/sites/all/modules/views/views.module index 2093aa7..aa407f0 100644 --- a/sites/all/modules/views/views.module +++ b/sites/all/modules/views/views.module @@ -36,7 +36,7 @@ function views_help($path, $arg) { } /** - * Advertise the current views api version + * Advertise the current views api version. */ function views_api_version() { return '3.0'; @@ -81,7 +81,9 @@ function views_api_minimum_version() { } /** - * Implement hook_theme(). Register views theming functions. + * Implements hook_theme(). + * + * Register views theming functions. */ function views_theme($existing, $type, $theme, $path) { $path = drupal_get_path('module', 'views'); @@ -93,9 +95,13 @@ function views_theme($existing, $type, $theme, $path) { 'path' => $path . '/theme', ); - // Our extra version of pager from pager.inc + // Our extra version of pager from pager.inc. $hooks['views_mini_pager'] = $base + array( - 'variables' => array('tags' => array(), 'element' => 0, 'parameters' => array()), + 'variables' => array( + 'tags' => array(), + 'element' => 0, + 'parameters' => array(), + ), 'pattern' => 'views_mini_pager__', ); @@ -104,28 +110,48 @@ function views_theme($existing, $type, $theme, $path) { // $view is an object but the core contextual_preprocess() function only // attaches contextual links when the primary theme argument is an array. 'display' => array('view_array' => array(), 'view' => NULL), - 'style' => array('view' => NULL, 'options' => NULL, 'rows' => NULL, 'title' => NULL), - 'row' => array('view' => NULL, 'options' => NULL, 'row' => NULL, 'field_alias' => NULL), + 'style' => array( + 'view' => NULL, + 'options' => NULL, + 'rows' => NULL, + 'title' => NULL, + ), + 'row' => array( + 'view' => NULL, + 'options' => NULL, + 'row' => NULL, + 'field_alias' => NULL, + ), 'exposed_form' => array('view' => NULL, 'options' => NULL), 'pager' => array( - 'view' => NULL, 'options' => NULL, - 'tags' => array(), 'quantity' => 10, 'element' => 0, 'parameters' => array() + 'view' => NULL, + 'options' => NULL, + 'tags' => array(), + 'quantity' => 10, + 'element' => 0, + 'parameters' => array(), ), ); - // Default view themes + // Default view themes. $hooks['views_view_field'] = $base + array( 'pattern' => 'views_view_field__', 'variables' => array('view' => NULL, 'field' => NULL, 'row' => NULL), ); $hooks['views_view_grouping'] = $base + array( 'pattern' => 'views_view_grouping__', - 'variables' => array('view' => NULL, 'grouping' => NULL, 'grouping_level' => NULL, 'rows' => NULL, 'title' => NULL), + 'variables' => array( + 'view' => NULL, + 'grouping' => NULL, + 'grouping_level' => NULL, + 'rows' => NULL, + 'title' => NULL, + ), ); $plugins = views_fetch_plugin_data(); - // Register theme functions for all style plugins + // Register theme functions for all style plugins. foreach ($plugins as $type => $info) { foreach ($info as $plugin => $def) { if (isset($def['theme']) && (!isset($def['register theme']) || !empty($def['register theme']))) { @@ -180,7 +206,11 @@ function views_theme($existing, $type, $theme, $path) { $hooks['views_more'] = $base + array( 'template' => 'views-more', 'pattern' => 'views_more__', - 'variables' => array('more_url' => NULL, 'link_text' => 'more', 'view' => NULL), + 'variables' => array( + 'more_url' => NULL, + 'link_text' => 'more', + 'view' => NULL, + ), ); // Add theme suggestions which are part of modules. @@ -195,16 +225,16 @@ function views_theme($existing, $type, $theme, $path) { /** * Scans a directory of a module for template files. * - * @param $cache + * @param array $cache * The existing cache of theme hooks to test against. - * @param $path + * @param string $path * The path to search. * * @see drupal_find_theme_templates() */ function _views_find_module_templates($cache, $path) { $templates = array(); - $regex = '/' . '\.tpl\.php' . '$' . '/'; + $regex = '/\.tpl\.php$/'; // Because drupal_system_listing works the way it does, we check for real // templates separately from checking for patterns. @@ -242,11 +272,12 @@ function _views_find_module_templates($cache, $path) { // for the purposes of searching. $pattern = strtr($info['pattern'], '_', '-'); - $matches = preg_grep('/^'. $pattern .'/', $patterns); + $matches = preg_grep('/^' . $pattern . '/', $patterns); if ($matches) { foreach ($matches as $match) { $file = substr($match, 0, strpos($match, '.')); - // Put the underscores back in for the hook name and register this pattern. + // Put the underscores back in for the hook name and register this + // pattern. $templates[strtr($file, '-', '_')] = array( 'template' => $file, 'path' => dirname($files[$match]->uri), @@ -315,6 +346,8 @@ function views_plugin_list() { } /** + * Preprocess a node. + * * A theme preprocess function to automatically allow view-based node * templates if called from a view. * @@ -330,8 +363,8 @@ function views_preprocess_node(&$vars) { if (!empty($vars['node']->view->current_display)) { $vars['theme_hook_suggestions'][] = 'node__view__' . $vars['node']->view->name . '__' . $vars['node']->view->current_display; - // If a node is being rendered in a view, and the view does not have a path, - // prevent drupal from accidentally setting the $page variable: + // If a node is being rendered in a view, and the view does not have a + // path, prevent drupal from accidentally setting the $page variable. if ($vars['page'] && $vars['view_mode'] == 'full' && !$vars['view']->display_handler->has_path()) { $vars['page'] = FALSE; } @@ -345,11 +378,14 @@ function views_preprocess_node(&$vars) { } /** + * Preprocess a comment. + * * A theme preprocess function to automatically allow view-based node * templates if called from a view. */ function views_preprocess_comment(&$vars) { - // The 'view' attribute of the node is added in template_preprocess_views_view_row_comment() + // The 'view' attribute of the node is added in + // template_preprocess_views_view_row_comment(). if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) { $vars['view'] = &$vars['node']->view; $vars['theme_hook_suggestions'][] = 'comment__view__' . $vars['node']->view->name; @@ -360,7 +396,7 @@ function views_preprocess_comment(&$vars) { } /** - * Implement hook_permission(). + * Implements hook_permission(). */ function views_permission() { return array( @@ -378,7 +414,7 @@ function views_permission() { } /** - * Implement hook_menu(). + * Implements hook_menu(). */ function views_menu() { $items = array(); @@ -392,8 +428,8 @@ function views_menu() { 'type' => MENU_CALLBACK, 'file' => 'includes/ajax.inc', ); - // Path is not admin/structure/views due to menu complications with the wildcards from - // the generic ajax callback. + // Path is not admin/structure/views due to menu complications with the + // wildcards from the generic ajax callback. $items['admin/views/ajax/autocomplete/user'] = array( 'page callback' => 'views_ajax_autocomplete_user', 'theme callback' => 'ajax_base_page_theme', @@ -416,7 +452,7 @@ function views_menu() { } /** - * Implement hook_menu_alter(). + * Implements hook_menu_alter(). */ function views_menu_alter(&$callbacks) { $our_paths = array(); @@ -425,18 +461,14 @@ function views_menu_alter(&$callbacks) { list($view, $display_id) = $data; $result = $view->execute_hook_menu($display_id, $callbacks); if (is_array($result)) { - // The menu system doesn't support having two otherwise - // identical paths with different placeholders. So we - // want to remove the existing items from the menu whose - // paths would conflict with ours. - - // First, we must find any existing menu items that may - // conflict. We use a regular expression because we don't - // know what placeholders they might use. Note that we - // first construct the regex itself by replacing %views_arg - // in the display path, then we use this constructed regex - // (which will be something like '#^(foo/%[^/]*/bar)$#') to - // search through the existing paths. + // The menu system doesn't support having two otherwise identical paths + // with different placeholders. So we want to remove the existing items + // from the menu whose paths would conflict with ours. First, we must find + // any existing menu items that may conflict. We use a regular expression + // because we don't know what placeholders they might use. Note that we + // first construct the regex itself by replacing %views_arg in the display + // path, then we use this constructed regex (which will be something like + // '#^(foo/%[^/]*/bar)$#') to search through the existing paths. $regex = '#^(' . preg_replace('#%views_arg#', '%[^/]*', implode('|', array_keys($result))) . ')$#'; $matches = preg_grep($regex, array_keys($callbacks)); @@ -457,10 +489,10 @@ function views_menu_alter(&$callbacks) { // This item already exists, so it must be one that we added. // We change the various callback arguments to pass an array // of possible display IDs instead of a single ID. - $callbacks[$path]['page arguments'][1] = (array)$callbacks[$path]['page arguments'][1]; + $callbacks[$path]['page arguments'][1] = (array) $callbacks[$path]['page arguments'][1]; $callbacks[$path]['page arguments'][1][] = $display_id; $callbacks[$path]['access arguments'][] = $item['access arguments'][0]; - $callbacks[$path]['load arguments'][1] = (array)$callbacks[$path]['load arguments'][1]; + $callbacks[$path]['load arguments'][1] = (array) $callbacks[$path]['load arguments'][1]; $callbacks[$path]['load arguments'][1][] = $display_id; } $our_paths[$path] = TRUE; @@ -476,22 +508,24 @@ function views_menu_alter(&$callbacks) { } /** + * Load a views argument. + * * Helper function for menu loading. This will automatically be * called in order to 'load' a views argument; primarily it * will be used to perform validation. * - * @param $value + * @param string $value * The actual value passed. - * @param $name + * @param string $name * The name of the view. This needs to be specified in the 'load function' * of the menu entry. - * @param $display_id + * @param string $display_id * The display id that will be loaded for this menu item. - * @param $index + * @param int $index * The menu argument index. This counts from 1. */ function views_arg_load($value, $name, $display_id, $index) { - static $views = array(); + static $views = array(); $display_ids = is_array($display_id) ? $display_id : array($display_id); $display_id = reset($display_ids); @@ -547,12 +581,12 @@ function views_arg_load($value, $name, $display_id, $index) { /** * Page callback: Displays a page view, given a name and display id. * - * @param $name + * @param string $name * The name of a view. - * @param $display_id + * @param string $display_id * The display id of a view. * - * @return + * @return string|int * Either the HTML of a fully-executed view, or MENU_NOT_FOUND. */ function views_page($name, $display_id) { @@ -616,8 +650,8 @@ function views_preprocess_html(&$variables) { } /** -* Implements hook_preprocess_HOOK() for page.tpl.php. -*/ + * Implements hook_preprocess_HOOK() for page.tpl.php. + */ function views_preprocess_page(&$variables) { // If the page contains a view as its main content, contextual links may have // been attached to the page as a whole; for example, by views_page_alter(). @@ -649,7 +683,7 @@ function views_contextual_links_view_alter(&$element, $items) { } /** - * Implement hook_block_info(). + * Implements hook_block_info(). */ function views_block_info() { // Try to avoid instantiating all the views just to get the blocks info. @@ -662,7 +696,7 @@ function views_block_info() { $items = array(); $views = views_get_all_views(); foreach ($views as $view) { - // disabled views get nothing. + // Disabled views get nothing. if (!empty($view->disabled)) { continue; } @@ -691,7 +725,7 @@ function views_block_info() { // can also be 32. So for very long deltas, change to md5 hashes. $hashes = array(); - // get the keys because we're modifying the array and we don't want to + // Get the keys because we're modifying the array and we don't want to // confuse PHP too much. $keys = array_keys($items); foreach ($keys as $delta) { @@ -719,11 +753,69 @@ function views_block_info() { } /** - * Implement hook_block_view(). + * Implements hook_block_configure(). + */ +function views_block_configure($delta = '') { + // If there's no Views UI module there's nothing to link to. + if (!module_exists('views_ui')) { + return array(); + } + + // If the user doesn't have access to edit the view then don't bother with + // anything else. + if (!user_access('administer views')) { + return array(); + } + + // If this is 32, this should be an md5 hash. + if (strlen($delta) == 32) { + $hashes = variable_get('views_block_hashes', array()); + if (!empty($hashes[$delta])) { + $delta = $hashes[$delta]; + } + } + + // Some added precaution in case the delta is missing values. + list($view_name, $display_id) = explode('-', $delta, 2) + array('', ''); + + // If the view name or display ID can't be found, there's something wrong. + if ($view_name === '' || $display_id === '') { + return array(); + } + + $view = views_get_view($view_name); + if (empty($view)) { + return array(); + } + + if (!isset($view->display[$display_id])) { + return array(); + } + + /** @var \views_display $display */ + $display = $view->display[$display_id]; + + $view_label = $view->get_human_name(); + $display_label = $display->display_title; + + $path = "admin/structure/views/view/$view_name/edit/$display_id"; + + return array( + 'fieldset' => array( + '#type' => 'fieldset', + '#title' => t('Configure this views display'), + 'content' => array( + '#markup' => l($view_label . ' - ' . $display_label, $path), + ), + ), + ); +} + +/** + * Implements hook_block_view(). */ function views_block_view($delta) { - $start = microtime(TRUE); - // if this is 32, this should be an md5 hash. + // If this is 32, this should be an md5 hash. if (strlen($delta) == 32) { $hashes = variable_get('views_block_hashes', array()); if (!empty($hashes[$delta])) { @@ -758,7 +850,7 @@ function views_block_view($delta) { return; } list($name, $display_id) = $explode; - // Load the view + // Load the view. if ($view = views_get_view($name)) { if ($view->access($display_id)) { $output = $view->execute_display($display_id); @@ -775,18 +867,18 @@ function views_block_view($delta) { /** * Converts Views block content to a renderable array with contextual links. * - * @param $block + * @param array $block * An array representing the block, with the same structure as the return * value of hook_block_view(). This will be modified so as to force * $block['content'] to be a renderable array, containing the optional * '#contextual_links' property (if there are any contextual links associated * with the block). - * @param $view + * @param object $view * The view that was used to generate the block content. - * @param $display_id + * @param string $display_id * The ID of the display within the view that was used to generate the block * content. - * @param $block_type + * @param string $block_type * The type of the block. If it's block it's a regular views display, * but 'special_block_-exp' exist as well. */ @@ -833,12 +925,12 @@ function views_add_block_contextual_links(&$block, $view, $display_id, $block_ty * later on (for example, alter hooks which run later during the same page * request). * - * @param $render_element + * @param array $render_element * The renderable array to which contextual links will be added. This array * should be suitable for passing in to drupal_render() and will normally * contain a representation of the view display whose contextual links are * being requested. - * @param $location + * @param string $location * The location in which the calling function intends to render the view and * its contextual links. The core system supports three options for this * parameter: @@ -858,9 +950,9 @@ function views_add_block_contextual_links(&$block, $view, $display_id, $block_ty * declare, via the 'contextual links locations' array key, which view * displays support having their contextual links rendered in the location * you have defined. - * @param $view + * @param object $view * The view whose contextual links will be added. - * @param $display_id + * @param string $display_id * The ID of the display within $view whose contextual links will be added. * * @see hook_views_plugins() @@ -878,7 +970,7 @@ function views_add_contextual_links(&$render_element, $location, $view, $display $plugin = views_fetch_plugin_data('display', $view->display[$display_id]->display_plugin); // If contextual links locations are not set, provide a sane default. (To // avoid displaying any contextual links at all, a display plugin can still - // set 'contextual links locations' to, e.g., an empty array.) + // set 'contextual links locations' to, e.g., an empty array). $plugin += array('contextual links locations' => array('view')); // On exposed_forms blocks contextual links should always be visible. $plugin['contextual links locations'][] = 'special_block_-exp'; @@ -920,13 +1012,14 @@ function views_add_contextual_links(&$render_element, $location, $view, $display /** * Returns an array of language names. * - * This is a one to one copy of locale_language_list because we can't rely on enabled locale module. + * This is a one to one copy of locale_language_list because we can't rely on + * enabled locale module. * - * @param $field - * 'name' => names in current language, localized - * 'native' => native names - * @param $all - * Boolean to return all languages or only enabled ones + * @param string $field + * Either 'name' for localized names in current language or 'native' for + * native names. + * @param bool $all + * Boolean to return all languages or only enabled ones. * * @see locale_language_list() */ @@ -953,7 +1046,7 @@ function views_flush_caches() { } /** - * Implements hook_field_create_instance. + * Implements hook_field_create_instance(). */ function views_field_create_instance($instance) { cache_clear_all('*', 'cache_views', TRUE); @@ -961,7 +1054,7 @@ function views_field_create_instance($instance) { } /** - * Implements hook_field_update_instance. + * Implements hook_field_update_instance(). */ function views_field_update_instance($instance, $prior_instance) { cache_clear_all('*', 'cache_views', TRUE); @@ -969,7 +1062,7 @@ function views_field_update_instance($instance, $prior_instance) { } /** - * Implements hook_field_delete_instance. + * Implements hook_field_delete_instance(). */ function views_field_delete_instance($instance) { cache_clear_all('*', 'cache_views', TRUE); @@ -978,10 +1071,14 @@ function views_field_delete_instance($instance) { /** * Invalidate the views cache, forcing a rebuild on the next grab of table data. + * + * @param string $cid + * The cache identifier we want to clear. If no given, it will default to '*' + * which will clear the entire cache_views bin. */ -function views_invalidate_cache() { +function views_invalidate_cache($cid = '*') { // Clear the views cache. - cache_clear_all('*', 'cache_views', TRUE); + cache_clear_all($cid, 'cache_views', TRUE); // Clear the page and block cache. cache_clear_all(); @@ -990,7 +1087,7 @@ function views_invalidate_cache() { variable_set('menu_rebuild_needed', TRUE); // Allow modules to respond to the Views cache being cleared. - module_invoke_all('views_invalidate_cache'); + module_invoke_all('views_invalidate_cache', $cid); } /** @@ -1065,7 +1162,7 @@ function views_check_perm($perms, $account = NULL) { /** * Access callback for the views_plugin_access_role access plugin. - + * * Determine if the specified user has access to a view on the basis of any of * the requested roles. If the $account argument is omitted, the current user * is used. @@ -1077,10 +1174,10 @@ function views_check_roles($rids, $account = NULL) { $roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID; return user_access('access all views', $account) || array_intersect(array_filter($rids), $roles); } -// ------------------------------------------------------------------ -// Functions to help identify views that are running or ran /** + * Set page view. + * * Set the current 'page view' that is being displayed so that it is easy * for other modules or the theme to identify. */ @@ -1094,6 +1191,8 @@ function &views_set_page_view($view = NULL) { } /** + * Get page view. + * * Find out what, if any, page view is currently in use. Please note that * this returns a reference, so be careful! You can unintentionally modify the * $view object. @@ -1106,10 +1205,13 @@ function &views_get_page_view() { } /** + * Set current view. + * * Set the current 'current view' that is being built/rendered so that it is - * easy for other modules or items in drupal_eval to identify + * easy for other modules or items in drupal_eval to identify. * * @return view + * The current view. */ function &views_set_current_view($view = NULL) { static $cache = NULL; @@ -1121,24 +1223,28 @@ function &views_set_current_view($view = NULL) { } /** + * Get current view. + * * Find out what, if any, current view is currently in use. Please note that * this returns a reference, so be careful! You can unintentionally modify the * $view object. * * @return view + * The current view. */ function &views_get_current_view() { return views_set_current_view(); } -// ------------------------------------------------------------------ -// Include file helpers - /** * Include views .inc files as necessary. */ function views_include($file) { - ctools_include($file, 'views'); + static $views_path; + if (!isset($views_path)) { + $views_path = DRUPAL_ROOT . '/' . drupal_get_path('module', 'views'); + } + include_once $views_path . '/includes/' . $file . '.inc'; } /** @@ -1175,7 +1281,7 @@ function views_get_module_apis($api = 'views', $reset = FALSE) { function views_add_css($file) { // We set preprocess to FALSE because we are adding the files conditionally, // and we don't want to generate duplicate cache files. - // TODO: at some point investigate adding some files unconditionally and + // @todo at some point investigate adding some files unconditionally and // allowing preprocess. drupal_add_css(drupal_get_path('module', 'views') . "/css/$file.css", array('preprocess' => FALSE)); } @@ -1184,7 +1290,7 @@ function views_add_css($file) { * Include views .js files. */ function views_add_js($file) { - // If javascript has been disabled by the user, never add js files. + // If JavaScript has been disabled by the user, never add js files. if (variable_get('views_no_javascript', FALSE)) { return; } @@ -1219,22 +1325,18 @@ function views_include_handlers($reset = FALSE) { $finished = TRUE; } -// ----------------------------------------------------------------------- -// Views handler functions - /** * Fetch a handler from the data cache. * - * @param $table + * @param string $table * The name of the table this handler is from. - * @param $field + * @param string $field * The name of the field this handler is from. - * @param $key - * The type of handler. i.e, sort, field, argument, filter, relationship - * @param $override - * Override the actual handler object with this class. Used for - * aggregation when the handler is redirected to the aggregation - * handler. + * @param string $key + * The type of handler. i.e, sort, field, argument, filter, relationship. + * @param mixed $override + * Override the actual handler object with this class. Used for aggregation + * when the handler is redirected to the aggregation handler. * * @return views_handler * An instance of a handler object. May be views_handler_broken. @@ -1246,8 +1348,6 @@ function views_get_handler($table, $field, $key, $override = NULL) { $handler = NULL; views_include('handlers'); - // Support old views_data entries conversion. - // Support conversion on table level. if (isset($data['moved to'])) { $moved = array($data['moved to'], $field); @@ -1265,7 +1365,7 @@ function views_get_handler($table, $field, $key, $override = NULL) { if (!empty($moved)) { list($moved_table, $moved_field) = $moved; if (!empty($recursion_protection[$moved_table][$moved_field])) { - // recursion detected! + // Recursion detected! return NULL; } @@ -1273,7 +1373,7 @@ function views_get_handler($table, $field, $key, $override = NULL) { $handler = views_get_handler($moved_table, $moved_field, $key, $override); $recursion_protection = array(); if ($handler) { - // store these values so we know what we were originally called. + // Store these values so we know what we were originally called. $handler->original_table = $table; $handler->original_field = $field; if (empty($handler->actual_table)) { @@ -1284,7 +1384,7 @@ function views_get_handler($table, $field, $key, $override = NULL) { return $handler; } - // Set up a default handler: + // Set up a default handler. if (empty($data[$field][$key]['handler'])) { $data[$field][$key]['handler'] = 'views_handler_' . $key; } @@ -1300,8 +1400,9 @@ function views_get_handler($table, $field, $key, $override = NULL) { return $handler; } - // DEBUG -- identify missing handlers - vpr("Missing handler: @table @field @key", array('@table' => $table, '@field' => $field, '@key' => $key)); + // DEBUG -- identify missing handlers. + $placeholders = array('@table' => $table, '@field' => $field, '@key' => $key); + vpr("Missing handler: @table @field @key", $placeholders); $broken = array( 'title' => t('Broken handler @table.@field', array('@table' => $table, '@field' => $field)), 'handler' => 'views_handler_' . $key . '_broken', @@ -1312,16 +1413,13 @@ function views_get_handler($table, $field, $key, $override = NULL) { } /** - * Fetch Views' data from the cache + * Fetch Views' data from the cache. */ function views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) { views_include('cache'); return _views_fetch_data($table, $move, $reset); } -// ----------------------------------------------------------------------- -// Views plugin functions - /** * Fetch the plugin data from cache. */ @@ -1331,17 +1429,17 @@ function views_fetch_plugin_data($type = NULL, $plugin = NULL, $reset = FALSE) { } /** - * Fetch a list of all base tables available + * Fetch a list of all base tables available. * - * @param $type - * Either 'display', 'style' or 'row' - * @param $key - * For style plugins, this is an optional type to restrict to. May be 'normal', - * 'summary', 'feed' or others based on the needs of the display. - * @param $base + * @param string $type + * Either 'display', 'style' or 'row'. + * @param string $key + * For style plugins, this is an optional type to restrict to. May be + * 'normal', 'summary', 'feed' or others based on the needs of the display. + * @param array $base * An array of possible base tables. * - * @return + * @return array * A keyed array of in the form of 'base_table' => 'Description'. */ function views_fetch_plugin_names($type, $key = NULL, $base = array()) { @@ -1363,16 +1461,16 @@ function views_fetch_plugin_names($type, $key = NULL, $base = array()) { asort($plugins[$type]); return $plugins[$type]; } - // fall-through + + // Fall-through. return array(); } /** - * Get a handler for a plugin + * Get a handler for a plugin. * * @return views_plugin - * - * The created plugin object. + * The created plugin object. */ function views_get_plugin($type, $plugin, $reset = FALSE) { views_include('handlers'); @@ -1385,7 +1483,8 @@ function views_get_plugin($type, $plugin, $reset = FALSE) { /** * Load the current enabled localization plugin. * - * @return The name of the localization plugin. + * @return string + * The name of the localization plugin. */ function views_get_localization_plugin() { $plugin = variable_get('views_localization_plugin', ''); @@ -1402,9 +1501,6 @@ function views_get_localization_plugin() { return $plugin; } -// ----------------------------------------------------------------------- -// Views database functions - /** * Get all view templates. * @@ -1445,19 +1541,20 @@ function views_new_view() { } /** - * Return a list of all views and display IDs that have a particular - * setting in their display's plugin settings. + * Get applicable views. * - * @return - * @code - * array( - * array($view, $display_id), - * array($view, $display_id), - * ); - * @endcode + * Return a list of all views and display IDs that have a particular setting in + * their display's plugin settings. + * + * @return array + * An array with the following structure. + * array( + * array($view, $display_id), + * array($view, $display_id), + * ); */ function views_get_applicable_views($type) { - // @todo: Use a smarter flagging system so that we don't have to + // @todo Use a smarter flagging system so that we don't have to // load every view for this. $result = array(); $views = views_get_all_views(); @@ -1498,7 +1595,7 @@ function views_get_applicable_views($type) { /** * Return an array of all views as fully loaded $view objects. * - * @param $reset + * @param bool $reset * If TRUE, reset the static cache forcing views to be reloaded. */ function views_get_all_views($reset = FALSE) { @@ -1523,29 +1620,31 @@ function views_get_disabled_views() { } /** + * Get options array. + * * Return an array of view as options array, that can be used by select, * checkboxes and radios as #options. * * @param bool $views_only - * If TRUE, only return views, not displays. + * If TRUE, only return views, not displays. * @param string $filter - * Filters the views on status. Can either be 'all' (default), 'enabled' or - * 'disabled' - * @param mixed $exclude_view - * view or current display to exclude - * either a - * - views object (containing $exclude_view->name and $exclude_view->current_display) - * - views name as string: e.g. my_view - * - views name and display id (separated by ':'): e.g. my_view:default + * Filters the views on status. Can either be 'all' (default), 'enabled' or + * 'disabled'. + * @param mixed $exclude_view + * View or current display to exclude + * either a + * - views object (containing name and current_display) + * - views name as string: e.g. my_view + * - views name and display id (separated by ':'): e.g. my_view:default. * @param bool $optgroup - * If TRUE, returns an array with optgroups for each view (will be ignored for - * $views_only = TRUE). Can be used by select + * If TRUE, returns an array with optgroups for each view (will be ignored for + * $views_only = TRUE). Can be used by select. * @param bool $sort - * If TRUE, the list of views is sorted ascending. + * If TRUE, the list of views is sorted ascending. * * @return array - * an associative array for use in select. - * - key: view name and display id separated by ':', or the view name only + * An associative array for use in select. + * - key: view name and display id separated by ':', or the view name only */ function views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclude_view = NULL, $optgroup = FALSE, $sort = FALSE) { @@ -1557,6 +1656,7 @@ function views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclu $func = "views_get_{$filter}_views"; $views = $func(); break; + default: return array(); } @@ -1621,10 +1721,11 @@ function views_view_is_disabled($view) { * isn't called 'views_load()' primarily because it might get a view * from the default views which aren't technically loaded from the database. * - * @param $name + * @param string $name * The name of the view. - * @param $reset + * @param bool $reset * If TRUE, reset this entry in the load cache. + * * @return view * A reference to the $view object. Use $reset if you're sure you want * a fresh one. @@ -1730,22 +1831,19 @@ function views_export_status($view, $status) { views_invalidate_cache(); } -// ------------------------------------------------------------------ -// Views debug helper functions - /** * Provide debug output for Views. * * This relies on devel.module * or on the debug() function if you use a simpletest. * - * @param $message + * @param mixed $message * The message/variable which should be debugged. * This either could be * * an array/object which is converted to pretty output - * * a translation source string which is used together with the parameter placeholders. - * - * @param $placeholder + * * a translation source string which is used together with the parameter + * placeholders. + * @param array $placeholders * The placeholders which are used for the translation source string. */ function views_debug($message, $placeholders = array()) { @@ -1758,7 +1856,7 @@ function views_debug($message, $placeholders = array()) { $output = $message; watchdog('views_logging', $output, $placeholders); } - else if ($devel_region == 'drupal_debug') { + elseif ($devel_region == 'drupal_debug') { $output = empty($output) ? t($message, $placeholders) : $output; dd($output); } @@ -1774,14 +1872,14 @@ function views_debug($message, $placeholders = array()) { } /** - * Shortcut to views_debug() + * Shortcut to views_debug(). */ function vpr($message, $placeholders = array()) { views_debug($message, $placeholders); } /** - * Debug messages + * Debug messages. */ function vsm($message) { if (module_exists('devel')) { @@ -1792,7 +1890,8 @@ function vsm($message) { function views_trace() { $message = ''; foreach (debug_backtrace() as $item) { - if (!empty($item['file']) && !in_array($item['function'], array('vsm_trace', 'vpr_trace', 'views_trace'))) { + $traces = array('vsm_trace', 'vpr_trace', 'views_trace'); + if (!empty($item['file']) && !in_array($item['function'], $traces)) { $message .= basename($item['file']) . ": " . (empty($item['class']) ? '' : ($item['class'] . '->')) . "$item[function] line $item[line]" . "\n"; } } @@ -1807,10 +1906,9 @@ function vpr_trace() { dpr(views_trace()); } -// ------------------------------------------------------------------ -// Views form (View with form elements) - /** + * Determine whether the view has form elements. + * * Returns TRUE if the passed-in view contains handlers with views form * implementations, FALSE otherwise. */ @@ -1832,6 +1930,7 @@ function views_view_has_form_elements($view) { /** * This is the entry function. Just gets the form for the current step. + * * The form is always assumed to be multistep, even if it has only one * step (the default 'views_form_views_form' step). That way it is actually * possible for modules to have a multistep form if they need to. @@ -1859,6 +1958,7 @@ function views_form($form, &$form_state, $view, $output) { /** * Callback for the main step of a Views form. + * * Invoked by views_form(). */ function views_form_views_form($form, &$form_state, $view, $output) { @@ -1948,6 +2048,7 @@ function views_form_views_form($form, &$form_state, $view, $output) { /** * Validate handler for the first step of the views form. + * * Calls any existing views_form_validate functions located * on the views fields. */ @@ -1973,6 +2074,7 @@ function views_form_views_form_validate($form, &$form_state) { /** * Submit handler for the first step of the views form. + * * Calls any existing views_form_submit functions located * on the views fields. */ @@ -1996,9 +2098,6 @@ function views_form_views_form_submit($form, &$form_state) { } } -// ------------------------------------------------------------------ -// Exposed widgets form - /** * Form builder for the exposed widgets form. * @@ -2008,7 +2107,8 @@ function views_exposed_form($form, &$form_state) { // Don't show the form when batch operations are in progress. if ($batch = batch_get() && isset($batch['current_set'])) { return array( - // Set the theme callback to be nothing to avoid errors in template_preprocess_views_exposed_form(). + // Set the theme callback to be nothing to avoid errors in + // template_preprocess_views_exposed_form(). '#theme' => '', ); } @@ -2023,7 +2123,7 @@ function views_exposed_form($form, &$form_state) { // Let form plugins know this is for exposed widgets. $form_state['exposed'] = TRUE; - // Check if the form was already created + // Check if the form was already created. if ($cache = views_exposed_form_cache($view->name, $view->current_display)) { return $cache; } @@ -2060,8 +2160,9 @@ function views_exposed_form($form, &$form_state) { } } + // Form submit, #name is an empty string to prevent showing up in $_GET. $form['submit'] = array( - '#name' => '', // prevent from showing up in $_GET. + '#name' => '', '#type' => 'submit', '#value' => t('Apply'), '#id' => drupal_html_id('edit-submit-' . $view->name), @@ -2070,7 +2171,6 @@ function views_exposed_form($form, &$form_state) { $form['#action'] = url($view->display_handler->get_url()); $form['#theme'] = views_theme_functions('views_exposed_form', $view, $display); $form['#id'] = drupal_clean_css_identifier('views_exposed_form-' . check_plain($view->name) . '-' . check_plain($display->id)); -// $form['#attributes']['class'] = array('views-exposed-form'); // If using AJAX, we need the form plugin. if ($view->use_ajax) { @@ -2081,14 +2181,14 @@ function views_exposed_form($form, &$form_state) { $exposed_form_plugin = $form_state['exposed_form_plugin']; $exposed_form_plugin->exposed_form_alter($form, $form_state); - // Save the form + // Save the form. views_exposed_form_cache($view->name, $view->current_display, $form); return $form; } /** - * Implement hook_form_alter for the exposed form. + * Implements hook_form_alter() for views_exposed_form(). * * Since the exposed form is a GET form, we don't want it to send a wide * variety of information. @@ -2100,7 +2200,7 @@ function views_form_views_exposed_form_alter(&$form, &$form_state) { } /** - * Validate handler for exposed filters + * Validate handler for exposed filters. */ function views_exposed_form_validate(&$form, &$form_state) { foreach (array('field', 'filter') as $type) { @@ -2114,7 +2214,7 @@ function views_exposed_form_validate(&$form, &$form_state) { } /** - * Submit handler for exposed filters + * Submit handler for exposed filters. */ function views_exposed_form_submit(&$form, &$form_state) { foreach (array('field', 'filter') as $type) { @@ -2126,8 +2226,16 @@ function views_exposed_form_submit(&$form, &$form_state) { $form_state['view']->exposed_data = $form_state['values']; $form_state['view']->exposed_raw_input = array(); - - $exclude = array('q', 'submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', '', 'reset'); + $exclude = array( + 'q', + 'submit', + 'form_build_id', + 'form_id', + 'form_token', + 'exposed_form_plugin', + '', + 'reset', + ); $exposed_form_plugin = $form_state['exposed_form_plugin']; $exposed_form_plugin->exposed_form_submit($form, $form_state, $exclude); @@ -2141,13 +2249,14 @@ function views_exposed_form_submit(&$form, &$form_state) { /** * Save the Views exposed form for later use. * - * @param $views_name - * String. The views name. - * @param $display_name - * String. The current view display name. - * @param $form_output - * Array (optional). The form structure. Only needed when inserting the value. - * @return + * @param string $views_name + * The views name. + * @param string $display_name + * The current view display name. + * @param array $form_output + * An optional form structure. Only needed when inserting the value. + * + * @return array|bool * Array. The form structure, if any. Otherwise, return FALSE. */ function views_exposed_form_cache($views_name, $display_name, $form_output = NULL) { @@ -2155,19 +2264,15 @@ function views_exposed_form_cache($views_name, $display_name, $form_output = NUL // be cleared between each test. $views_exposed = &drupal_static(__FUNCTION__); - // Save the form output + // Save the form output. if (!empty($form_output)) { $views_exposed[$views_name][$display_name] = $form_output; - return; } - // Return the form output, if any + // Return the form output, if any. return empty($views_exposed[$views_name][$display_name]) ? FALSE : $views_exposed[$views_name][$display_name]; } -// ------------------------------------------------------------------ -// Misc helpers - /** * Build a list of theme function names for use most everywhere. */ @@ -2252,9 +2357,9 @@ function _views_query_tag_alter_condition(QueryAlterableInterface $query, &$cond * to do that, you will need to do what this function does manually, by * loading the view, getting the preview and then getting $view->get_title(). * - * @param $name + * @param string $name * The name of the view to embed. - * @param $display_id + * @param string $display_id * The display id to embed. If unsure, use 'default', as it will always be * valid. But things like 'page' or 'block' should work here. * @param ... @@ -2262,9 +2367,11 @@ function _views_query_tag_alter_condition(QueryAlterableInterface $query, &$cond */ function views_embed_view($name, $display_id = 'default') { $args = func_get_args(); - array_shift($args); // remove $name + // Remove $name. + array_shift($args); if (count($args)) { - array_shift($args); // remove $display_id + // Remove $display_id. + array_shift($args); } $view = views_get_view($name); @@ -2289,14 +2396,17 @@ function views_embed_view($name, $display_id = 'default') { * Everything after #views-tab- is the display ID, e.g. page_1. * @param ... * Any additional parameters will be passed as arguments. + * * @return array * An array containing an object for each view item. */ function views_get_view_result($name, $display_id = NULL) { $args = func_get_args(); - array_shift($args); // remove $name + // Remove $name. + array_shift($args); if (count($args)) { - array_shift($args); // remove $display_id + // Remove $display_id. + array_shift($args); } $view = views_get_view($name); @@ -2361,22 +2471,28 @@ function views_var_export($var, $prefix = '', $init = TRUE) { } /** - * Prepare a string for use as a valid CSS identifier (element, class or ID name). + * Prepare a string for use as a valid CSS identifier. + * * This function is similar to a core version but with more sane filter values. - * * http://www.w3.org/TR/CSS21/syndata.html#characters shows the syntax for valid - * CSS identifiers (including element names, classes, and IDs in selectors.) + * CSS identifiers (including element names, classes, and IDs in selectors). * - * @param $identifier + * @param string $identifier * The identifier to clean. - * @param $filter + * @param array $filter * An array of string replacements to use on the identifier. - * @return + * + * @return string * The cleaned identifier. * * @see drupal_clean_css_identifier() */ -function views_clean_css_identifier($identifier, $filter = array(' ' => '-', '/' => '-', '[' => '-', ']' => '')) { +function views_clean_css_identifier($identifier, $filter = array( + ' ' => '-', + '/' => '-', + '[' => '-', + ']' => '', +)) { // By default, we filter using Drupal's coding standards. $identifier = strtr($identifier, $filter); @@ -2394,19 +2510,19 @@ function views_clean_css_identifier($identifier, $filter = array(' ' => '-', '/' } /** - * Implement hook_views_exportables(). + * Implements hook_views_exportables(). */ function views_views_exportables($op = 'list', $views = NULL, $name = 'foo') { $all_views = views_get_all_views(); if ($op == 'list') { foreach ($all_views as $name => $view) { - // in list, $views is a list of tags. + // In list, $views is a list of tags. if (empty($views) || in_array($view->tag, $views)) { $return[$name] = array( 'name' => check_plain($name), 'desc' => check_plain($view->description), - 'tag' => check_plain($view->tag) + 'tag' => check_plain($view->tag), ); } } @@ -2433,7 +2549,7 @@ function views_views_exportables($op = 'list', $views = NULL, $name = 'foo') { } /** - * #process callback to see if we need to check_plain() the options. + * Process callback to see if we need to check_plain() the options. * * Since FAPI is inconsistent, the #options are sanitized for you in all cases * _except_ checkboxes. We have form elements that are sometimes 'select' and @@ -2451,19 +2567,18 @@ function views_process_check_options($element, &$form_state) { /** * Trim the field down to the specified length. * - * @param $alter + * @param array $alter * - max_length: Maximum length of the string, the rest gets truncated. * - word_boundary: Trim only on a word boundary. * - ellipsis: Show an ellipsis (...) at the end of the trimmed string. * - html: Take sure that the html is correct. - * - * @param $value + * @param string $value * The string which should be trimmed. */ function views_trim_text($alter, $value) { if (drupal_strlen($value) > $alter['max_length']) { $value = drupal_substr($value, 0, $alter['max_length']); - // TODO: replace this with cleanstring of ctools + // @todo Replace this with cleanstring of CTools. if (!empty($alter['word_boundary'])) { $regex = "(.*)\b.+"; if (function_exists('mb_ereg')) { @@ -2477,7 +2592,7 @@ function views_trim_text($alter, $value) { $value = $matches[1]; } } - // Remove scraps of HTML entities from the end of a strings + // Remove scraps of HTML entities from the end of a strings. $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value)); if (!empty($alter['ellipsis'])) { @@ -2500,7 +2615,7 @@ function views_array_key_plus($array) { $keys = array_keys($array); rsort($keys); foreach ($keys as $key) { - $array[$key+1] = $array[$key]; + $array[$key + 1] = $array[$key]; unset($array[$key]); } asort($array); @@ -2508,14 +2623,15 @@ function views_array_key_plus($array) { } /** - * Report to CTools that we use hook_views_api instead of hook_ctools_plugin_api() + * Implements hook_ctools_plugin_api_hook_name(). + * + * Report to CTools that we use hook_views_api instead of + * hook_ctools_plugin_api(). */ function views_ctools_plugin_api_hook_name() { return 'views_api'; } -// Declare API compatibility on behalf of core modules: - /** * Implements hook_views_api(). * @@ -2523,84 +2639,190 @@ function views_ctools_plugin_api_hook_name() { */ function views_views_api() { return array( - // in your modules do *not* use views_api_version()!!! + // In your modules do *not* use views_api_version()!!! 'api' => views_api_version(), 'path' => drupal_get_path('module', 'views') . '/modules', ); } +/** + * Implements hook_admin_menu_cache_info(). + */ +function views_admin_menu_cache_info() { + $caches['views'] = array( + 'title' => t('Views'), + 'callback' => 'views_invalidate_cache', + ); + return $caches; +} + if (!function_exists('aggregator_views_api')) { - function aggregator_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Aggregator module. + */ + function aggregator_views_api() { + return views_views_api(); + } } if (!function_exists('book_views_api')) { - function book_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Book module. + */ + function book_views_api() { + return views_views_api(); + } } if (!function_exists('comment_views_api')) { - function comment_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Comment module. + */ + function comment_views_api() { + return views_views_api(); + } } if (!function_exists('field_views_api')) { - function field_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Field module. + */ + function field_views_api() { + return views_views_api(); + } } if (!function_exists('file_views_api')) { - function file_views_api() { return views_views_api(); } + /** + * Provide Views integration for the File module. + */ + function file_views_api() { + return views_views_api(); + } } if (!function_exists('filter_views_api')) { - function filter_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Filter module. + */ + function filter_views_api() { + return views_views_api(); + } } if (!function_exists('image_views_api')) { - function image_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Image module. + */ + function image_views_api() { + return views_views_api(); + } } if (!function_exists('locale_views_api')) { - function locale_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Locale module. + */ + function locale_views_api() { + return views_views_api(); + } } if (!function_exists('node_views_api')) { - function node_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Node module. + */ + function node_views_api() { + return views_views_api(); + } } if (!function_exists('poll_views_api')) { - function poll_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Poll module. + */ + function poll_views_api() { + return views_views_api(); + } } if (!function_exists('profile_views_api')) { - function profile_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Profile module. + */ + function profile_views_api() { + return views_views_api(); + } } if (!function_exists('search_views_api')) { - function search_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Search module. + */ + function search_views_api() { + return views_views_api(); + } } if (!function_exists('statistics_views_api')) { - function statistics_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Statistics module. + */ + function statistics_views_api() { + return views_views_api(); + } } if (!function_exists('system_views_api')) { - function system_views_api() { return views_views_api(); } + /** + * Provide Views integration for the System module. + */ + function system_views_api() { + return views_views_api(); + } } if (!function_exists('tracker_views_api')) { - function tracker_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Tracker module. + */ + function tracker_views_api() { + return views_views_api(); + } } if (!function_exists('taxonomy_views_api')) { - function taxonomy_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Taxonomy module. + */ + function taxonomy_views_api() { + return views_views_api(); + } } if (!function_exists('translation_views_api')) { - function translation_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Translation module. + */ + function translation_views_api() { + return views_views_api(); + } } if (!function_exists('user_views_api')) { - function user_views_api() { return views_views_api(); } + /** + * Provide Views integration for the User module. + */ + function user_views_api() { + return views_views_api(); + } } if (!function_exists('contact_views_api')) { - function contact_views_api() { return views_views_api(); } + /** + * Provide Views integration for the Contact module. + */ + function contact_views_api() { + return views_views_api(); + } } diff --git a/sites/all/modules/views/views_ui.info b/sites/all/modules/views/views_ui.info index 21705ea..7a8e538 100644 --- a/sites/all/modules/views/views_ui.info +++ b/sites/all/modules/views/views_ui.info @@ -8,9 +8,8 @@ dependencies[] = views files[] = views_ui.module files[] = plugins/views_wizard/views_ui_base_views_wizard.class.php -; Information added by Drupal.org packaging script on 2017-08-23 -version = "7.x-3.18" +; Information added by Drupal.org packaging script on 2019-05-10 +version = "7.x-3.23" core = "7.x" project = "views" -datestamp = "1503495103" - +datestamp = "1557505389" diff --git a/sites/all/modules/views/views_ui.module b/sites/all/modules/views/views_ui.module index c33526a..0eadd6f 100644 --- a/sites/all/modules/views/views_ui.module +++ b/sites/all/modules/views/views_ui.module @@ -435,8 +435,7 @@ function views_ui_preprocess_views_view(&$vars) { /** * Theme preprocess for theme_views_ui_view_preview_section(). * - * @TODO - * Perhaps move this to includes/admin.inc or theme/theme.inc + * @todo Perhaps move this to includes/admin.inc or theme/theme.inc. */ function template_preprocess_views_ui_view_preview_section(&$vars) { switch ($vars['section']) { @@ -483,12 +482,12 @@ function template_preprocess_views_ui_view_preview_section(&$vars) { break; case 'attachment_before': - // @todo: Add links to the attachment configuration page. + // @todo Add links to the attachment configuration page. $vars['title'] = t('Attachment before'); break; case 'attachment_after': - // @todo: Add links to the attachment configuration page. + // @todo Add links to the attachment configuration page. $vars['title'] = t('Attachment after'); break; } @@ -524,9 +523,8 @@ function theme_views_ui_view_preview_section($vars) { * @param string $title * Add a bolded title of this section. * - * @TODO - * Bring in relationships - * Refactor this function to use much stuff of views_ui_edit_form_get_bucket. + * @todo Bring in relationships. + * @todo Refactor this function to use much of views_ui_edit_form_get_bucket. */ function views_ui_view_preview_section_handler_links($view, $type, $title = FALSE) { $display = $view->display_handler->display; @@ -806,6 +804,9 @@ function views_ui_contextual_links_suppress_pop() { * @see http://drupal.org/node/774876 */ function views_ui_ajax_get_form($form_id) { + $args = func_get_args(); + array_shift($args); + // @see ajax_get_form() $form_state = array( 'no_redirect' => TRUE, @@ -814,8 +815,6 @@ function views_ui_ajax_get_form($form_id) { $form_state['rebuild_info']['copy']['#action'] = TRUE; // @see drupal_get_form() - $args = func_get_args(); - array_shift($args); $form_state['build_info']['args'] = $args; $form = drupal_build_form($form_id, $form_state); @@ -904,7 +903,7 @@ function _views_ui_get_displays_list($view) { * @see /js/jquery.ui.dialog.patch.js * @see /js/jquery.ui.dialog.min.js * - * The javascript patch overwrites the $.ui.dialog.overlay.events object to + * The JavaScript patch overwrites the $.ui.dialog.overlay.events object to * remove the mousedown, mouseup and click events from the list of events that * are bound in $.ui.dialog.overlay.create. */