You are here

function page_manager_get_pages in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 page_manager/page_manager.admin.inc \page_manager_get_pages()

Sort tasks into buckets based upon whether or not they have subtasks.

2 calls to page_manager_get_pages()
page_manager_list_page in page_manager/page_manager.admin.inc
Output a list of pages that are managed.
page_manager_panels_dashboard_blocks in page_manager/page_manager.module
Implementation of hook_panels_dashboard_blocks().

File

page_manager/page_manager.admin.inc, line 130
Administrative functions for the page manager.

Code

function page_manager_get_pages($tasks, &$pages, $task_id = NULL) {
  foreach ($tasks as $id => $task) {
    if (empty($task_id) && !empty($task['page operations'])) {
      $pages['operations'] = array_merge($pages['operations'], $task['page operations']);
    }

    // If a type has subtasks, add its subtasks in its own table.
    if (!empty($task['subtasks'])) {
      page_manager_get_pages(page_manager_get_task_subtasks($task), $pages, $task['name']);
      continue;
    }
    if (isset($task_id)) {
      $task_name = page_manager_make_task_name($task_id, $task['name']);
    }
    else {
      $task_name = $task['name'];
    }
    $class = array(
      'page-task-' . $id,
    );
    if (isset($task['row class'])) {
      $class[] = $task['row class'];
    }
    if (!empty($task['disabled'])) {
      $class[] = 'page-manager-disabled';
    }
    $path = array();
    $visible_path = '';
    if (!empty($task['admin path'])) {
      foreach (explode('/', $task['admin path']) as $bit) {
        if (isset($bit[0]) && $bit[0] != '!') {
          $path[] = $bit;
        }
      }
      $path = implode('/', $path);
      if (empty($task['disabled']) && strpos($path, '%') === FALSE) {
        $visible_path = l('/' . $task['admin path'], $path);
      }
      else {
        $visible_path = '/' . $task['admin path'];
      }
    }
    $row = array(
      'data' => array(),
      'class' => $class,
      'title' => strip_tags($task['admin description']),
    );
    $type = isset($task['admin type']) ? $task['admin type'] : t('System');
    if (isset($task['module'])) {
      $module = $task['module'];
    }
    elseif (isset($task['subtask']->export_module)) {
      $module = $task['subtask']->export_module;
    }
    else {
      $module = '';
    }
    $pages['types'][$type] = $type;
    $row['data']['type'] = array(
      'data' => $type,
      'class' => array(
        'page-manager-page-type',
      ),
    );
    $row['data']['module'] = array(
      'data' => $module,
      'class' => array(
        'page-manager-page-module',
      ),
    );
    $row['data']['name'] = array(
      'data' => $task_name,
      'class' => array(
        'page-manager-page-name',
      ),
    );
    $row['data']['title'] = array(
      'data' => $task['admin title'],
      'class' => array(
        'page-manager-page-title',
      ),
    );
    $row['data']['path'] = array(
      'data' => $visible_path,
      'class' => array(
        'page-manager-page-path',
      ),
    );
    $storage = isset($task['storage']) ? $task['storage'] : t('In code');
    $pages['storages'][$storage] = $storage;
    $row['data']['storage'] = array(
      'data' => $storage,
      'class' => array(
        'page-manager-page-storage',
      ),
    );

    /*
        if (empty($task['disabled'])) {
          $item = menu_get_item($path);
          if (empty($item)) {
            dsm($path);
          }
          else {
            dsm($item);
          }
        }
    */
    $operations = array(
      array(
        'title' => t('Edit'),
        'href' => page_manager_edit_url($task_name),
      ),
    );
    if (!empty($task['enable callback'])) {
      if (!empty($task['disabled'])) {
        array_unshift($operations, array(
          'title' => t('Enable'),
          'href' => 'admin/structure/pages/nojs/enable/' . $task_name,
          'query' => array(
            'token' => drupal_get_token($task_name),
          ),
        ));
      }
      else {
        $operations[] = array(
          'title' => t('Disable'),
          'href' => 'admin/structure/pages/nojs/disable/' . $task_name,
          'query' => array(
            'token' => drupal_get_token($task_name),
          ),
        );
      }
    }
    $ops = theme('links__ctools_dropbutton', array(
      'links' => $operations,
      'attributes' => array(
        'class' => array(
          'links',
          'inline',
        ),
      ),
    ));
    $row['data']['operations'] = array(
      'data' => $ops,
      'class' => array(
        'page-manager-page-operations',
      ),
    );
    $pages['disabled'][$task_name] = !empty($task['disabled']);
    $pages['tasks'][] = $task_name;
    $pages['rows'][$task_name] = $row;
  }
}