You are here

function cmis_browser_block in CMIS API 6.2

Implementation of hook_block() for CMIS content module.

File

cmis_browser/cmis_browser.module, line 224

Code

function cmis_browser_block($op = 'list', $delta = 0, $edit = array()) {
  module_load_include('content_block.inc', 'cmis_browser');
  switch ($op) {
    case 'list':

      // If $op is "list", we just need to return a list of block descriptions.
      // This is used to provide a list of possible blocks to the administrator,
      // end users will not see these descriptions.
      $blocks[0] = array(
        'info' => t('CMIS Repository Document View'),
      );
      return $blocks;
    case 'configure':

      // If $op is "configure", we need to provide the administrator with a
      // configuration form. The $delta parameter tells us which block is being
      // configured. In this example, we'll allow the administrator to customize
      // the text of the first block.
      $form = array(
        '#cache' => TRUE,
      );
      if ($delta == 0) {

        // All we need to provide is a text field, Drupal will take care of
        // the other block configuration options and the save button.
        $form['cmis_target_document_items'] = array(
          '#tree' => TRUE,
          '#prefix' => '<div class="clear-block" id="cmis-content-items-wrapper">',
          '#suffix' => '</div>',
        );
        $cmis_block_items = variable_get('cmis_target_document_items', array_fill(0, 2, '/'));

        // Making sure that there is at least one item
        $cmis_block_items += count($cmis_block_items) == 0 ? array(
          '/',
        ) : array();
        foreach ($cmis_block_items as $key => $item) {
          $form['cmis_target_document_items'][] = _cmis_browser_block_settings_path_form($key, $item);
        }
        $form['cmis_target_document_items_more'] = array(
          '#type' => 'submit',
          '#value' => t('Add more'),
          '#description' => t("If the amount of boxes above isn't enough, click here to add more."),
          '#weight' => 1,
          '#ahah' => array(
            'path' => 'cmis/block_settings_more_items_js',
            'wrapper' => 'cmis-content-items-wrapper',
            'method' => 'replace',
            'effect' => 'fade',
          ),
        );
      }
      return $form;
    case 'save':

      // If $op is "save", we need to save settings from the configuration form.
      // Since the first block is the only one that allows configuration, we
      // need to check $delta to make sure we only save it.
      if ($delta == 0) {
        $cmis_block_items = $edit['cmis_target_document_items'];

        // Removing empty items
        foreach ($cmis_block_items as $key => $cmis_block_item) {
          if (empty($cmis_block_item) || $cmis_block_item == '/') {
            unset($cmis_block_items[$key]);
          }
        }

        // Save configuration in `cmis_target_document_items` var
        variable_set('cmis_target_document_items', array_values($cmis_block_items));
      }
      return;
    case 'view':
    default:

      // If $op is "view", then we need to generate the block for display
      // purposes. The $delta parameter tells us which block is being requested.
      switch ($delta) {
        case 0:

          // The subject is displayed at the top of the block. Note that it
          // should be passed through t() for translation.
          $block['subject'] = t('Documents');

          // The content of the block is typically generated by calling a custom
          // function.
          $block['content'] = cmis_browser_block_content(0, variable_get('cmis_target_document_items', array()));
          break;
      }
      return $block;
  }
}