You are here

function pm_dashboard_get_links in Drupal PM (Project Management) 8

Same name and namespace in other branches
  1. 7.3 pm.module \pm_dashboard_get_links()
  2. 7 pm.module \pm_dashboard_get_links()
  3. 7.2 pm.module \pm_dashboard_get_links()

Return links array for the pm dashboard.

Parameters

bool $check_active: When FALSE, returns all links whether active or not (for admin settings).

string $type: Dashboard type.

Return value

array Dashboard links.

2 calls to pm_dashboard_get_links()
pm_block_view in ./pm.module
Implements hook_block_view().
pm_page_front in includes/pm.pages.inc
Page callback for 'pm' path.

File

./pm.module, line 214
Main module file for the Project Management module.

Code

function pm_dashboard_get_links($check_active = TRUE, $type = 'page') {
  $links = module_invoke_all('pm_dashboard_links', $type);
  if (!empty($links)) {
    $default_dashboard_settings = variable_get('pm_' . $type . 'dashboard_settings', array());
    $weight = 0;
    foreach ($links as $key => &$link_array) {

      // Active check.
      if ($check_active && isset($default_dashboard_settings[$link_array['path']]['active']) && $default_dashboard_settings[$link_array['path']]['active'] == FALSE) {
        unset($links[$key]);
        continue;
      }

      // Module exist check.
      if (isset($link_array['destination_module']) && !module_exists($link_array['destination_module'])) {
        unset($links[$key]);
        continue;
      }

      // Access check.
      if (!drupal_valid_path($link_array['path'])) {
        unset($links[$key]);
      }
      if (isset($default_dashboard_settings[$link_array['path']]['weight'])) {
        $link_array['weight'] = $default_dashboard_settings[$link_array['path']]['weight'];
      }
      elseif (!isset($link_array['weight'])) {
        $link_array['weight'] = $weight;
        $weight++;
      }
    }

    // Hook for altering links.
    drupal_alter('pm_dashboard_links', $links, $type);

    // Sort links by weight.
    uasort($links, '_pm_dashboard_sort_links');
  }
  return $links;
}