You are here

function oa_buttons_add_space_content_render in Open Atrium Core 7.2

Renders the widget.

1 string reference to 'oa_buttons_add_space_content_render'
add_space_content.inc in modules/oa_buttons/plugins/content_types/add_space_content.inc

File

modules/oa_buttons/plugins/content_types/add_space_content.inc, line 18

Code

function oa_buttons_add_space_content_render($subtype, $conf, $args, $context) {
  global $user;
  $context = og_context();
  $section = oa_core_get_section_context();
  $content = '';
  if (isset($context['gid'])) {
    $node = node_load($context['gid']);
  }
  else {
    return;
  }
  $cache_key = 'oa_section_buttons:' . $context['gid'] . ':' . $section . ':' . $user->uid;

  // Lets cache this, since it can be expensive.
  if ($cache = cache_get($cache_key, 'cache_oa_section_buttons')) {
    $content = $cache->data;
  }
  else {
    $caption = isset($conf['caption']) ? $conf['caption'] : t('Create Content');
    $btn_title = isset($conf['btn_title']) ? $conf['btn_title'] : t('Create Content');
    $buttons = oa_buttons_get_command_buttons($node);
    if (count($buttons)) {
      drupal_alter('oa_space_buttons', $buttons);
      $command_buttons = array();
      $node_types = array_flip(node_type_get_names());

      // Iterate over each of the buttons.
      foreach ($buttons as $button) {
        $entity_type = $button['value'];
        $command_buttons[$entity_type] = $entity_type;
      }
      $entities = command_buttons_machine_name_load(array_keys($command_buttons));
      $btn_class = !empty($conf['btn_class']) ? check_plain($conf['btn_class']) : 'btn btn-inverse';
      $classes = array(
        'use_dropdowns' => TRUE,
        'dropdown_label' => $caption,
        'btn_title' => !empty($btn_title) ? $btn_title : $caption,
        'direction' => !empty($conf['direction']) ? check_plain($conf['direction']) : '',
        'icon_class' => !empty($conf['icon']) ? check_plain($conf['icon']) : '',
        'show_caret' => isset($conf['caret']) ? $conf['caret'] : TRUE,
        'item_class' => array(
          'oa-button',
        ),
        'wrapper_class' => array(
          'oa-buttons',
          $btn_class,
        ),
      );
      if (!empty($entities) && !empty($buttons)) {
        $content = command_buttons_render_buttons($entities, $classes, $buttons);
      }

      // Cache for 1 hour.
      cache_set($cache_key, $content, 'cache_oa_section_buttons', time() + 6000);
    }
  }
  if (empty($content)) {
    return;
  }
  $block = new stdClass();
  $block->content = $content;
  return $block;
}