Ejemplo n.º 1
0
/**
 * Return a rendered or renderable view of a block.
 *
 * @param string $delta
 *   Which block to render. This is a unique identifier for the block
 *   within the module, defined in hook_block_info().
 * @param array $settings
 *   An array of settings for this block. Defaults may not be populated, so it's
 *   best practice to merge in defaults within hook_block_view().
 * @param array $contexts
 *   An array of contexts required by this block. Each context will be keyed
 *   by the string specified in this module's hook_block_info().
 *
 * @return
 *   Either an empty array so the block will not be shown or an array containing
 *   the following elements:
 *   - subject: The default localized title of the block. If the block does not
 *     have a default title, this should be set to NULL.
 *   - content: The content of the block's body. This may be a renderable array
 *     (preferable) or a string containing rendered HTML content. If the content
 *     is empty the block will not be shown.
 *
 * For a detailed usage example, see block_example.module.
 *
 * @see hook_block_info()
 * @see hook_block_view_alter()
 * @see hook_block_view_MODULE_DELTA_alter()
 */
function hook_block_view($delta = '', $settings = array(), $contexts = array())
{
    // This example is adapted from node.module.
    $block = array();
    switch ($delta) {
        case 'syndicate':
            $block['subject'] = t('Syndicate');
            $block['content'] = array('#theme' => 'feed_icon', '#url' => 'rss.xml', '#title' => t('Syndicate'));
            break;
        case 'recent':
            if (user_access('access content')) {
                $settings += array('node_count' => 10);
                $block['subject'] = t('Recent content');
                if ($nodes = node_get_recent($settings['node_count'])) {
                    $block['content'] = array('#theme' => 'node_recent_block', '#nodes' => $nodes);
                } else {
                    $block['content'] = t('No content available.');
                }
            }
            break;
        case 'author_picture':
            $author_account = user_load($contexts['node']->uid);
            $block['subject'] = '';
            $block['content'] = theme('user_picture', array('account' => $author_account));
            return $block;
    }
    return $block;
}
Ejemplo n.º 2
0
/**
 * Return a rendered or renderable view of a block.
 *
 * @param $delta
 *   Which block to render. This is a unique identifier for the block
 *   within the module, defined in hook_block_info().
 *
 * @return
 *   Either an empty array so the block will not be shown or an array containing
 *   the following elements:
 *   - subject: The default localized title of the block. If the block does not
 *     have a default title, this should be set to NULL.
 *   - content: The content of the block's body. This may be a renderable array
 *     (preferable) or a string containing rendered HTML content. If the content
 *     is empty the block will not be shown.
 *
 * For a detailed usage example, see block_example.module.
 *
 * @see hook_block_info()
 * @see hook_block_view_alter()
 * @see hook_block_view_MODULE_DELTA_alter()
 */
function hook_block_view($delta = '')
{
    // This example is adapted from node.module.
    $block = array();
    switch ($delta) {
        case 'syndicate':
            $block['subject'] = t('Syndicate');
            $block['content'] = array('#theme' => 'feed_icon', '#url' => 'rss.xml', '#title' => t('Syndicate'));
            break;
        case 'recent':
            if (user_access('access content')) {
                $block['subject'] = t('Recent content');
                if ($nodes = node_get_recent(variable_get('node_recent_block_count', 10))) {
                    $block['content'] = array('#theme' => 'node_recent_block', '#nodes' => $nodes);
                } else {
                    $block['content'] = t('No content available.');
                }
            }
            break;
    }
    return $block;
}
Ejemplo n.º 3
0
/**
 * Return a rendered or renderable view of a block.
 *
 * @param $delta
 *   Which block to render. This is a unique identifier for the block
 *   within the module, defined in hook_block_info().
 *
 * @return
 *   An array containing the following elements:
 *   - subject: The default localized title of the block. If the block does not
 *     have a default title, this should be set to NULL.
 *   - content: The content of the block's body. This may be a renderable array
 *     (preferable) or a string containing rendered HTML content.
 *
 * For a detailed usage example, see block_example.module.
 *
 * @see hook_block_info()
 * @see hook_block_view_alter()
 * @see hook_block_view_MODULE_DELTA_alter()
 */
function hook_block_view($delta = '')
{
    // This example comes from node.module. Note that you can also return a
    // renderable array rather than rendered HTML for 'content'.
    $block = array();
    switch ($delta) {
        case 'syndicate':
            $block['subject'] = t('Syndicate');
            $block['content'] = theme('feed_icon', array('url' => url('rss.xml'), 'title' => t('Syndicate')));
            break;
        case 'recent':
            if (user_access('access content')) {
                $block['subject'] = t('Recent content');
                if ($nodes = node_get_recent(variable_get('node_recent_block_count', 10))) {
                    $block['content'] = theme('node_recent_block', array('nodes' => $nodes));
                } else {
                    $block['content'] = t('No content available.');
                }
            }
            break;
    }
    return $block;
}