pmorganization.module in Drupal PM (Project Management) 8
Same filename and directory in other branches
Main module file for PM Organization.
File
pmorganization/pmorganization.moduleView source
<?php
/**
* @file
* Main module file for PM Organization.
*/
/**
* Implements hook_help().
*/
function pmorganization_help($path, $arg) {
$output = '';
switch ($path) {
case "admin/help#pmorganization":
$output = '<p>' . t("Provides organization support for Project Management") . '</p>';
break;
}
return $output;
}
/**
* Implements hook_permission().
*/
function pmorganization_permission() {
$name = 'Project Management Organization';
return array(
"Project Management Organization: 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 pmorganization_node_info() {
return array(
'pmorganization' => array(
'name' => t('Organization'),
'base' => 'pmorganization',
'description' => t('Use <em>organizations</em> for formal groups of people, such as clients/customers/service providers within <em>Project Management</em>.'),
'title_label' => t('Name'),
'body_label' => t('Description'),
),
);
}
/**
* Implements hook_form().
*/
function pmorganization_form($node, &$form_state) {
$breadcrumb = array(
l(t('Project Management'), 'pm'),
l(t('Organizations'), 'pm/organizations'),
);
drupal_set_breadcrumb($breadcrumb);
return node_content_form($node, $form_state);
}
/**
* Implements hook_view().
*/
function pmorganization_view($node, $view_mode) {
if ($view_mode == 'full' && node_is_page($node)) {
$breadcrumb = array(
l(t('Project Management'), 'pm'),
l(t('Organizations'), 'pm/organizations'),
);
drupal_set_breadcrumb($breadcrumb);
}
return $node;
}
/**
* Implements hook_views_api().
*/
function pmorganization_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'pmorganization'),
);
}
/**
* Implements hook_pm_dashboard_links().
*/
function pmorganization_pm_dashboard_links($type) {
$links = array();
if ($type == 'page' || $type == 'block') {
$links[] = array(
'theme' => 'pm_dashboard_link',
'title' => t('Organizations'),
'icon' => 'pmorganizations',
'path' => 'pm/organizations',
'params' => array(),
'node_type' => 'pmorganization',
'add_type' => 'pmorganization',
'map' => array(),
'weight' => 1,
);
}
return $links;
}
/**
* Implements hook_ctools_plugin_api().
*/
function pmorganization_ctools_plugin_api($module = NULL, $api = NULL) {
if ($module == "field_group" && $api == "field_group") {
return array(
"version" => "1",
);
}
}
/**
* @defgroup pmorganization_index pmorganization indexing
* @{
* Functions to maintain pmorganization indexing.
*/
/**
* Implements hook_node_insert().
*/
function pmorganization_node_insert($node) {
// Add pmorganization index entries for the node.
pmorganization_build_node_index($node);
}
/**
* Builds and inserts pmorganization index entries for a given node.
*
* The index lists all terms that are related to a given node entity, and is
* therefore maintained at the entity level.
*
* @param object $node
* The node object.
*/
function pmorganization_build_node_index($node) {
// We maintain a denormalized table of term/node relationships, containing
// only data for current, published nodes.
$status = NULL;
if (variable_get('pmorganization_maintain_index_table', TRUE)) {
// If a node property is not set in the node object when node_save() is
// called, the old value from $node->original is used.
if (!empty($node->original)) {
$status = (int) (!empty($node->status) || !isset($node->status) && !empty($node->original->status));
}
else {
$status = (int) (!empty($node->status));
}
}
// We only maintain the pmorganization index for published nodes.
if ($status) {
// Hunt for PM Organization.
$pmorganization_nid = pm_permission_get_parent_nid_of_node($node, 'pmorganization');
// Insert index entries for all the node's terms.
if (!empty($pmorganization_nid)) {
$query = db_insert('pmorganization_index')
->fields(array(
'nid',
'pmorganization_nid',
'created',
));
$query
->values(array(
'nid' => $node->nid,
'pmorganization_nid' => $pmorganization_nid,
'created' => $node->created,
));
$query
->execute();
}
}
}
/**
* Implements hook_node_update().
*/
function pmorganization_node_update($node) {
// Always rebuild the node's pmorganization index entries on node save.
pmorganization_delete_node_index($node);
pmorganization_build_node_index($node);
}
/**
* Implements hook_node_delete().
*/
function pmorganization_node_delete($node) {
// Clean up the {pmorganization_index} table when nodes are deleted.
pmorganization_delete_node_index($node);
if (variable_get('pmorganization_maintain_index_table', TRUE) and $node->type = 'pmorganization') {
// Clean up the {pmorganization_index} table when pmorganization is deleted.
db_delete('pmorganization_index')
->condition('pmorganization_nid', $node->nid)
->execute();
}
}
/**
* Deletes pmorganization index entries for a given node.
*
* @param object $node
* The node object.
*/
function pmorganization_delete_node_index($node) {
if (variable_get('pmorganization_maintain_index_table', TRUE)) {
db_delete('pmorganization_index')
->condition('nid', $node->nid)
->execute();
}
}
/**
* @} End of "defgroup pmorganization_index".
*/
Functions
Name | Description |
---|---|
pmorganization_build_node_index | Builds and inserts pmorganization index entries for a given node. |
pmorganization_ctools_plugin_api | Implements hook_ctools_plugin_api(). |
pmorganization_delete_node_index | Deletes pmorganization index entries for a given node. |
pmorganization_form | Implements hook_form(). |
pmorganization_help | Implements hook_help(). |
pmorganization_node_delete | Implements hook_node_delete(). |
pmorganization_node_info | Implements hook_node_info(). |
pmorganization_node_insert | Implements hook_node_insert(). |
pmorganization_node_update | Implements hook_node_update(). |
pmorganization_permission | Implements hook_permission(). |
pmorganization_pm_dashboard_links | Implements hook_pm_dashboard_links(). |
pmorganization_view | Implements hook_view(). |
pmorganization_views_api | Implements hook_views_api(). |