function domain_content_form in Domain Access 7.3
Same name and namespace in other branches
- 5 domain_content/domain_content.module \domain_content_form()
- 6.2 domain_content/domain_content.admin.inc \domain_content_form()
- 7.2 domain_content/domain_content.admin.inc \domain_content_form()
Rewrites node_admin_nodes() to use db_rewrite_sql().
Return value
A form array according to the FormsAPI.
1 call to domain_content_form()
- domain_content_admin in domain_content/
domain_content.admin.inc - Content admin page callback.
File
- domain_content/
domain_content.admin.inc, line 217 - Administration pages for Domain Content.
Code
function domain_content_form() {
$_domain = domain_get_domain();
$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',
),
),
);
$options = array();
// Get the actions the user may perform.
if ($admin_access) {
foreach (module_invoke_all('node_operations') as $operation => $array) {
$options[$operation] = $array['label'];
}
}
else {
$list = domain_content_node_operations();
foreach ($list as $key => $value) {
$options[$key] = $value['label'];
}
}
// No options? No form access.
if (empty($options)) {
$form['options']['#access'] = FALSE;
}
$form['options']['operation'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => 'approve',
);
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#validate' => array(
'node_admin_nodes_validate',
),
'#submit' => array(
'node_admin_nodes_submit',
),
);
// Enable language column if translation module is enabled
// or if we have any node with language.
$multilanguage = module_exists('translation') || db_query("SELECT 1 FROM {node} WHERE language <> :language", array(
':language' => LANGUAGE_NONE,
))
->fetchField();
// Build the sortable table header.
$header = array(
'title' => array(
'data' => t('Title'),
'field' => 'n.title',
),
'domains' => array(
'data' => t('Affiliates'),
),
'type' => array(
'data' => t('Type'),
'field' => 'n.type',
),
'author' => t('Author'),
'status' => array(
'data' => t('Status'),
'field' => 'n.status',
),
'changed' => array(
'data' => t('Updated'),
'field' => 'n.changed',
'sort' => 'desc',
),
);
if ($multilanguage) {
$header['language'] = array(
'data' => t('Language'),
'field' => 'n.language',
);
}
$header['operations'] = array(
'data' => t('Operations'),
);
$query = db_select('node', 'n')
->extend('PagerDefault')
->extend('TableSort');
node_build_filter_query($query);
if (!user_access('bypass node access')) {
// If the user can view unpublished nodes on assigned domains, then we can
// continue here.
if (user_access('view unpublished domain content')) {
// Do nothing.
}
elseif (user_access('view own unpublished content')) {
$subselect = db_select('node', 'node')
->fields('node', array(
'nid',
))
->condition('node.uid', $GLOBALS['user']->uid)
->condition('node.status', 0);
$query
->condition(db_or()
->condition('n.status', 1)
->condition('n.nid', $subselect, 'IN'));
}
else {
$query
->condition('n.status', 1);
}
}
// Write the proper query.
$arg = arg(3);
// If 'all', only show content assigned to all affiliates.
if ($arg == 'all') {
domain_content_alter_node_query($query, TRUE, FALSE);
}
else {
// Restrict the query to the active domain.
domain_content_alter_node_query($query, FALSE);
}
$nids = $query
->fields('n', array(
'nid',
))
->limit(50)
->orderByHeader($header)
->execute()
->fetchCol();
$nodes = node_load_multiple($nids);
// Prepare the list of nodes.
$languages = language_list();
$destination = drupal_get_destination();
$options = array();
foreach ($nodes as $node) {
$l_options = !empty($node->language) && $node->language != LANGUAGE_NONE ? array(
'language' => $languages[$node->language],
) : array();
$options[$node->nid] = array(
'title' => array(
'data' => array(
'#type' => 'link',
'#title' => $node->title,
'#href' => 'node/' . $node->nid,
'#options' => $l_options,
'#suffix' => ' ' . theme('mark', array(
'type' => node_mark($node->nid, $node->changed),
)),
),
),
'domains' => domain_content_view_domains($node),
// set the assigned domains
'type' => check_plain(node_type_get_name($node)),
'author' => theme('username', array(
'account' => $node,
)),
'status' => $node->status ? t('published') : t('not published'),
'changed' => format_date($node->changed, 'short'),
);
if ($multilanguage) {
$options[$node->nid]['language'] = empty($node->language) || $node->language == LANGUAGE_NONE ? t('Language neutral') : t($languages[$node->language]->name);
}
// 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[$node->nid]['operations'] = array();
if (count($operations) > 1) {
// Render an unordered list of operations links.
$options[$node->nid]['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[$node->nid]['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 (!empty($operations)) {
$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', array(
'tags' => NULL,
)),
);
return $form;
}