diff --git a/core/includes/common.inc b/core/includes/common.inc index a1834f6..e584c40 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -33,6 +33,37 @@ use Drupal\Core\Session\AnonymousUserSession; /** + * @defgroup php_wrappers PHP wrapper functions + * @{ + * Functions that are wrappers or custom implementations of PHP functions. + * + * Certain PHP functions should not be used in Drupal. Instead, Drupal's + * replacement functions should be used. + * + * For example, for improved or more secure UTF8-handling, or RFC-compliant + * handling of URLs in Drupal. + * + * For ease of use and memorizing, all these wrapper functions use the same name + * as the original PHP function, but prefixed with "drupal_". Beware, however, + * that not all wrapper functions support the same arguments as the original + * functions. + * + * You should always use these wrapper functions in your code. + * + * Wrong: + * @code + * $my_substring = substr($original_string, 0, 5); + * @endcode + * + * Correct: + * @code + * $my_substring = drupal_substr($original_string, 0, 5); + * @endcode + * + * @} + */ + +/** * Return status for saving which involved creating a new item. */ const SAVED_NEW = 1; @@ -302,6 +333,12 @@ function drupal_get_destination() { } /** + * @defgroup validation Input validation + * @{ + * Functions to validate user input. + */ + +/** * Verifies the syntax of the given email address. * * This uses the @@ -318,6 +355,19 @@ function valid_email_address($mail) { } /** + * @} End of "defgroup validation". + */ + +/** + * @defgroup sanitization Sanitization functions + * @{ + * Functions to sanitize values. + * + * See http://drupal.org/writing-secure-code for information + * on writing secure code. + */ + +/** * Strips dangerous protocols from a URI and encodes it for output to HTML. * * @param $uri @@ -340,6 +390,16 @@ function check_url($uri) { } /** + * @} End of "defgroup sanitization". + */ + +/** + * @defgroup format Formatting + * @{ + * Functions to format numbers, strings, dates, etc. + */ + +/** * Formats an RSS channel. * * Arbitrary elements may be added using the $args associative array. @@ -622,6 +682,10 @@ function _format_date_callback(array $matches = NULL, $new_langcode = NULL) { } /** + * @} End of "defgroup format". + */ + +/** * Generates an internal or external URL. * * When creating links in modules, consider whether l() could be a better @@ -4120,4 +4184,59 @@ function drupal_get_filetransfer_info() { uasort($info, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement')); } return $info; -} \ No newline at end of file +} + +/** + * @defgroup queue Queue operations + * @{ + * Queue items to allow later processing. + * + * The queue system allows placing items in a queue and processing them later. + * The system tries to ensure that only one consumer can process an item. + * + * Before a queue can be used it needs to be created by + * Drupal\Core\Queue\QueueInterface::createQueue(). + * + * Items can be added to the queue by passing an arbitrary data object to + * Drupal\Core\Queue\QueueInterface::createItem(). + * + * To process an item, call Drupal\Core\Queue\QueueInterface::claimItem() and + * specify how long you want to have a lease for working on that item. + * When finished processing, the item needs to be deleted by calling + * Drupal\Core\Queue\QueueInterface::deleteItem(). If the consumer dies, the + * item will be made available again by the Drupal\Core\Queue\QueueInterface + * implementation once the lease expires. Another consumer will then be able to + * receive it when calling Drupal\Core\Queue\QueueInterface::claimItem(). + * Due to this, the processing code should be aware that an item might be handed + * over for processing more than once. + * + * The $item object used by the Drupal\Core\Queue\QueueInterface can contain + * arbitrary metadata depending on the implementation. Systems using the + * interface should only rely on the data property which will contain the + * information passed to Drupal\Core\Queue\QueueInterface::createItem(). + * The full queue item returned by Drupal\Core\Queue\QueueInterface::claimItem() + * needs to be passed to Drupal\Core\Queue\QueueInterface::deleteItem() once + * processing is completed. + * + * There are two kinds of queue backends available: reliable, which preserves + * the order of messages and guarantees that every item will be executed at + * least once. The non-reliable kind only does a best effort to preserve order + * in messages and to execute them at least once but there is a small chance + * that some items get lost. For example, some distributed back-ends like + * Amazon SQS will be managing jobs for a large set of producers and consumers + * where a strict FIFO ordering will likely not be preserved. Another example + * would be an in-memory queue backend which might lose items if it crashes. + * However, such a backend would be able to deal with significantly more writes + * than a reliable queue and for many tasks this is more important. See + * aggregator_cron() for an example of how to effectively utilize a + * non-reliable queue. Another example is doing Twitter statistics -- the small + * possibility of losing a few items is insignificant next to power of the + * queue being able to keep up with writes. As described in the processing + * section, regardless of the queue being reliable or not, the processing code + * should be aware that an item might be handed over for processing more than + * once (because the processing code might time out before it finishes). + */ + +/** + * @} End of "defgroup queue". + */ diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 77fd447..da0fa2a 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -10,6 +10,252 @@ use Drupal\Core\Template\Attribute; /** + * @defgroup menu Menu and routing system + * @{ + * Define the navigation menus, and route page requests to code based on URLs. + * + * @section sec_overview Overview and terminology + * The Drupal routing system defines how Drupal responds to URL requests that + * the web server passes on to Drupal. The routing system is based on the + * @link http://symfony.com Symfony framework. @endlink The central idea is + * that Drupal subsystems and modules can register routes (basically, URL + * paths and context); they can also register to respond dynamically to + * routes, for more flexibility. When Drupal receives a URL request, it will + * attempt to match the request to a registered route, and query dynamic + * responders. If a match is made, Drupal will then instantiate the required + * classes, gather the data, format it, and send it back to the web browser. + * Otherwise, Drupal will return a 404 or 403 response. + * + * The menu system uses routes; it is used for navigation menus, local tasks, + * local actions, and contextual links: + * - Navigation menus are hierarchies of menu links; links point to routes or + * URLs. + * - Menu links and their hierarchies can be defined by Drupal subsystems + * and modules, or created in the user interface using the Menu UI module. + * - Local tasks are groups of related routes. Local tasks are usually rendered + * as a group of tabs. + * - Local actions are used for operations such as adding a new item on a page + * that lists items of some type. Local actions are usually rendered as + * buttons. + * - Contextual links are actions that are related to sections of rendered + * output, and are usually rendered as a pop-up list of links. The + * Contextual Links module handles the gathering and rendering of contextual + * links. + * + * The following sections of this topic provide an overview of the routing and + * menu APIs. For more detailed information, see + * https://www.drupal.org/developing/api/8/routing and + * https://www.drupal.org/developing/api/8/menu + * + * @section sec_register Registering simple routes + * To register a route, add lines similar to this to a module_name.routing.yml + * file in your top-level module directory: + * @code + * dblog.overview: + * path: '/admin/reports/dblog' + * defaults: + * _content: '\Drupal\dblog\Controller\DbLogController::overview' + * _title: 'Recent log messages' + * requirements: + * _permission: 'access site reports' + * @endcode + * Some notes: + * - The first line is the machine name of the route. Typically, it is prefixed + * by the machine name of the module that defines the route, or the name of + * a subsystem. + * - The 'path' line gives the URL path of the route (relative to the site's + * base URL). + * - The 'defaults' section tells how to build the main content of the route, + * and can also give other information, such as the page title and additional + * arguments for the route controller method. There are several possibilities + * for how to build the main content, including: + * - _content: A callable, usually a method on a page controller class + * (see @ref sec_controller below for details). + * - _controller: A callable, usually a method on a page controller class + * (see @ref sec_controller below for details). + * - _form: A form controller class. See the + * @link form_api Form API topic @endlink for more information about + * form controllers. + * - _entity_form: A form for editing an entity. See the + * @link entity_api Entity API topic @endlink for more information. + * - The 'requirements' section is used in Drupal to give access permission + * instructions (it has other uses in the Symfony framework). Most + * routes have a simple permission-based access scheme, as shown in this + * example. See the @link user_api Permission system topic @endlink for + * more information about permissions. + * + * See https://www.drupal.org/node/2092643 for more details about *.routing.yml + * files, and https://www.drupal.org/node/2122201 for information on how to + * set up dynamic routes. + * + * @section sec_placeholders Defining routes with placeholders + * Some routes have placeholders in them, and these can also be defined in a + * module_name.routing.yml file, as in this example from the Block module: + * @code + * block.admin_edit: + * path: '/admin/structure/block/manage/{block}' + * defaults: + * _entity_form: 'block.default' + * _title: 'Configure block' + * requirements: + * _entity_access: 'block.update' + * @endcode + * In the path, '{block}' is a placeholder - it will be replaced by the + * ID of the block that is being configured by the entity system. See the + * @link entity_api Entity API topic @endlink for more information. + * + * @section sec_controller Route controllers for simple routes + * For simple routes, after you have defined the route in a *.routing.yml file + * (see @ref sec_register above), the next step is to define a page controller + * class and method. Page controller classes do not necessarily need to + * implement any particular interface or extend any particular base class. The + * only requirement is that the method specified in your *.routing.yml file + * return one of the following, depending on whether you specified _content or + * _controller in the routing file defaults section: + * - A render array (see the + * @link theme_render Theme and render topic @endlink for more information), + * if _content is used in the routing file. + * - A \Drupal\Core\Page\HtmlFragmentInterface object (fragment or page), if + * _content is used in the routing file. + * - A \Symfony\Component\HttpFoundation\Response object, if _controller is + * used in the routing file. + * As a note, if your module registers multiple simple routes, it is usual + * (and usually easiest) to put all of their methods on one controller class. + * + * Most controllers will need to display some information stored in the Drupal + * database, which will involve using one or more Drupal services (see the + * @link container Services and container topic @endlink). In order to properly + * inject services, a controller should implement + * \Drupal\Core\DependencyInjection\ContainerInjectionInterface; simple + * controllers can do this by extending the + * \Drupal\Core\Controller\ControllerBase class. See + * \Drupal\dblog\Controller\DbLogController for a straightforward example of + * a controller class. + * + * @section sec_links Defining menu links for the administrative menu + * Routes for administrative tasks can be added to the main Drupal + * administrative menu hierarchy. To do this, add lines like the following to a + * module_name.menu_links.yml file (in the top-level directory for your module): + * @code + * dblog.overview: + * title: 'Recent log messages' + * parent: system.admin_reports + * description: 'View events that have recently been logged.' + * route_name: dblog.overview + * weight: -1 + * @endcode + * Some notes: + * - The first line is the machine name for your menu link, which usually + * matches the machine name of the route (given in the 'route_name' line). + * - parent: The machine name of the menu link that is the parent in the + * administrative hierarchy. See system.menu_links.yml to find the main + * skeleton of the hierarchy. + * - weight: Lower (negative) numbers come before higher (positive) numbers, + * for menu items with the same parent. + * + * Menu items from other modules can be altered using + * hook_menu_link_defaults_alter(). + * + * @todo Derivatives will probably be defined for these; when they are, add + * documentation here. + * + * @section sec_tasks Defining groups of local tasks (tabs) + * Local tasks appear as tabs on a page when there are at least two defined for + * a route, including the base route as the main tab, and additional routes as + * other tabs. Static local tasks can be defined by adding lines like the + * following to a module_name.local_tasks.yml file (in the top-level directory + * for your module): + * @code + * book.admin: + * route_name: book.admin + * title: 'List' + * base_route: book.admin + * book.settings: + * route_name: book.settings + * title: 'Settings' + * base_route: book.admin + * weight: 100 + * @endcode + * Some notes: + * - The first line is the machine name for your local task, which usually + * matches the machine name of the route (given in the 'route_name' line). + * - base_route: The machine name of the main task (tab) for the set of local + * tasks. + * - weight: Lower (negative) numbers come before higher (positive) numbers, + * for tasks on the same base route. If there is a tab whose route + * matches the base route, that will be the default/first tab shown. + * + * Local tasks from other modules can be altered using + * hook_menu_local_tasks_alter(). + * + * @todo Derivatives are in flux for these; when they are more stable, add + * documentation here. + * + * @section sec_actions Defining local actions for routes + * Local actions can be defined for operations related to a given route. For + * instance, adding content is a common operation for the content management + * page, so it should be a local action. Static local actions can be + * defined by adding lines like the following to a + * module_name.local_actions.yml file (in the top-level directory for your + * module): + * @code + * node.add_page: + * route_name: node.add_page + * title: 'Add content' + * appears_on: + * - system.admin_content + * @endcode + * Some notes: + * - The first line is the machine name for your local action, which usually + * matches the machine name of the route (given in the 'route_name' line). + * - appears_on: Machine names of one or more routes that this local task + * should appear on. + * + * Local actions from other modules can be altered using + * hook_menu_local_actions_alter(). + * + * @todo Derivatives are in flux for these; when they are more stable, add + * documentation here. + * + * @section sec_contextual Defining contextual links + * Contextual links are displayed by the Contextual Links module for user + * interface elements whose render arrays have a '#contextual_links' element + * defined. For example, a block render array might look like this, in part: + * @code + * array( + * '#contextual_links' => array( + * 'block' => array( + * 'route_parameters' => array('block' => $entity->id()), + * ), + * ), + * @endcode + * In this array, the outer key 'block' defines a "group" for contextual + * links, and the inner array provides values for the route's placeholder + * parameters (see @ref sec_placeholders above). + * + * To declare that a defined route should be a contextual link for a + * contextual links group, put lines like the following in a + * module_name.contextual_links.yml file (in the top-level directory for your + * module): + * @code + * block_configure: + * title: 'Configure block' + * route_name: 'block.admin_edit' + * group: 'block' + * @endcode + * Some notes: + * - The first line is the machine name for your contextual link, which usually + * matches the machine name of the route (given in the 'route_name' line). + * - group: This needs to match the link group defined in the render array. + * + * Contextual links from other modules can be altered using + * hook_contextual_links_alter(). + * + * @todo Derivatives are in flux for these; when they are more stable, add + * documentation here. + */ + +/** * The maximum depth of a menu links tree - matches the number of p columns. * * @todo Move this constant to MenuLinkStorage along with all the tree @@ -132,6 +378,7 @@ function template_preprocess_menu_tree(&$variables) { * - tree: An HTML string containing the tree's items. * * @see template_preprocess_menu_tree() + * @ingroup themeable */ function theme_menu_tree($variables) { return '
'; @@ -144,6 +391,7 @@ function theme_menu_tree($variables) { * An associative array containing: * - element: Structured array data for a menu link. * + * @ingroup themeable */ function theme_menu_link(array $variables) { $element = $variables['element']; @@ -167,6 +415,7 @@ function theme_menu_link(array $variables) { * keys. * - #active: A boolean indicating whether the local task is active. * + * @ingroup themeable */ function theme_menu_local_task($variables) { $link = $variables['element']['#link']; @@ -209,6 +458,7 @@ function theme_menu_local_task($variables) { * - #link: A menu link array with 'title', 'href', and 'localized_options' * keys. * + * @ingroup themeable */ function theme_menu_local_action($variables) { $link = $variables['element']['#link']; @@ -461,6 +711,7 @@ function menu_local_tabs() { * - primary: (optional) An array of local tasks (tabs). * - secondary: (optional) An array of local tasks (tabs). * + * @ingroup themeable * @see menu_local_tasks() */ function theme_menu_local_tasks(&$variables) { @@ -832,4 +1083,8 @@ function _menu_set_expanded_menus() { } \Drupal::state()->set('menu_expanded', $names); -} \ No newline at end of file +} + +/** + * @} End of "defgroup menu". + */ diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 2eea30d..3a91c69 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -9,6 +9,11 @@ use Drupal\Core\Utility\UpdateException; /** + * @addtogroup hooks + * @{ + */ + +/** * Defines one or more hooks that are exposed by a module. * * Normally hooks do not need to be explicitly defined. However, by declaring a @@ -433,6 +438,7 @@ function hook_page_build(&$page) { * - options: (optional) An array of options to be passed to l() when * generating a link from this menu item. * + * @ingroup menu */ function hook_menu_link_defaults_alter(&$links) { // Change the weight and title of the user.logout link. @@ -508,6 +514,7 @@ function hook_menu_local_tasks(&$data, $route_name) { * * @see hook_menu_local_tasks() * + * @ingroup menu */ function hook_menu_local_tasks_alter(&$data, $route_name) { } @@ -521,6 +528,7 @@ function hook_menu_local_tasks_alter(&$data, $route_name) { * @see \Drupal\Core\Menu\LocalActionInterface * @see \Drupal\Core\Menu\LocalActionManager * + * @ingroup menu */ function hook_menu_local_actions_alter(&$local_actions) { } @@ -571,6 +579,7 @@ function hook_local_tasks_alter(&$local_tasks) { * * @see \Drupal\Core\Menu\ContextualLinkManager * + * @ingroup menu */ function hook_contextual_links_alter(array &$links, $group, array $route_parameters) { if ($group == 'menu') { @@ -966,6 +975,7 @@ function hook_system_info_alter(array &$info, \Drupal\Core\Extension\Extension $ * site. Use the 'description' key instead to provide any information that * is specific to the permission you are defining. * + * @ingroup user_api */ function hook_permission() { return array( @@ -1700,6 +1710,7 @@ function hook_requirements($phase) { * * @see hook_schema_alter() * + * @ingroup schemaapi */ function hook_schema() { $schema['node'] = array( @@ -1770,6 +1781,7 @@ function hook_schema() { * @param $schema * Nested array describing the schemas for all modules. * + * @ingroup schemaapi */ function hook_schema_alter(&$schema) { // Add field to existing schema. @@ -2616,6 +2628,7 @@ function hook_token_info_alter(&$data) { * @see batch_set() * @see batch_process() * + * @ingroup batch */ function hook_batch_alter(&$batch) { } @@ -2823,3 +2836,41 @@ function hook_config_import_steps_alter(&$sync_steps, \Drupal\Core\Config\Config $sync_steps[] = '_additional_configuration_step'; } } + +/** + * @} End of "addtogroup hooks". + */ + +/** + * @defgroup annotation Annotations + * @{ + * Annotations for class discovery and metadata description. + * + * The Drupal plugin system has a set of reusable components that developers + * can use, override, and extend in their modules. Most of the plugins use + * annotations, which let classes register themselves as plugins and describe + * their metadata. (Annotations can also be used for other purposes, though + * at the moment, Drupal only uses them for the plugin system.) + * + * To annotate a class as a plugin, add code similar to the following to the + * end of the documentation block immediately preceding the class declaration: + * @code + * * @ContentEntityType( + * * id = "comment", + * * label = @Translation("Comment"), + * * ... + * * base_table = "comment" + * * ) + * @endcode + * + * Note that you must use double quotes; single quotes will not work in + * annotations. + * + * The available annotation classes are listed in this topic, and can be + * identified when you are looking at the Drupal source code by having + * "@ Annotation" in their documentation blocks (without the space after @). To + * find examples of annotation for a particular annotation class, such as + * EntityType, look for class files that have an @ annotation section using the + * annotation class. + * @} + */ diff --git a/core/modules/update/update.manager.inc b/core/modules/update/update.manager.inc index 7a661b3..f52d679 100644 --- a/core/modules/update/update.manager.inc +++ b/core/modules/update/update.manager.inc @@ -277,6 +277,7 @@ function update_manager_update_form($form, $form_state = array(), $context) { * An associative array containing: * - form: A render element representing the form. * + * @ingroup themeable */ function theme_update_manager_update_form($variables) { $form = $variables['form'];