From 419704d1f3710626e08f2a4bc82aab6557d3a1f9 Mon Sep 17 00:00:00 2001 From: Nate Haug Date: Fri, 22 Apr 2016 18:43:23 -0700 Subject: [PATCH] Issue #905: Adding/fixing docblocks related to Redirect module. Enabling Redirect in standard profile. --- core/includes/database/select.inc | 24 ++- core/modules/redirect/redirect.admin.inc | 53 ++++-- core/modules/redirect/redirect.api.php | 110 ++++++----- core/modules/redirect/redirect.class.inc | 7 +- core/modules/redirect/redirect.module | 130 ++++++++----- core/modules/redirect/tests/redirect.test | 6 +- .../redirect/views/redirect.views_default.inc | 16 -- ...ect_handler_field_redirect_link_delete.inc | 4 +- ...irect_handler_field_redirect_link_edit.inc | 4 +- core/modules/redirect/views/redirects.view | 177 ------------------ .../views_handler_filter_in_operator.inc | 10 +- profiles/standard/standard.info | 1 + 12 files changed, 232 insertions(+), 310 deletions(-) delete mode 100644 core/modules/redirect/views/redirect.views_default.inc delete mode 100644 core/modules/redirect/views/redirects.view diff --git a/core/includes/database/select.inc b/core/includes/database/select.inc index 8dee73b328..68db595be1 100755 --- a/core/includes/database/select.inc +++ b/core/includes/database/select.inc @@ -22,12 +22,21 @@ interface QueryExtendableInterface { /** * Enhance this object by wrapping it in an extender object. * + * The core implementations of QueryExtendableInterface include: + * - TableSort: Extend a query to sort based on query strings. + * - PagerDefault: Extend a query to limit results based on query strings. + * - SearchQuery: Extend a query to join on the search index tables. + * + * Other implementations may be added by other modules, but for the sake of + * code validation, these core extenders are specified as possible return + * values of this interface. + * * @param $extender_name * The base name of the extending class. The base name will be checked * against the current database connection to allow driver-specific subclasses * as well, using the same logic as the query objects themselves. For example, * PagerDefault_mysql is the MySQL-specific override for PagerDefault. - * @return QueryExtendableInterface + * @return QueryExtendableInterface|SelectQueryInterface|TableSort|PagerDefault|SearchQuery * The extender object, which now contains a reference to this object. */ public function extend($extender_name); @@ -1291,6 +1300,19 @@ class SelectQuery extends Query implements SelectQueryInterface { return $alias; } + /** + * Add columns to be retrieved from a database table. + * + * @param $table_alias + * The table alias used when specifying a table to be added to the query, + * either through SelectQueryInterface::select(), + * SelectQueryInterface::join(), or other joining methods. + * @param array $fields + * An array of column names to be selected from this table. + * + * @return SelectQueryInterface + * The current select object. + */ public function fields($table_alias, array $fields = array()) { if ($fields) { diff --git a/core/modules/redirect/redirect.admin.inc b/core/modules/redirect/redirect.admin.inc index eb290654ff..fb5e54681b 100644 --- a/core/modules/redirect/redirect.admin.inc +++ b/core/modules/redirect/redirect.admin.inc @@ -151,13 +151,20 @@ function redirect_list_form($form, &$form_state) { } /** - * Return a form to filter URL redirects. + * Return a partial form to filter URL redirects. + * + * @param string $filter_value + * The default value for the filter textfield. + * + * @return array + * The partial form for filtering redirects. * + * @see redirect_list_form(). * @see redirect_list_filter_form_submit() * * @ingroup forms */ -function redirect_list_filter_form($keys = '') { +function redirect_list_filter_form($filter_value = '') { $form['#attributes'] = array('class' => array('search-form')); $form['basic'] = array( '#type' => 'fieldset', @@ -167,7 +174,7 @@ function redirect_list_filter_form($keys = '') { $form['basic']['filter'] = array( '#type' => 'textfield', '#title' => '', - '#default_value' => $keys, + '#default_value' => $filter_value, '#maxlength' => 128, '#size' => 25, ); @@ -176,7 +183,7 @@ function redirect_list_filter_form($keys = '') { '#value' => t('Filter'), '#submit' => array('redirect_list_filter_form_submit'), ); - if ($keys) { + if ($filter_value) { $form['basic']['reset'] = array( '#type' => 'submit', '#value' => t('Reset'), @@ -203,12 +210,14 @@ function redirect_list_filter_form_reset($form, &$form_state) { /** * Extends a query object for URL redirect filters. * - * @param $query + * @param QueryAlterableInterface $query * Query object that should be filtered. - * @param $keys - * The filter string to use. + * @param array $fields + * The fields within the query that should be checked for the $keys value. + * @param string $keys + * The filter string on which asterisks should be replaced with */ -function redirect_build_filter_query(QueryAlterableInterface $query, array $fields, $keys = '') { +function redirect_build_filter_query(SelectQueryInterface $query, array $fields, $keys = '') { if ($keys && $fields) { // Replace wildcards with PDO wildcards. $conditions = db_or(); @@ -271,6 +280,11 @@ function redirect_list_form_operations_submit($form, &$form_state) { /** * Form callback; Confirm a bulk operation on a list of redirects. * + * @param string $operation + * An operation string from hook_redirect_operations(). + * @param int[] $rids + * An array of redirect IDs on which the operation will be performed. + * * @see redirect_list_form() */ function redirect_list_form_operations_confirm_form($form, &$form_state, $operation, $rids) { @@ -318,6 +332,9 @@ function redirect_add_redirect_page() { /** * Form builder to add or edit an URL redirect. * + * @param Redirect|NULL $redirect + * The redirect object to be edited or NULL if creating a new redirect. + * * @see redirect_element_validate_source() * @see redirect_element_validate_redirect() * @see redirect_edit_form_validate() @@ -465,7 +482,7 @@ function redirect_element_validate_source($element, &$form_state) { $parsed_value = _redirect_extract_url_options($element, $form_state); - // Disallow redirections from the frontpage. + // Disallow redirects from the front page. if ($parsed_value['path'] === '') { form_error($element, t('The source path cannot be the front page.')); } @@ -597,12 +614,15 @@ function redirect_edit_form_submit($form, &$form_state) { /** * Form builder to delete an URL redirect. * + * @param Redirect $redirect + * The redirect object to be deleted. + * * @see redirect_delete_form() * @see confirm_form() * * @ingroup forms */ -function redirect_delete_form($form, &$form_state, $redirect) { +function redirect_delete_form($form, &$form_state, Redirect $redirect) { $form['rid'] = array( '#type' => 'value', '#value' => $redirect->rid, @@ -647,7 +667,7 @@ function redirect_settings_form($form, &$form_state) { '#type' => 'checkbox', '#title' => t('Retain query string through redirect.'), '#default_value' => $config->get('passthrough_querystring'), - '#description' => t('For example, given a redirect from %source to %redirect, if a user visits %sourcequery they would be redirected to %redirectquery. The query strings in the redirection will always take precedence over the current query string.', array('%source' => 'source-path', '%redirect' => 'node?a=apples', '%sourcequery' => 'source-path?a=alligators&b=bananas', '%redirectquery' => 'node?a=apples&b=bananas')), + '#description' => t('For example, given a redirect from %source to %redirect, if a user visits %source_query they would be redirected to %redirect_query. The query strings in the redirection will always take precedence over the current query string.', array('%source' => 'source-path', '%redirect' => 'node?a=apples', '%source_query' => 'source-path?a=alligators&b=bananas', '%redirect_query' => 'node?a=apples&b=bananas')), ); $form['additional_statuses'] = array( '#type' => 'radios', @@ -773,11 +793,14 @@ function redirect_404_list($form = NULL) { /** * Return a form to filter URL redirects. * + * @param string $filter_value + * The current string by which the list of 404s will be filtered. + * * @see redirect_list_filter_form_submit() * * @ingroup forms */ -function redirect_list_404_filter_form($form, &$form_state, $keys = '') { +function redirect_list_404_filter_form($form, &$form_state, $filter_value = '') { $form['#attributes'] = array('class' => array('search-form')); $form['help'] = array( '#markup' => '

