You are here

function opigno_block_view in Opigno 7

Same name and namespace in other branches
  1. 7.0 opigno.module \opigno_block_view()

Implements hook_block_view().

File

./opigno.module, line 157
Contains all hook_implementations and module specific API.

Code

function opigno_block_view($delta) {
  global $user;
  $node = menu_get_object();
  switch ($delta) {
    case 'opigno_tool_actions_block':
      if (!empty($node) && opigno_access_tools($node)) {
        $links = array();
        foreach (opigno_get_node_tools($node, $user) as $tool) {
          if (!empty($tool['actions'])) {
            foreach ($tool['actions'] as $action_id => $action) {
              $defaults = array(
                'access_arguments' => array(
                  'access content',
                ),
                'access_callback' => 'user_access',
              );
              $action += $defaults;
              if (opigno_tool_action_access($action, $user)) {
                $links[$action_id] = $action;
              }
            }
          }
        }
      }
      return array(
        'subject' => t("Tool actions"),
        'content' => empty($links) ? '' : theme('links', array(
          'links' => $links,
        )),
      );
    case 'opigno_tools_block':
      if (!empty($node) && opigno_access_tools($node)) {
        $elements = array();
        foreach (opigno_get_node_tools($node, $user) as $tool) {
          $elements[$delta] = array(
            '#type' => 'html_tag',
            '#tag' => 'p',
            '#value' => check_plain($tool['name']),
          );
        }
      }
      return array(
        'subject' => t("Tool actions"),
        'content' => empty($elements) ? '' : $elements,
      );
  }
}