function workflow_menu_alter in Workflow 7.2
Implements hook_menu_alter().
hook_menu() in workflownode sets a '/workflow' menu item for entity type 'node'. hook_menu_alter() in workflowfield sets a '/workflow' menu item for each relevant entity type.
File
- ./
workflow.module, line 80 - Support workflows made up of arbitrary states.
Code
function workflow_menu_alter(&$items) {
// @todo: Move menu-items to a UI Controller class via workflow.entity.inc:
$items['workflow_transition/%workflow_transition/edit'] = array(
// %workflow_transition maps to function workflow_transition_load()
'title' => 'Edit workflow log comment',
'description' => 'Edit workflow transition comment.',
// 'page callback' => 'drupal_get_form',
// 'page arguments' => array('workflow_transition_form_wrapper', 1),
'page callback' => 'entity_ui_get_form',
// @todo: below parameter should be the machine_name of the entity type.
'page arguments' => array(
'WorkflowTransition',
1,
),
'access arguments' => array(
'edit workflow comment',
),
// 'file' => 'workflow.transition.page.inc',
'menu wildcard' => '%workflow_transition',
);
if (module_exists('workflownode')) {
$type = 'node';
$items['node/%node/workflow'] = array(
'title' => 'Workflow',
'page callback' => 'workflow_tab_page',
'page arguments' => array(
$type,
1,
),
'access callback' => 'workflow_tab_access',
'access arguments' => array(
$type,
1,
),
'file' => 'workflow.pages.inc',
'file path' => drupal_get_path('module', 'workflow'),
'weight' => 2,
'type' => MENU_LOCAL_TASK,
'module' => 'workflow',
);
}
if (!module_exists('workflowfield')) {
return;
}
$menu_item = array(
'title' => 'Workflow',
'page callback' => 'workflow_tab_page',
'access callback' => 'workflow_tab_access',
'file' => 'workflow.pages.inc',
'file path' => drupal_get_path('module', 'workflow'),
'weight' => 2,
'type' => MENU_LOCAL_TASK,
'module' => 'workflow',
);
// Get a cross-bundle map of all workflow fields so we can add the workflow
// tab to all entities with a workflow field.
foreach (_workflow_info_fields() as $field_info) {
if (TRUE) {
// Loop over the entity types that have this field.
foreach ($field_info['bundles'] as $type => $bundles) {
$entity_info = entity_get_info($type);
// Add the workflow tab in the Entity Admin UI.
if (!empty($entity_info['admin ui']['path'])) {
$admin_path = $entity_info['admin ui']['path'];
$entity_position = substr_count($admin_path, '/') + 2;
$wildcard = isset($entity_info['admin ui']['menu wildcard']) ? $entity_info['admin ui']['menu wildcard'] : '%entity_object';
$items["{$admin_path}/manage/{$wildcard}/workflow"] = $menu_item + array(
'page arguments' => array(
$type,
$entity_position,
),
'access arguments' => array(
$type,
$entity_position,
),
'load arguments' => array(
$type,
),
);
}
// We can only continue if the entity relies on a ENTITY_TYPE_load() load hook.
if ($entity_info['load hook'] == $type . '_load') {
try {
foreach ($bundles as $bundle) {
// Get the default entity values.
$values = array(
$entity_info['entity keys']['id'] => '%' . $type,
);
if ($entity_info['entity keys']['bundle']) {
$values[$entity_info['entity keys']['bundle']] = $bundle;
}
// Create a dummy entity and get the URI.
$entity = @entity_create($type, $values);
if (!$entity) {
// Some entities (entity_example.module, ECK) are not complete.
$entity = new stdClass($values);
foreach ($values as $key => $value) {
$entity->{$key} = $value;
}
}
$uri = entity_uri($type, $entity);
if (isset($uri['path'])) {
$uri = $uri['path'];
// Add the workflow tab if possible.
if (isset($items[$uri]) && !isset($items[$uri . '/workflow'])) {
$entity_position = array_search('%' . $type, explode('/', $uri));
if ($entity_position) {
$items[$uri . '/workflow'] = $menu_item + array(
'page arguments' => array(
$type,
$entity_position,
),
'access arguments' => array(
$type,
$entity_position,
),
);
}
}
}
}
} catch (Exception $ex) {
// The $type entity could not be created or the URI building failed.
// workflow_debug( __FILE__, __FUNCTION__, __LINE__, $ex->getMessage(), '');
}
}
}
}
}
}