' . @@ -792,7 +815,7 @@ function redirect_list_404_filter_form($form, &$form_state, $keys = '') { $form['basic']['filter'] = array( '#type' => 'textfield', '#title' => '', - '#default_value' => $keys, + '#default_value' => $filter_value, '#maxlength' => 128, '#size' => 25, ); @@ -801,7 +824,7 @@ function redirect_list_404_filter_form($form, &$form_state, $keys = '') { '#value' => t('Filter'), '#submit' => array('redirect_list_404_filter_form_submit'), ); - if ($keys) { + if ($filter_value) { $form['basic']['reset'] = array( '#type' => 'submit', '#value' => t('Reset'), @@ -828,7 +851,7 @@ function redirect_list_404_filter_form_reset($form, &$form_state) { /** * Display a list of redirects. Used on forms when editing an entity. * - * @param Redirects[] $redirects + * @param Redirect[] $redirects * An array of Redirect objects. * @param $header * The table header columns for the table. diff --git a/core/modules/redirect/redirect.api.php b/core/modules/redirect/redirect.api.php index 8135c2e5e8..a5a10f91d2 100644 --- a/core/modules/redirect/redirect.api.php +++ b/core/modules/redirect/redirect.api.php @@ -8,43 +8,25 @@ /** * @defgroup redirect_api_hooks Redirect API Hooks * @{ - * During redirect operations (create, update, view, delete, etc.), there are - * several sets of hooks that get invoked to allow modules to modify the - * redirect operation: - * - All-module hooks: Generic hooks for "redirect" operations. These are - * always invoked on all modules. - * - Entity hooks: Generic hooks for "entity" operations. These are always - * invoked on all modules. - * - * Here is a list of the redirect and entity hooks that are invoked, and other - * steps that take place during redirect operations: - * - Creating a new redirect (calling redirect_save() on a new redirect): - * - hook_redirect_presave() (all) - * - Redirect written to the database - * - hook_redirect_insert() (all) - * - hook_entity_insert() (all) - * - Updating an existing redirect (calling redirect_save() on an existing redirect): - * - hook_redirect_presave() (all) - * - Redirect written to the database - * - hook_redirect_update() (all) - * - hook_entity_update() (all) - * - Loading a redirect (calling redirect_load(), redirect_load_multiple(), or - * entity_load() with $entity_type of 'redirect'): - * - Redirect information is read from database. - * - hook_entity_load() (all) - * - hook_redirect_load() (all) - * - Deleting a redirect (calling redirect_delete() or redirect_delete_multiple()): - * - Redirect is loaded (see Loading section above) - * - Redirect information is deleted from database - * - hook_redirect_delete() (all) - * - hook_entity_delete() (all) - * - Preparing a redirect for editing (note that if it's - * an existing redirect, it will already be loaded; see the Loading section - * above): - * - hook_redirect_prepare() (all) - * - Validating a redirect during editing form submit (calling - * redirect_form_validate()): - * - hook_redirect_validate() (all) + * Redirects may be created by end-users to manually redirect from one URL on + * the site to another one (or to an external URL). For example the path + * "about" may be redirected to "pages/about-us" after a site redesign. The old + * URLs should be redirect to the new ones to maintain search engine rankings, + * existing links, and bookmarks to the old URL. + * + * Redirects are stored in the database in the "redirect" table. Loading and + * saving of redirects should be done through the Redirect API to ensure modules + * responding to the modification of redirects also have an opportunity to + * make adjustments as needed. The Redirect object is used to wrap around all + * the operations that can be done on redirects. It is recommended that + * redirects be loaded using one of the existing functions for loading, or + * if creating a new redirect, created by instantiating a new Redirect object. + * + * @see Redirect + * @see redirect_load() + * @see redirect_load_multiple() + * @see redirect_load_by_source() + * * @} */ @@ -57,15 +39,12 @@ * Act on redirects being loaded from the database. * * This hook is invoked during redirect loading, which is handled by - * entity_load(), via classes RedirectController and - * DefaultEntityController. After the redirect information is read from - * the database or the entity cache, hook_entity_load() is invoked on all - * implementing modules, and then hook_redirect_load() is invoked on all - * implementing modules. + * redirect_load_multiple(). After the redirect information is read from + * the database hook_redirect_load() is invoked on all implementing modules. * * This hook should only be used to add information that is not in the redirect * table, not to replace information that is in that table (which could - * interfere with the entity cache). For performance reasons, information for + * interfere with saving). For performance reasons, information for * all available redirects should be loaded in a single query where possible. * * The $types parameter allows for your module to have an early return (for @@ -123,7 +102,7 @@ function hook_redirect_load_by_source_alter(array &$redirects, $source, array $c * block access, return REDIRECT_ACCESS_IGNORE or simply return nothing. * Blindly returning FALSE will break other redirect access modules. * - * @param $redirect + * @param Redirect|string $redirect * The redirect object on which the operation is to be performed, or, if it * does not yet exist, the type of redirect to be created. * @param $op @@ -135,10 +114,10 @@ function hook_redirect_load_by_source_alter(array &$redirects, $source, array $c * A user object representing the user for whom the operation is to be * performed. * - * @return + * @return string|NULL * REDIRECT_ACCESS_ALLOW if the operation is to be allowed; * REDIRECT_ACCESS_DENY if the operation is to be denied; - * REDIRECT_ACCESSS_IGNORE to not affect this operation at all. + * REDIRECT_ACCESS_IGNORE to not affect this operation at all. * * @see redirect_access() * @ingroup redirect_api_hooks @@ -171,16 +150,24 @@ function hook_redirect_access($op, $redirect, $account) { /** * Act on a redirect object about to be shown on the add/edit form. * - * This hook is invoked from the Redirect object contructor in + * This hook is invoked from the Redirect object constructor in * Redirect::__construct(). * - * @param $redirect - * The redirect that is about to be shown on the add/edit form. + * @param Redirect $redirect + * A newly initialized redirect object. Likely to be shown on the form for + * adding or editing a redirect. + * @param array $values + * The default values for the Redirect from the database if editing an + * existing Redirect. * * @ingroup redirect_api_hooks */ -function hook_redirect_prepare($redirect) { - +function hook_redirect_prepare(Redirect $redirect, array $values) { + // Change the default type to be a 302 temporary redirect instead of a 301 + // permanent redirect. + if (empty($values['type'])) { + $redirect->type = 302; + } } /** @@ -289,6 +276,27 @@ function hook_redirect_delete($redirect) { * @ingroup redirect_api_hooks */ function hook_redirect_alter($redirect) { + // Make any redirect going to the homepage considered temporary. + if ($redirect->redirect = '') { + $redirect->type = 302; + } +} + +/** + * Provide additional operations that may be done on redirects. + * + * @return array + * An array of callback information for executing the operation. + */ +function hook_redirect_operations() { + // Example from redirect_redirect_operations(): + $operations['delete'] = array( + 'action' => t('Delete'), + 'action_past' => t('Deleted'), + 'callback' => 'redirect_delete_multiple', + 'confirm' => TRUE, + ); + return $operations; } /** diff --git a/core/modules/redirect/redirect.class.inc b/core/modules/redirect/redirect.class.inc index 5a66487334..f7a9bfa3fc 100644 --- a/core/modules/redirect/redirect.class.inc +++ b/core/modules/redirect/redirect.class.inc @@ -84,6 +84,11 @@ class Redirect { */ public $count = 0; + /** + * A timestamp of the last time this redirect was accessed. + */ + public $access = 0; + /** * Hashes are an alternative ID by which a redirect may be loaded. * @@ -122,7 +127,7 @@ class Redirect { $this->redirect_options = unserialize($this->redirect_options); } - module_invoke_all('redirect_prepare', $this); + module_invoke_all('redirect_prepare', $this, $values); } /** diff --git a/core/modules/redirect/redirect.module b/core/modules/redirect/redirect.module index dad4220bee..a28146356b 100644 --- a/core/modules/redirect/redirect.module +++ b/core/modules/redirect/redirect.module @@ -26,27 +26,6 @@ define('REDIRECT_ACCESS_DENY', 'deny'); */ define('REDIRECT_ACCESS_IGNORE', NULL); -/** - * Implements hook_entity_info(). - */ -function redirect_entity_info() { - $info['redirect'] = array( - 'label' => t('Redirect'), - 'base table' => 'redirect', - 'entity class' => 'Redirect', - 'controller class' => 'RedirectController', - 'entity keys' => array( - 'id' => 'rid', - 'bundle' => 'type', - ), - 'fieldable' => FALSE, - 'uuid' => FALSE, - 'redirect' => FALSE, - ); - - return $info; -} - /** * Implements hook_hook_info(). */ @@ -72,7 +51,7 @@ function redirect_hook_info() { */ function redirect_permission() { $permissions['administer redirects'] = array( - 'title' => t('Administer URL redirections'), + 'title' => t('Administer URL redirects'), ); return $permissions; } @@ -131,7 +110,7 @@ function redirect_menu() { ); // Add an action link to the 404 page. - $site_404 = config_get('system.c'); + $site_404 = config_get('system.core', 'site_404'); if (empty($path)) { $site_404 = 'system/404'; } @@ -207,7 +186,7 @@ function redirect_get_current_redirect() { function redirect_url_inbound_alter(&$path, $original_path, $path_language) { // If the inbound path has been changed, then attempt to find a redirect // matching the original path and save it for processing later in - // redirect_init(). For example, if the Sub-pathauto module changes the path + // redirect_init(). For example, if the Sub-Pathauto module changes the path // 'foo/redirect' to 'node/1/redirect', and there is a redirect enabled for // the path 'foo/redirect', then redirect_init() would normally fail since it // would not find a match. @@ -226,9 +205,11 @@ function redirect_url_inbound_alter(&$path, $original_path, $path_language) { * @param $entity_type * An entity type. * - * @return - * TRUE if the entity type has an uri callback and supports redirects, or - * FALSE otherwise. + * @return bool + * TRUE if the entity type has specified that it supports redirects in + * hook_entity_info(). FALSE otherwise. + * + * @see hook_entity_info() */ function redirect_entity_type_supports_redirects($entity_type) { $types = &backdrop_static(__FUNCTION__); @@ -518,7 +499,7 @@ function redirect_load_by_source($source, $langcode = LANGUAGE_NONE, array $quer * @param $reset * Whether to reset the redirect_load_multiple cache. * - * @return + * @return Redirect[] * An array of URL redirect objects indexed by redirect IDs. * * @ingroup redirect_api @@ -530,6 +511,7 @@ function redirect_load_multiple(array $rids = array(), array $conditions = array } $new_rids = array_diff($rids, array_keys($cached_redirects)); + $added_redirects = array(); if ($new_rids || $conditions) { $query = db_select('redirect')->fields('redirect'); if ($rids) { @@ -539,7 +521,6 @@ function redirect_load_multiple(array $rids = array(), array $conditions = array $query->condition($key, $value); } $rows = $query->execute()->fetchAllAssoc('rid', PDO::FETCH_ASSOC); - $added_redirects = array(); foreach ($rows as $rid => $row) { if ($rows[$rid]) { $added_redirects[$rid] = new Redirect($row); @@ -583,7 +564,7 @@ function redirect_load_multiple(array $rids = array(), array $conditions = array * Optional, a user object representing the user for whom the operation is to * be performed. Determines access for a user other than the current user. * - * @return + * @return bool * TRUE if the operation may be performed, FALSE otherwise. */ function redirect_access($op, $redirect, $account = NULL) { @@ -632,6 +613,9 @@ function redirect_access($op, $redirect, $account = NULL) { /** * Validate a redirect. + * + * @param Redirect $redirect + * The Redirect object to be validated. */ function redirect_validate(Redirect $redirect, $form, &$form_state) { // Check that there there are no redirect loops. @@ -660,6 +644,12 @@ function redirect_validate(Redirect $redirect, $form, &$form_state) { * The Redirect object to be saved. If $redirect->rid is omitted (or * $redirect->is_new is TRUE), a new redirect will be added. * + * @return int + * The constants SAVED_NEW or SAVED_UPDATED. + * + * @throws Exception + * A generic exception if the redirect cannot be saved. + * * @ingroup redirect_api */ function redirect_save(Redirect $redirect) { @@ -720,14 +710,14 @@ function redirect_save(Redirect $redirect) { /** * Implements hook_redirect_insert(). */ -function redirect_redirect_insert($redirect) { +function redirect_redirect_insert(Redirect $redirect) { redirect_page_cache_clear($redirect); } /** * Implements hook_redirect_update(). */ -function redirect_redirect_update($redirect) { +function redirect_redirect_update(Redirect $redirect) { redirect_page_cache_clear($redirect); // Clear the page cache for the original redirect as well. @@ -739,7 +729,7 @@ function redirect_redirect_update($redirect) { /** * Implements hook_redirect_delete(). */ -function redirect_redirect_delete($redirect) { +function redirect_redirect_delete(Redirect $redirect) { redirect_page_cache_clear($redirect); } @@ -749,6 +739,12 @@ function redirect_redirect_delete($redirect) { * @param $rid * The ID of the redirect to delete. * + * @return int + * The constant SAVED_DELETED on success. + * + * @throws Exception + * A generic exception if the redirects could not be deleted. + * * @ingroup redirect_api */ function redirect_delete($rid) { @@ -814,6 +810,12 @@ function redirect_delete_by_entity_path($entity) { * @param $rids * An array of redirect IDs to delete. * + * @return int + * The constant SAVED_DELETED on success. + * + * @throws Exception + * A generic exception if the redirects could not be deleted. + * * @ingroup redirect_api */ function redirect_delete_multiple(array $rids) { @@ -861,7 +863,7 @@ function redirect_purge_inactive_redirects(array $types = array('redirect'), $in } // If there is no interval at all, do not discard any redirects. if (empty($interval)) { - return; + return array(); } $query = db_select('redirect'); @@ -918,8 +920,14 @@ function redirect_redirect($redirect = NULL) { /** * Redirect callback; perform an URL redirect. + * + * @param Redirect $redirect + * The Redirect that should be executed. + * + * @return NULL + * This function will end the execution of the current page. */ -function redirect_goto($redirect) { +function redirect_goto(Redirect $redirect) { $redirect->redirect_options['absolute'] = TRUE; $url = url($redirect->redirect, $redirect->redirect_options); backdrop_add_http_header('Location', $url); @@ -964,6 +972,9 @@ function redirect_hash(Redirect $redirect) { /** * Clear a page from the page cache. + * + * @param Redirect $redirect + * The redirect upon which the cache-clear should be based. */ function redirect_page_cache_clear(Redirect $redirect) { $path = url($redirect->source, array('absolute' => TRUE)); @@ -982,8 +993,8 @@ function redirect_page_cache_clear(Redirect $redirect) { * - If the current request does not have any POST data since a redirect * may interrupt form submission. * - * @return - * TRUE if redirections can be performed, or FALSE otherwise. + * @return bool + * TRUE if redirects can be performed, or FALSE otherwise. */ function redirect_can_redirect() { $can_redirect = &backdrop_static(__FUNCTION__); @@ -1020,7 +1031,7 @@ function redirect_can_redirect() { * The array that has the values. * @param $haystack * The array that will be searched for values. - * @return + * @return bool * TRUE if all the elements of $match were found in $haystack, or FALSE * otherwise. */ @@ -1045,7 +1056,7 @@ function redirect_compare_array_recursive($match, $haystack) { } /** - * Sort an array recusively. + * Sort an array recursively. * * @param $array * The array to sort, by reference. @@ -1067,6 +1078,18 @@ function redirect_sort_recursive(&$array, $callback = 'sort') { /** * Build the URL of a redirect for display purposes only. + * + * @param string $path + * The internal Backdrop path to be displayed. + * @param array $options + * An array of options as would be passed into the url() function. + * @param bool|NULL $clean_url + * Whether the returns string should use clean URLs or not. Defaults to the + * site-wide setting for clean URLs. + * + * @return string + * A string suitable for display. Note this is not yet escaped for HTML, + * so check_plain() should still be used if printing to HTML. */ function redirect_url($path, array $options = array(), $clean_url = NULL) { if (!isset($clean_url)) { @@ -1117,12 +1140,32 @@ function redirect_url($path, array $options = array(), $clean_url = NULL) { } /** - * Parse URLs into consituent parts. - * fragment, query, protocol, and URL. + * Parse URLs into component parts: fragment, query, protocol, and URL. + * + * This function extends the PHP parse_url() function. In addition to the return + * array normally provided by that function, this does additional parsing, + * including: + * - Removing the hash symbol from the "fragment" value. + * - Converting the "query" value into an array instead of a string. + * - Adds an "https" value indicating an https scheme. + * - Adds a "url" value that is suitable for passing into the url() function. + * If given a full URL of the current site, the hostname, scheme, and port + * will be stripped from this value. External URLs will be unaffected. * * @param string $url. * * @return array $parsed. + * An array with the following keys: + * - scheme: Usually "http" or "https". + * - host: The hostname, e.g. "example.com". + * - port: The port number. + * - user: Any HTTP user in a URL such as user:pass@example.com. + * - pass: Any HTTP password that is used with the "user". + * - path: The path portion of the URL. + * - query: An array of query string parameters. + * - fragment: Any string after the hash (#) symbol. + * - url: A local internal Backdrop path or a full external URL. + * - https: Whether the URL starts with "https". */ function redirect_parse_url($url) { $original_url = $url; @@ -1250,8 +1293,7 @@ function locale_form_redirect_edit_form_alter(&$form, &$form_state) { * Implements hook_field_attach_form(). */ function redirect_field_attach_form($entity_type, Entity $entity, &$form, &$form_state, $langcode) { - list($id) = entity_extract_ids($entity_type, $entity); - if (!empty($form['redirect']) || empty($id)) { + if (!empty($form['redirect']) || $entity->isNew()) { return; } @@ -1299,7 +1341,7 @@ function redirect_field_attach_form($entity_type, Entity $entity, &$form, &$form ); if (redirect_access('create', 'redirect')) { $form['redirect']['actions']['#links']['add'] = array( - 'title' => t('Add URL redirect to this @entitytype', array('@entitytype' => backdrop_strtolower($info['label']))), + 'title' => t('Add URL redirect to this @type', array('@type' => backdrop_strtolower($info['label']))), 'href' => 'admin/config/search/redirect/add', 'query' => array_filter($redirect) + backdrop_get_destination(), ); diff --git a/core/modules/redirect/tests/redirect.test b/core/modules/redirect/tests/redirect.test index 21041bed4f..941c788be2 100644 --- a/core/modules/redirect/tests/redirect.test +++ b/core/modules/redirect/tests/redirect.test @@ -38,10 +38,12 @@ class RedirectTestHelper extends BackdropWebTestCase { /** * Add an URL redirection. * - * @param $source + * @param string $source_path * A source path. - * @param $redirect + * @param string $redirect_path * A redirect path. + * @param array $redirect + * An array of values from which a Redirect object will be created. * * @return Redirect * A redirect object. diff --git a/core/modules/redirect/views/redirect.views_default.inc b/core/modules/redirect/views/redirect.views_default.inc deleted file mode 100644 index a7f1cd0bcb..0000000000 --- a/core/modules/redirect/views/redirect.views_default.inc +++ /dev/null @@ -1,16 +0,0 @@ - $file) { - require $path; - if (isset($view)) { - $views[$view->name] = $view; - } - } - return $views; -} diff --git a/core/modules/redirect/views/redirect_handler_field_redirect_link_delete.inc b/core/modules/redirect/views/redirect_handler_field_redirect_link_delete.inc index 7d29139f28..e41b333fb1 100644 --- a/core/modules/redirect/views/redirect_handler_field_redirect_link_delete.inc +++ b/core/modules/redirect/views/redirect_handler_field_redirect_link_delete.inc @@ -32,10 +32,12 @@ class redirect_handler_field_redirect_link_delete extends views_handler_field { } function render($values) { + $output = ''; $rid = $values->{$this->aliases['rid']}; if (($redirect = redirect_load($rid)) && redirect_access('delete', $redirect)) { $text = !empty($this->options['text']) ? $this->options['text'] : t('Delete'); - return l($text, "admin/config/search/redirect/delete/" . $rid, array('query' => backdrop_get_destination())); + $output = l($text, "admin/config/search/redirect/delete/" . $rid, array('query' => backdrop_get_destination())); } + return $output; } } diff --git a/core/modules/redirect/views/redirect_handler_field_redirect_link_edit.inc b/core/modules/redirect/views/redirect_handler_field_redirect_link_edit.inc index 4724600928..68c044ae38 100644 --- a/core/modules/redirect/views/redirect_handler_field_redirect_link_edit.inc +++ b/core/modules/redirect/views/redirect_handler_field_redirect_link_edit.inc @@ -33,9 +33,11 @@ class redirect_handler_field_redirect_link_edit extends views_handler_field { function render($values) { $rid = $values->{$this->aliases['rid']}; + $output = ''; if (($redirect = redirect_load($rid)) && redirect_access('update', $redirect)) { $text = !empty($this->options['text']) ? $this->options['text'] : t('Edit'); - return l($text, "admin/config/search/redirect/edit/" . $rid, array('query' => backdrop_get_destination())); + $output = l($text, "admin/config/search/redirect/edit/" . $rid, array('query' => backdrop_get_destination())); } + return $output; } } diff --git a/core/modules/redirect/views/redirects.view b/core/modules/redirect/views/redirects.view deleted file mode 100644 index fd9e777f5b..0000000000 --- a/core/modules/redirect/views/redirects.view +++ /dev/null @@ -1,177 +0,0 @@ -name = 'redirects'; -$view->description = 'Displays a list of redirects on user and admin pages.'; -$view->tag = ''; -$view->base_table = 'redirect'; -$view->human_name = 'Redirects'; -$view->core = 0; -$view->api_version = '3.0'; -$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */ - -/* Display: Defaults */ -$handler = $view->new_display('default', 'Defaults', 'default'); -$handler->display->display_options['use_more_always'] = FALSE; -$handler->display->display_options['access']['type'] = 'perm'; -$handler->display->display_options['access']['perm'] = 'administer redirects'; -$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'] = '25'; -$handler->display->display_options['pager']['options']['offset'] = '0'; -$handler->display->display_options['pager']['options']['id'] = '0'; -$handler->display->display_options['style_plugin'] = 'table'; -$handler->display->display_options['style_options']['columns'] = array( - 'source' => 'source', - 'redirect' => 'redirect', - 'language' => 'language', - 'count' => 'count', - 'access' => 'access', - 'edit_redirect' => 'edit_redirect', - 'delete_redirect' => 'delete_redirect', -); -$handler->display->display_options['style_options']['default'] = '-1'; -$handler->display->display_options['style_options']['info'] = array( - 'source' => array( - 'sortable' => 1, - 'align' => '', - 'separator' => '', - ), - 'redirect' => array( - 'sortable' => 1, - 'align' => '', - 'separator' => '', - ), - 'language' => array( - 'sortable' => 1, - 'align' => '', - 'separator' => '', - ), - 'count' => array( - 'sortable' => 1, - 'align' => '', - 'separator' => '', - ), - 'access' => array( - 'sortable' => 1, - 'align' => '', - 'separator' => '', - ), - 'edit_redirect' => array( - 'align' => '', - 'separator' => '', - ), - 'delete_redirect' => array( - 'align' => '', - 'separator' => '', - ), -); -$handler->display->display_options['style_options']['sticky'] = TRUE; -/* 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']['content'] = 'No URL redirects found.'; -$handler->display->display_options['empty']['area']['format'] = '1'; -/* Field: Redirect: Redirect ID */ -$handler->display->display_options['fields']['rid']['id'] = 'rid'; -$handler->display->display_options['fields']['rid']['table'] = 'redirect'; -$handler->display->display_options['fields']['rid']['field'] = 'rid'; -$handler->display->display_options['fields']['rid']['exclude'] = TRUE; -/* Field: Redirect: Source URL */ -$handler->display->display_options['fields']['source']['id'] = 'source'; -$handler->display->display_options['fields']['source']['table'] = 'redirect'; -$handler->display->display_options['fields']['source']['field'] = 'source'; -$handler->display->display_options['fields']['source']['absolute'] = 0; -/* Field: Redirect: Redirect URL */ -$handler->display->display_options['fields']['redirect']['id'] = 'redirect'; -$handler->display->display_options['fields']['redirect']['table'] = 'redirect'; -$handler->display->display_options['fields']['redirect']['field'] = 'redirect'; -$handler->display->display_options['fields']['redirect']['alter']['path'] = 'node'; -$handler->display->display_options['fields']['redirect']['alter']['absolute'] = TRUE; -$handler->display->display_options['fields']['redirect']['absolute'] = 0; -/* Field: Redirect: Language */ -$handler->display->display_options['fields']['language']['id'] = 'language'; -$handler->display->display_options['fields']['language']['table'] = 'redirect'; -$handler->display->display_options['fields']['language']['field'] = 'language'; -$handler->display->display_options['fields']['language']['empty'] = 'All'; -/* Field: Redirect: Clicks */ -$handler->display->display_options['fields']['count']['id'] = 'count'; -$handler->display->display_options['fields']['count']['table'] = 'redirect'; -$handler->display->display_options['fields']['count']['field'] = 'count'; -/* Field: Redirect: Last accessed date */ -$handler->display->display_options['fields']['access']['id'] = 'access'; -$handler->display->display_options['fields']['access']['table'] = 'redirect'; -$handler->display->display_options['fields']['access']['field'] = 'access'; -$handler->display->display_options['fields']['access']['label'] = 'Last accessed'; -$handler->display->display_options['fields']['access']['empty'] = 'Never'; -$handler->display->display_options['fields']['access']['empty_zero'] = TRUE; -$handler->display->display_options['fields']['access']['date_format'] = 'time ago'; -/* Field: Redirect: Operations */ -$handler->display->display_options['fields']['operations']['id'] = 'operations'; -$handler->display->display_options['fields']['operations']['table'] = 'redirect'; -$handler->display->display_options['fields']['operations']['field'] = 'operations'; -/* Filter criterion: Redirect: Type */ -$handler->display->display_options['filters']['type']['id'] = 'type'; -$handler->display->display_options['filters']['type']['table'] = 'redirect'; -$handler->display->display_options['filters']['type']['field'] = 'type'; -$handler->display->display_options['filters']['type']['value'] = array( - 'redirect' => 'redirect', -); - -/* Display: Page: User redirects */ -$handler = $view->new_display('page', 'Page: User redirects', 'page_user'); -$handler->display->display_options['defaults']['hide_admin_links'] = FALSE; -$handler->display->display_options['defaults']['arguments'] = FALSE; -/* Contextual filter: Redirect: User ID */ -$handler->display->display_options['arguments']['uid']['id'] = 'uid'; -$handler->display->display_options['arguments']['uid']['table'] = 'redirect'; -$handler->display->display_options['arguments']['uid']['field'] = 'uid'; -$handler->display->display_options['arguments']['uid']['default_action'] = 'default'; -$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'user'; -$handler->display->display_options['arguments']['uid']['default_argument_options']['user'] = FALSE; -$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary'; -$handler->display->display_options['path'] = 'user/%/redirects'; -$handler->display->display_options['menu']['type'] = 'tab'; -$handler->display->display_options['menu']['title'] = 'Redirects'; -$handler->display->display_options['menu']['weight'] = '0'; - -/* Display: Page: Admin redirects */ -$handler = $view->new_display('page', 'Page: Admin redirects', 'page_admin'); -$handler->display->display_options['defaults']['hide_admin_links'] = FALSE; -$handler->display->display_options['path'] = 'admin/config/search/redirect/list'; -$handler->display->display_options['menu']['type'] = 'default tab'; -$handler->display->display_options['menu']['title'] = 'List'; -$handler->display->display_options['menu']['weight'] = '0'; -$handler->display->display_options['menu']['name'] = 'main-menu'; -$handler->display->display_options['tab_options']['weight'] = '0'; -$translatables['redirects'] = array( - t('Defaults'), - t('more'), - t('Apply'), - t('Reset'), - t('Sort by'), - t('Asc'), - t('Desc'), - t('Items per page'), - t('- All -'), - t('Offset'), - t('« first'), - t('‹ previous'), - t('next ›'), - t('last »'), - t('No URL redirects found.'), - t('Redirect ID'), - t('Source URL'), - t('Redirect URL'), - t('Language'), - t('All'), - t('Clicks'), - t('Last accessed'), - t('Never'), - t('Operations'), - t('Page: User redirects'), - t('Page: Admin redirects'), -); diff --git a/core/modules/views/handlers/views_handler_filter_in_operator.inc b/core/modules/views/handlers/views_handler_filter_in_operator.inc index eed60ce89d..b2ee946243 100755 --- a/core/modules/views/handlers/views_handler_filter_in_operator.inc +++ b/core/modules/views/handlers/views_handler_filter_in_operator.inc @@ -18,8 +18,16 @@ class views_handler_filter_in_operator extends views_handler_filter { var $value_form_type = 'checkboxes'; /** - * @var array + * The title used when display this filter as an HTML form field. + * + * @var string + */ + var $value_title; + + /** * Stores all operations which are available on the form. + * + * @var array */ var $value_options = NULL; diff --git a/profiles/standard/standard.info b/profiles/standard/standard.info index 5cce2e0b98..aa452b43da 100644 --- a/profiles/standard/standard.info +++ b/profiles/standard/standard.info @@ -20,6 +20,7 @@ dependencies[] = menu dependencies[] = number dependencies[] = options dependencies[] = path +dependencies[] = redirect dependencies[] = taxonomy dependencies[] = dblog dependencies[] = search