Dru Documentation

Go to front page

developer/hooks/core.php, string 169 Versions 5 - 6 hook_block ($op = ' list ', $delta = 0, $edit = array ()) "Translation" the Pre-image Defines the block or a gang of blocks. Any unit can add the blocks, having defined them in hook_block. This хук is called in theme.inc at mapping of blocks, and also in block.module for show of the list of accessible blocks. After end of a spelling of your blocks, do not forget to include them in section of administration of blocks on a site. The detailed example of usage can be looked in block_example.module. Parametres $op What sort it is required to return the information on blocks. Possible values: * ' list ': the List of all blocks of the given unit. * ' configure ': Forms of customisations for the block. * ' save ': to Save block customisations. * ' view ': It is required to return contents of the block for mapping in the necessary section of page. $delta it is necessary to return the Information on what block (for all operations $op except ' list '). Though more often blocks are numbered by integers since zero, but it is not mandatory. For example, aggregator.module unit uses strings as values $delta. $edit If $op it is equal ' save ', the data is stored in this parametre from the customisation form. In remaining cases the array is empty. Returned value * $op = ' list ': the Array with expositions of all blocks of the unit. Each of expositions is the associative array with such keys: o ' info ': the Name of the block for mapping in the management interface is mandatory). o ' cache ': Flags, описывающае behaviour of the block from the point of view of system кеширования. Block.module unit defines таки flags: + BLOCK_CACHE_PER_ROLE (default value): block Contents vary depending on a role of the user viewing it. + BLOCK_CACHE_PER_USER: block Contents vary depending on the user viewing the block. The block with this flag can demand many resources for mapping, especially for large a site, therefore this flag should be used only in case it is impossible to use flag BLOCK_CACHE_PER_ROLE. + BLOCK_CACHE_PER_PAGE: block Contents vary depending on page on which it is mapped. + BLOCK_CACHE_GLOBAL: block Contents do not depend on the user viewing the block, from page on which the block is mapped. + BLOCK_NO_CACHE: the Block it is not necessary кешировать. Let's notice that for the user #1 blocks never кешируются. o ' weight ', ' status', ' region ', ' visibility ', ' pages': the block (set in the parametre $delta) can specify explicitly weight to include/switch off it to limit mapping only on the set pages, etc. These installations will take effect at the first mapping of the block in the administration interface then the manager can change them. Let's notice that if for the block mapping in the area which are absent in the given subject is set, the block will be located in area by default (the first array cell _regions in subject exposition). * $op = ' configure ': the Optional form of customisation for the block. * $op = ' save ': Anything. * $op = ' view ': the Associative array describing the block (set in the parametre $delta). The key ' subject ' this array should set the block header, and ' content ' - its contents. If value ' content ' is empty, the block will not be output, even if ' subject ' will be filled. Declare a block or set of blocks. Any module can export a block (or blocks) to be displayed by defining the _block hook. This hook is called by theme.inc to display a block, and also by block.module to procure the list of available blocks. The functions mymodule_display_block_1 and 2, as used in the example, should of course be defined somewhere in your module and return the content you want to display to your users. If the "content" element is empty, no block will be displayed even if "subject" is present. After completing your blocks, do not forget to enable them in the block admin menu. For a detailed usage example, see block_example.module. Parameters $op What kind of information to retrieve about the block or blocks. Possible values: * ' list ': A list of all blocks defined by the module. * ' configure ': Configuration form for the block. * ' save ': Save the configuration options. * ' view ': Process the block when enabled in a region in order to view its contents. $delta Which block to return (not applicable if $op is ' list '). Although it is most commonly an integer starting at 0, this is not mandatory. For instance, aggregator.module uses string values for $delta $edit If $op is ' save ', the submitted form data from the configuration form. Return value * If $op is ' list ': An array of block descriptions. Each block description is an associative array, with the following key-value pairs: o ' info ': (required) The human-readable name of the block. o ' cache ': A bitmask of flags describing how the block should behave with respect to block caching. The following shortcut bitmasks are provided as constants in block.module: + BLOCK_CACHE_PER_ROLE (default): The block can change depending on the roles the user viewing the page belongs to. + BLOCK_CACHE_PER_USER: The block can change depending on the user viewing the page. This setting can be resource-consuming for sites with large number of users, and should only be used when BLOCK_CACHE_PER_ROLE is not sufficient. + BLOCK_CACHE_PER_PAGE: The block can change depending on the page being viewed. + BLOCK_CACHE_GLOBAL: The block is the same for every user on every page where it is visible. + BLOCK_NO_CACHE: The block should not get cached. o ' weight ', ' status', ' region ', ' visibility ', ' pages': You can give your blocks an explicit weight, enable them, limit them to given pages, etc. These settings will be registered when the block is first loaded at admin/block, and from there can be changed manually via block administration. Note that if you set a region that isn't available in a given theme, the block will be registered instead to that theme's default region (the first item in the _regions array). o If $op is ' configure ': optionally return the configuration form. o If $op is ' save ': return nothing. o If $op is ' view ': return an array which must define a ' subject ' element and a ' content ' element defining the block indexed by $delta. The linked subjects Хуки Allows units to co-operate with kernel Drupal. Источник основного материала