function state_flow_admin_nodes in State Machine 7.3
Same name and namespace in other branches
- 7.2 modules/state_flow/state_flow.admin.inc \state_flow_admin_nodes()
Form builder: Builds the node administration overview.
1 call to state_flow_admin_nodes()
- state_flow_content_page in modules/
state_flow/ state_flow.admin.inc - Menu callback: content administration.
File
- modules/
state_flow/ state_flow.admin.inc, line 107 - Revision Content administration.
Code
function state_flow_admin_nodes() {
$admin_access = user_access('administer nodes');
// Build the 'Update options' form.
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Update options'),
'#attributes' => array(
'class' => array(
'container-inline',
),
),
'#access' => $admin_access,
);
$options = array();
$operations = module_invoke_all('node_revision_operations');
drupal_alter('state_flow_node_revision_operations', $operations);
foreach ($operations as $operation => $array) {
$options[$operation] = $array['label'];
}
$form['options']['operation'] = array(
'#type' => 'select',
'#title' => t('Operation'),
'#title_display' => 'invisible',
'#options' => $options,
'#default_value' => 'approve',
);
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#validate' => array(
'state_flow_admin_nodes_validate',
),
'#submit' => array(
'state_flow_admin_nodes_submit',
),
);
// Build the sortable table header.
$header = array(
'title' => array(
'data' => t('Title'),
'field' => 'nr.title',
),
'type' => array(
'data' => t('Type'),
'field' => 'n.type',
),
'author' => t('Author'),
'status' => t('Status'),
);
$header['operations'] = array(
'data' => t('Operations'),
);
$query = db_select('node', 'n')
->extend('PagerDefault')
->extend('TableSort');
$query
->join('node_revision', 'nr', 'n.nid = nr.nid');
$filters = isset($_SESSION['node_revision_filter']) ? $_SESSION['node_revision_filter'] : array();
$rows = $query
->fields('nr', array(
'nid',
'vid',
))
->limit(50)
->orderByHeader($header)
->addTag('node_revision')
->addMetaData('filters', $filters)
->execute();
$options = array();
if ($rows) {
// Prepare the list of nodes.
$destination = drupal_get_destination();
foreach ($rows as $row) {
$node = node_load($row->nid, $row->vid);
$key = "{$node->nid}:::{$node->vid}";
$machine = state_flow_entity_load_state_machine($node, 'node')
->get_label_for_current_state();
$options[$key] = array(
'title' => array(
'data' => array(
'#type' => 'link',
'#title' => $node->title,
'#href' => 'node/' . $node->nid,
),
),
'type' => check_plain(node_type_get_name($node)),
'author' => theme('username', array(
'account' => $node,
)),
'status' => $machine,
);
// Build a list of all the accessible operations for the current node.
$operations = array();
if (node_access('update', $node)) {
$operations['edit'] = array(
'title' => t('edit'),
'href' => 'node/' . $node->nid . '/edit',
'query' => $destination,
);
}
if (node_access('delete', $node)) {
$operations['delete'] = array(
'title' => t('delete'),
'href' => 'node/' . $node->nid . '/delete',
'query' => $destination,
);
}
$options[$key]['operations'] = array();
if (count($operations) > 1) {
// Render an unordered list of operations links.
$options[$key]['operations'] = array(
'data' => array(
'#theme' => 'links__node_operations',
'#links' => $operations,
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
),
);
}
elseif (!empty($operations)) {
// Render the first and only operation as a link.
$link = reset($operations);
$options[$key]['operations'] = array(
'data' => array(
'#type' => 'link',
'#title' => $link['title'],
'#href' => $link['href'],
'#options' => array(
'query' => $link['query'],
),
),
);
}
}
}
// Only use a tableselect when the current user is able to perform any
// operations.
if ($admin_access) {
$form['nodes'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No content available.'),
);
}
else {
$form['nodes'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $options,
'#empty' => t('No content available.'),
);
}
$form['pager'] = array(
'#markup' => theme('pager'),
);
return $form;
}