You are here

pmticket.module in Drupal PM (Project Management) 7.3

Main module file for the PM Ticket module.

File

pmticket/pmticket.module
View source
<?php

/**
 * @file
 * Main module file for the PM Ticket module.
 */

/**
 * Implements hook_help().
 */
function pmticket_help($path, $arg) {
  $o = '';
  switch ($path) {
    case "admin/help#pmticket":
      $o = '<p>' . t("Provides ticket support for Project Management") . '</p>';
      break;
  }
  return $o;
}

/**
 * Implements hook_permission().
 */
function pmticket_permission() {
  $name = 'Project Management Ticket';
  return array(
    "Project Management Ticket: access" => array(
      'title' => t('Access %type_name.', array(
        '%type_name' => $name,
      )),
      'description' => t('Allows the user to see pages and blocks associated with the %type_name, but does not control specific item that is shown within them.', array(
        '%type_name' => $name,
      )),
    ),
  );
}

/**
 * Implements hook_node_info().
 */
function pmticket_node_info() {
  return array(
    'pmticket' => array(
      'name' => t('Ticket'),
      'base' => 'pmticket',
      'description' => t('Use <em>tickets</em> for recording and tracking items that need resolution within <em>Project Management</em>.'),
      'title_label' => t('Title'),
    ),
  );
}

/**
 * Implements hook_form().
 */
function pmticket_form(&$node, $form_state) {
  $breadcrumb = array(
    array(
      'text' => t('Tickets'),
      'path' => 'pm/tickets',
    ),
  );
  pm_set_breadcrumb($breadcrumb);
  return node_content_form($node, $form_state);
}

/**
 * Implements hook_view().
 */
function pmticket_view($node, $view_mode) {
  if ($view_mode == 'full' && node_is_page($node)) {
    $breadcrumb = array(
      array(
        'text' => t('Tickets'),
        'path' => 'pm/tickets',
      ),
    );
    pm_set_breadcrumb($breadcrumb);
  }
  return $node;
}

/**
 * Implements hook_pm_contextual_links().
 */
function pmticket_pm_contextual_links($entity, $type, $view_mode, $langcode) {
  $links = array();
  list($id, $vid, $bundle) = entity_extract_ids($type, $entity);
  if ($type == 'node') {
    $field_info = field_info_field('pmticket_parent');
    if (isset($field_info['settings']['handler_settings']['target_bundles'])) {
      $target_bundles = $field_info['settings']['handler_settings']['target_bundles'];
    }
    else {
      $target_bundles = array(
        'pmproject',
      );
    }
    if (in_array($bundle, $target_bundles)) {
      $links[t('Add Ticket')] = array(
        'title' => t('Add Ticket'),
        'href' => 'node/add/pmticket',
        'query' => array(
          'pmticket_parent' => $id,
        ),
      );
    }
  }
  return $links;
}

/**
 * Implements hook_views_api().
 */
function pmticket_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'pmticket'),
  );
}

/**
 * Implements hook_token_list().
 */
function pmticket_token_list($type = 'all') {
  $tokens = array();
  if ($type == 'node' || $type == 'all') {
    $tokens['node']['pmticket-organization-nid'] = t('Project Management Ticket: Organization Node ID.');
    $tokens['node']['pmticket-organization-title'] = t('Project Management Ticket: Organization Title.');
    $tokens['node']['pmticket-project-nid'] = t('Project Management Ticket: Project Node ID.');
    $tokens['node']['pmticket-project-title'] = t('Project Management Ticket: Project Title.');
  }
  return $tokens;
}

/**
 * Implements hook_token_values().
 */
function pmticket_token_values($type, $object = NULL) {
  $values = array();
  $node = $object;
  if (($type == 'node' || $type == 'all') && $node->type === 'pmticket') {
    $values['pmticket-organization-nid'] = $node->organization_nid;
    $values['pmticket-organization-title'] = $node->organization_title;
    $values['pmticket-project-nid'] = $node->project_nid;
    $values['pmticket-project-title'] = $node->project_title;
  }
  return $values;
}

/**
 * Implements hook_pm_dashboard_links().
 */
function pmticket_pm_dashboard_links($type) {
  $links = array();
  if ($type == 'page' || $type == 'block') {
    $links[] = array(
      'theme' => 'pm_dashboard_link',
      'title' => t('Tickets'),
      'icon' => 'pmtickets',
      'path' => 'pm/tickets',
      'params' => array(),
      'node_type' => 'pmticket',
      'add_type' => 'pmticket',
      'map' => array(),
      'weight' => 6,
    );
  }
  return $links;
}

Functions

Namesort descending Description
pmticket_form Implements hook_form().
pmticket_help Implements hook_help().
pmticket_node_info Implements hook_node_info().
pmticket_permission Implements hook_permission().
pmticket_pm_contextual_links Implements hook_pm_contextual_links().
pmticket_pm_dashboard_links Implements hook_pm_dashboard_links().
pmticket_token_list Implements hook_token_list().
pmticket_token_values Implements hook_token_values().
pmticket_view Implements hook_view().
pmticket_views_api Implements hook_views_api().