2007-08-20 07:03:08 +00:00
< ? php
2012-01-23 04:47:08 +00:00
use Drupal\Core\Database\Query\SelectInterface ;
2011-12-29 19:28:11 +00:00
2007-08-20 07:03:08 +00:00
/**
* @ file
* Content administration and module settings UI .
*/
/**
2011-11-28 11:44:25 +00:00
* Page callback : Form constructor for the permission rebuild confirmation form .
*
* @ see node_menu ()
* @ see node_configure_rebuild_confirm_submit ()
2007-08-20 07:03:08 +00:00
*/
function node_configure_rebuild_confirm () {
2007-11-12 19:06:33 +00:00
return confirm_form ( array (), t ( 'Are you sure you want to rebuild the permissions on site content?' ),
2009-07-06 13:52:57 +00:00
'admin/reports/status' , t ( 'This action rebuilds all permissions on site content, and may be a lengthy process. This action cannot be undone.' ), t ( 'Rebuild permissions' ), t ( 'Cancel' ));
2007-08-20 07:03:08 +00:00
}
/**
2011-11-28 11:44:25 +00:00
* Form submission handler for node_configure_rebuild_confirm () .
2007-08-20 07:03:08 +00:00
*/
2007-08-29 19:56:09 +00:00
function node_configure_rebuild_confirm_submit ( $form , & $form_state ) {
2007-09-02 14:42:30 +00:00
node_access_rebuild ( TRUE );
2009-06-05 05:28:28 +00:00
$form_state [ 'redirect' ] = 'admin/reports/status' ;
2007-08-20 07:03:08 +00:00
}
/**
2009-12-04 16:49:48 +00:00
* Implements hook_node_operations () .
2007-08-20 07:03:08 +00:00
*/
function node_node_operations () {
$operations = array (
'publish' => array (
2010-01-13 23:30:43 +00:00
'label' => t ( 'Publish selected content' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'status' => NODE_PUBLISHED )),
2007-08-20 07:03:08 +00:00
),
'unpublish' => array (
2010-01-13 23:30:43 +00:00
'label' => t ( 'Unpublish selected content' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'status' => NODE_NOT_PUBLISHED )),
2007-08-20 07:03:08 +00:00
),
'promote' => array (
2010-01-13 23:30:43 +00:00
'label' => t ( 'Promote selected content to front page' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'status' => NODE_PUBLISHED , 'promote' => NODE_PROMOTED )),
2007-08-20 07:03:08 +00:00
),
'demote' => array (
2010-01-13 23:30:43 +00:00
'label' => t ( 'Demote selected content from front page' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'promote' => NODE_NOT_PROMOTED )),
2007-08-20 07:03:08 +00:00
),
'sticky' => array (
2010-01-13 23:30:43 +00:00
'label' => t ( 'Make selected content sticky' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'status' => NODE_PUBLISHED , 'sticky' => NODE_STICKY )),
2007-08-20 07:03:08 +00:00
),
'unsticky' => array (
2010-01-13 23:30:43 +00:00
'label' => t ( 'Make selected content not sticky' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'sticky' => NODE_NOT_STICKY )),
2007-08-20 07:03:08 +00:00
),
'delete' => array (
2010-01-13 23:30:43 +00:00
'label' => t ( 'Delete selected content' ),
2007-08-20 07:03:08 +00:00
'callback' => NULL ,
),
);
return $operations ;
}
/**
2011-11-28 11:44:25 +00:00
* Lists node administration filters that can be applied .
*
* @ return
* Associative array of filters .
2007-08-20 07:03:08 +00:00
*/
function node_filters () {
// Regular filters
2008-01-29 11:08:17 +00:00
$filters [ 'status' ] = array (
'title' => t ( 'status' ),
'options' => array (
2009-11-03 04:35:01 +00:00
'[any]' => t ( 'any' ),
2008-01-29 11:08:17 +00:00
'status-1' => t ( 'published' ),
'status-0' => t ( 'not published' ),
'promote-1' => t ( 'promoted' ),
'promote-0' => t ( 'not promoted' ),
'sticky-1' => t ( 'sticky' ),
'sticky-0' => t ( 'not sticky' ),
),
2007-08-20 07:03:08 +00:00
);
// Include translation states if we have this module enabled
if ( module_exists ( 'translation' )) {
2008-01-29 11:08:17 +00:00
$filters [ 'status' ][ 'options' ] += array (
'translate-0' => t ( 'Up to date translation' ),
'translate-1' => t ( 'Outdated translation' ),
);
2007-08-20 07:03:08 +00:00
}
2009-11-03 04:35:01 +00:00
$filters [ 'type' ] = array (
'title' => t ( 'type' ),
'options' => array (
'[any]' => t ( 'any' ),
) + node_type_get_names (),
);
2007-08-20 07:03:08 +00:00
2012-03-19 06:57:15 +00:00
// Language filter if language support is present.
2012-01-23 15:46:29 +00:00
if ( language_multilingual ()) {
2012-06-15 17:03:15 +00:00
$languages = language_list ( LANGUAGE_ALL );
2012-01-23 15:46:29 +00:00
foreach ( $languages as $langcode => $language ) {
2012-06-15 17:03:15 +00:00
// Make locked languages appear special in the list.
$language_options [ $langcode ] = $language -> locked ? t ( '- @name -' , array ( '@name' => $language -> name )) : $language -> name ;
2012-01-23 15:46:29 +00:00
}
2009-11-03 04:35:01 +00:00
$filters [ 'language' ] = array (
'title' => t ( 'language' ),
'options' => array (
2012-02-02 16:08:57 +00:00
'[any]' => t ( '- Any -' ),
2012-01-23 15:46:29 +00:00
) + $language_options ,
2009-11-03 04:35:01 +00:00
);
2007-08-20 07:03:08 +00:00
}
return $filters ;
}
/**
2011-11-28 11:44:25 +00:00
* Applies filters for the node administration overview based on session .
2009-07-21 01:36:51 +00:00
*
* @ param $query
* A SelectQuery to which the filters should be applied .
2007-08-20 07:03:08 +00:00
*/
2011-12-29 19:28:11 +00:00
function node_build_filter_query ( SelectInterface $query ) {
2007-08-20 07:03:08 +00:00
// Build query
2009-06-02 06:58:17 +00:00
$filter_data = isset ( $_SESSION [ 'node_overview_filter' ]) ? $_SESSION [ 'node_overview_filter' ] : array ();
foreach ( $filter_data as $index => $filter ) {
2007-08-20 07:03:08 +00:00
list ( $key , $value ) = $filter ;
switch ( $key ) {
case 'status' :
// Note: no exploitable hole as $key/$value have already been checked when submitted
list ( $key , $value ) = explode ( '-' , $value , 2 );
case 'type' :
case 'language' :
2009-07-21 01:36:51 +00:00
$query -> condition ( 'n.' . $key , $value );
2007-11-12 17:26:16 +00:00
break ;
2007-08-20 07:03:08 +00:00
}
}
}
/**
2011-11-28 11:44:25 +00:00
* Returns the node administration filters form object to node_admin_content () .
*
* @ see node_multiple_delete_confirm ()
* @ see node_multiple_delete_confirm_submit ()
* @ see node_admin_nodes ()
* @ see node_admin_nodes_submit ()
* @ see node_admin_nodes_validate ()
* @ see node_filter_form_submit ()
* @ ingroup forms
2007-08-20 07:03:08 +00:00
*/
function node_filter_form () {
2009-06-02 06:58:17 +00:00
$session = isset ( $_SESSION [ 'node_overview_filter' ]) ? $_SESSION [ 'node_overview_filter' ] : array ();
2007-08-20 07:03:08 +00:00
$filters = node_filters ();
$i = 0 ;
2008-01-29 11:08:17 +00:00
$form [ 'filters' ] = array (
'#type' => 'fieldset' ,
2007-08-20 07:03:08 +00:00
'#title' => t ( 'Show only items where' ),
2010-09-17 14:53:22 +00:00
'#theme' => 'exposed_filters__node' ,
2007-08-20 07:03:08 +00:00
);
foreach ( $session as $filter ) {
list ( $type , $value ) = $filter ;
2008-11-22 14:09:41 +00:00
if ( $type == 'term' ) {
2007-08-20 07:03:08 +00:00
// Load term name from DB rather than search and parse options array.
2009-01-08 01:16:57 +00:00
$value = module_invoke ( 'taxonomy' , 'term_load' , $value );
2007-08-20 07:03:08 +00:00
$value = $value -> name ;
}
2008-10-12 04:30:09 +00:00
elseif ( $type == 'language' ) {
2012-02-02 16:08:57 +00:00
$value = language_name ( $value );
2007-08-20 07:03:08 +00:00
}
else {
$value = $filters [ $type ][ 'options' ][ $value ];
}
2010-09-17 14:53:22 +00:00
$t_args = array ( '%property' => $filters [ $type ][ 'title' ], '%value' => $value );
2007-08-20 07:03:08 +00:00
if ( $i ++ ) {
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'current' ][] = array ( '#markup' => t ( 'and where %property is %value' , $t_args ));
2007-08-20 07:03:08 +00:00
}
else {
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'current' ][] = array ( '#markup' => t ( 'where %property is %value' , $t_args ));
2007-08-20 07:03:08 +00:00
}
if ( in_array ( $type , array ( 'type' , 'language' ))) {
// Remove the option if it is already being filtered on.
unset ( $filters [ $type ]);
}
}
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ] = array (
'#type' => 'container' ,
'#attributes' => array ( 'class' => array ( 'clearfix' )),
'#prefix' => ( $i ? '<div class="additional-filters">' . t ( 'and where' ) . '</div>' : '' ),
);
$form [ 'filters' ][ 'status' ][ 'filters' ] = array (
'#type' => 'container' ,
'#attributes' => array ( 'class' => array ( 'filters' )),
);
2007-08-20 07:03:08 +00:00
foreach ( $filters as $key => $filter ) {
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ][ 'filters' ][ $key ] = array (
2009-11-03 04:35:01 +00:00
'#type' => 'select' ,
'#options' => $filter [ 'options' ],
'#title' => $filter [ 'title' ],
'#default_value' => '[any]' ,
);
2007-08-20 07:03:08 +00:00
}
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ][ 'actions' ] = array (
2010-04-24 14:49:14 +00:00
'#type' => 'actions' ,
'#attributes' => array ( 'class' => array ( 'container-inline' )),
2010-01-03 21:01:04 +00:00
);
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ][ 'actions' ][ 'submit' ] = array (
'#type' => 'submit' ,
'#value' => count ( $session ) ? t ( 'Refine' ) : t ( 'Filter' ),
);
2007-08-20 07:03:08 +00:00
if ( count ( $session )) {
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ][ 'actions' ][ 'undo' ] = array ( '#type' => 'submit' , '#value' => t ( 'Undo' ));
$form [ 'filters' ][ 'status' ][ 'actions' ][ 'reset' ] = array ( '#type' => 'submit' , '#value' => t ( 'Reset' ));
2007-08-20 07:03:08 +00:00
}
2011-10-31 04:05:57 +00:00
drupal_add_js ( 'core/misc/form.js' );
2010-07-07 17:56:42 +00:00
2007-08-20 07:03:08 +00:00
return $form ;
}
/**
2011-11-28 11:44:25 +00:00
* Form submission handler for node_filter_form () .
*
* @ see node_admin_content ()
* @ see node_multiple_delete_confirm ()
* @ see node_multiple_delete_confirm_submit ()
* @ see node_admin_nodes ()
* @ see node_admin_nodes_submit ()
* @ see node_admin_nodes_validate ()
* @ see node_filter_form ()
2007-08-20 07:03:08 +00:00
*/
function node_filter_form_submit ( $form , & $form_state ) {
$filters = node_filters ();
switch ( $form_state [ 'values' ][ 'op' ]) {
case t ( 'Filter' ) :
case t ( 'Refine' ) :
2009-11-03 04:35:01 +00:00
// Apply every filter that has a choice selected other than 'any'.
foreach ( $filters as $filter => $options ) {
if ( isset ( $form_state [ 'values' ][ $filter ]) && $form_state [ 'values' ][ $filter ] != '[any]' ) {
2011-11-30 02:13:33 +00:00
$_SESSION [ 'node_overview_filter' ][] = array ( $filter , $form_state [ 'values' ][ $filter ]);
2007-08-20 07:03:08 +00:00
}
}
break ;
case t ( 'Undo' ) :
array_pop ( $_SESSION [ 'node_overview_filter' ]);
break ;
case t ( 'Reset' ) :
2009-06-02 06:58:17 +00:00
$_SESSION [ 'node_overview_filter' ] = array ();
2007-08-20 07:03:08 +00:00
break ;
}
}
2007-12-20 09:08:35 +00:00
/**
2011-11-28 11:44:25 +00:00
* Updates all nodes in the passed - in array with the passed - in field values .
2007-12-20 09:08:35 +00:00
*
* IMPORTANT NOTE : This function is intended to work when called
2011-11-28 11:44:25 +00:00
* from a form submission handler . Calling it outside of the form submission
2007-12-20 09:08:35 +00:00
* process may not work correctly .
*
* @ param array $nodes
* Array of node nids to update .
* @ param array $updates
2011-11-28 11:44:25 +00:00
* Array of key / value pairs with node field names and the value to update
* that field to .
*
* @ ingroup batch
2007-12-20 09:08:35 +00:00
*/
function node_mass_update ( $nodes , $updates ) {
// We use batch processing to prevent timeout when updating a large number
// of nodes.
if ( count ( $nodes ) > 10 ) {
$batch = array (
'operations' => array (
array ( '_node_mass_update_batch_process' , array ( $nodes , $updates ))
),
'finished' => '_node_mass_update_batch_finished' ,
'title' => t ( 'Processing' ),
// We use a single multi-pass operation, so the default
// 'Remaining x of y operations' message will be confusing here.
'progress_message' => '' ,
'error_message' => t ( 'The update has encountered an error.' ),
// The operations do not live in the .module file, so we need to
// tell the batch engine which file to load before calling them.
2008-04-14 17:48:46 +00:00
'file' => drupal_get_path ( 'module' , 'node' ) . '/node.admin.inc' ,
2007-12-20 09:08:35 +00:00
);
batch_set ( $batch );
}
else {
2007-12-28 12:02:52 +00:00
foreach ( $nodes as $nid ) {
2007-12-20 09:08:35 +00:00
_node_mass_update_helper ( $nid , $updates );
}
drupal_set_message ( t ( 'The update has been performed.' ));
}
}
/**
2011-11-28 11:44:25 +00:00
* Updates individual nodes when fewer than 10 are queued .
*
* @ param $nid
* ID of node to update .
* @ param $updates
* Associative array of updates .
*
* @ see node_mass_update ()
2007-12-20 09:08:35 +00:00
*/
function _node_mass_update_helper ( $nid , $updates ) {
$node = node_load ( $nid , NULL , TRUE );
2010-11-30 19:31:47 +00:00
// For efficiency manually save the original node before applying any changes.
$node -> original = clone $node ;
2007-12-20 09:08:35 +00:00
foreach ( $updates as $name => $value ) {
$node -> $name = $value ;
}
2012-04-26 16:44:37 +00:00
$node -> save ();
2007-12-20 09:08:35 +00:00
return $node ;
}
/**
2011-11-28 11:44:25 +00:00
* Executes a batch operation for node_mass_update () .
2007-12-20 09:08:35 +00:00
*/
function _node_mass_update_batch_process ( $nodes , $updates , & $context ) {
if ( ! isset ( $context [ 'sandbox' ][ 'progress' ])) {
$context [ 'sandbox' ][ 'progress' ] = 0 ;
$context [ 'sandbox' ][ 'max' ] = count ( $nodes );
$context [ 'sandbox' ][ 'nodes' ] = $nodes ;
}
// Process nodes by groups of 5.
$count = min ( 5 , count ( $context [ 'sandbox' ][ 'nodes' ]));
for ( $i = 1 ; $i <= $count ; $i ++ ) {
// For each nid, load the node, reset the values, and save it.
$nid = array_shift ( $context [ 'sandbox' ][ 'nodes' ]);
$node = _node_mass_update_helper ( $nid , $updates );
// Store result for post-processing in the finished callback.
2012-07-22 18:07:00 +00:00
$context [ 'results' ][] = l ( $node -> label (), 'node/' . $node -> nid );
2007-12-20 09:08:35 +00:00
// Update our progress information.
$context [ 'sandbox' ][ 'progress' ] ++ ;
}
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ( $context [ 'sandbox' ][ 'progress' ] != $context [ 'sandbox' ][ 'max' ]) {
$context [ 'finished' ] = $context [ 'sandbox' ][ 'progress' ] / $context [ 'sandbox' ][ 'max' ];
}
}
/**
2011-11-28 11:44:25 +00:00
* Reports the 'finished' status of batch operation for node_mass_update () .
2007-12-20 09:08:35 +00:00
*/
function _node_mass_update_batch_finished ( $success , $results , $operations ) {
if ( $success ) {
drupal_set_message ( t ( 'The update has been performed.' ));
}
else {
drupal_set_message ( t ( 'An error occurred and processing did not complete.' ), 'error' );
$message = format_plural ( count ( $results ), '1 item successfully processed:' , '@count items successfully processed:' );
2009-10-09 01:00:08 +00:00
$message .= theme ( 'item_list' , array ( 'items' => $results ));
2007-12-20 09:08:35 +00:00
drupal_set_message ( $message );
}
}
2007-08-20 07:03:08 +00:00
/**
2011-11-28 11:44:25 +00:00
* Page callback : Form constructor for the content administration form .
*
* @ see node_multiple_delete_confirm ()
* @ see node_multiple_delete_confirm_submit ()
* @ see node_admin_nodes ()
* @ see node_admin_nodes_submit ()
* @ see node_admin_nodes_validate ()
* @ see node_filter_form ()
* @ see node_filter_form_submit ()
* @ see node_menu ()
2007-08-20 07:03:08 +00:00
*/
2009-09-18 00:12:48 +00:00
function node_admin_content ( $form , $form_state ) {
2007-08-20 07:03:08 +00:00
if ( isset ( $form_state [ 'values' ][ 'operation' ]) && $form_state [ 'values' ][ 'operation' ] == 'delete' ) {
2009-10-22 01:19:45 +00:00
return node_multiple_delete_confirm ( $form , $form_state , array_filter ( $form_state [ 'values' ][ 'nodes' ]));
2007-08-20 07:03:08 +00:00
}
2009-11-14 07:58:50 +00:00
$form [ 'filter' ] = node_filter_form ();
2009-08-23 04:37:52 +00:00
$form [ '#submit' ][] = 'node_filter_form_submit' ;
2008-09-15 00:02:10 +00:00
$form [ 'admin' ] = node_admin_nodes ();
2007-08-20 07:03:08 +00:00
return $form ;
}
2008-01-29 11:08:17 +00:00
/**
2011-11-28 11:44:25 +00:00
* Returns the admin form object to node_admin_content () .
*
* @ see node_multiple_delete_confirm ()
* @ see node_multiple_delete_confirm_submit ()
* @ see node_admin_nodes_submit ()
* @ see node_admin_nodes_validate ()
* @ see node_filter_form ()
* @ see node_filter_form_submit ()
* @ ingroup forms
2008-01-29 11:08:17 +00:00
*/
2007-08-20 07:03:08 +00:00
function node_admin_nodes () {
2009-11-14 07:58:50 +00:00
$admin_access = user_access ( 'administer nodes' );
2008-09-15 20:48:10 +00:00
2008-09-15 00:02:10 +00:00
// Build the 'Update options' form.
2008-01-29 11:08:17 +00:00
$form [ 'options' ] = array (
'#type' => 'fieldset' ,
2007-08-20 07:03:08 +00:00
'#title' => t ( 'Update options' ),
2010-03-03 19:46:26 +00:00
'#attributes' => array ( 'class' => array ( 'container-inline' )),
2009-11-14 07:58:50 +00:00
'#access' => $admin_access ,
2007-08-20 07:03:08 +00:00
);
$options = array ();
foreach ( module_invoke_all ( 'node_operations' ) as $operation => $array ) {
$options [ $operation ] = $array [ 'label' ];
}
2008-01-29 11:08:17 +00:00
$form [ 'options' ][ 'operation' ] = array (
'#type' => 'select' ,
2010-10-20 01:31:07 +00:00
'#title' => t ( 'Operation' ),
'#title_display' => 'invisible' ,
2008-01-29 11:08:17 +00:00
'#options' => $options ,
'#default_value' => 'approve' ,
);
2007-08-20 07:03:08 +00:00
$form [ 'options' ][ 'submit' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Update' ),
2009-10-24 21:39:40 +00:00
'#validate' => array ( 'node_admin_nodes_validate' ),
2009-11-14 07:58:50 +00:00
'#submit' => array ( 'node_admin_nodes_submit' ),
2007-08-20 07:03:08 +00:00
);
2012-03-19 06:57:15 +00:00
// Enable language column and filter if multiple languages are enabled.
$multilingual = language_multilingual ();
2009-11-14 07:58:50 +00:00
// Build the sortable table header.
$header = array (
'title' => array ( 'data' => t ( 'Title' ), 'field' => 'n.title' ),
2011-08-01 02:44:09 +00:00
'type' => array ( 'data' => t ( 'Content type' ), 'field' => 'n.type' ),
2010-01-08 05:57:12 +00:00
'author' => t ( 'Author' ),
2009-11-14 07:58:50 +00:00
'status' => array ( 'data' => t ( 'Status' ), 'field' => 'n.status' ),
'changed' => array ( 'data' => t ( 'Updated' ), 'field' => 'n.changed' , 'sort' => 'desc' )
);
2012-03-19 06:57:15 +00:00
if ( $multilingual ) {
2012-02-23 14:22:18 +00:00
$header [ 'language_name' ] = array ( 'data' => t ( 'Language' ), 'field' => 'n.langcode' );
2009-11-14 07:58:50 +00:00
}
$header [ 'operations' ] = array ( 'data' => t ( 'Operations' ));
2012-06-05 05:42:19 +00:00
$query = db_select ( 'node' , 'n' )
-> extend ( 'Drupal\Core\Database\Query\PagerSelectExtender' )
2012-06-08 12:26:56 +00:00
-> extend ( 'Drupal\Core\Database\Query\TableSortExtender' );
2009-11-14 07:58:50 +00:00
node_build_filter_query ( $query );
if ( ! user_access ( 'bypass node access' )) {
// If the user is able to view their own unpublished nodes, allow them
// to see these in addition to published nodes. Check that they actually
// have some unpublished nodes to view before adding the condition.
if ( user_access ( 'view own unpublished content' ) && $own_unpublished = db_query ( 'SELECT nid FROM {node} WHERE uid = :uid AND status = :status' , array ( ':uid' => $GLOBALS [ 'user' ] -> uid , ':status' => 0 )) -> fetchCol ()) {
$query -> condition ( db_or ()
-> condition ( 'n.status' , 1 )
-> condition ( 'n.nid' , $own_unpublished , 'IN' )
);
}
else {
// If not, restrict the query to published nodes.
$query -> condition ( 'n.status' , 1 );
}
}
$nids = $query
-> fields ( 'n' , array ( 'nid' ))
-> limit ( 50 )
-> orderByHeader ( $header )
2012-08-19 14:54:14 +00:00
-> addTag ( 'node_access' )
2009-11-14 07:58:50 +00:00
-> execute ()
-> fetchCol ();
$nodes = node_load_multiple ( $nids );
// Prepare the list of nodes.
2012-06-15 17:03:15 +00:00
$languages = language_list ( LANGUAGE_ALL );
2007-08-20 07:03:08 +00:00
$destination = drupal_get_destination ();
2009-11-14 07:58:50 +00:00
$options = array ();
foreach ( $nodes as $node ) {
2012-03-08 15:10:59 +00:00
$l_options = $node -> langcode != LANGUAGE_NOT_SPECIFIED && isset ( $languages [ $node -> langcode ]) ? array ( 'language' => $languages [ $node -> langcode ]) : array ();
2009-10-08 18:26:33 +00:00
$options [ $node -> nid ] = array (
2009-11-03 05:27:18 +00:00
'title' => array (
'data' => array (
'#type' => 'link' ,
2012-07-22 18:07:00 +00:00
'#title' => $node -> label (),
2009-11-03 05:27:18 +00:00
'#href' => 'node/' . $node -> nid ,
'#options' => $l_options ,
'#suffix' => ' ' . theme ( 'mark' , array ( 'type' => node_mark ( $node -> nid , $node -> changed ))),
),
),
2009-11-14 07:58:50 +00:00
'type' => check_plain ( node_type_get_name ( $node )),
2009-10-09 01:00:08 +00:00
'author' => theme ( 'username' , array ( 'account' => $node )),
2009-11-14 07:58:50 +00:00
'status' => $node -> status ? t ( 'published' ) : t ( 'not published' ),
2009-10-08 18:26:33 +00:00
'changed' => format_date ( $node -> changed , 'short' ),
);
2012-03-19 06:57:15 +00:00
if ( $multilingual ) {
2012-02-23 14:22:18 +00:00
$options [ $node -> nid ][ 'language_name' ] = language_name ( $node -> langcode );
2007-08-20 07:03:08 +00:00
}
2009-11-14 07:58:50 +00:00
// 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 (
2010-01-08 07:36:53 +00:00
'#theme' => 'links__node_operations' ,
2009-11-14 07:58:50 +00:00
'#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 ( $admin_access ) {
$form [ 'nodes' ] = array (
'#type' => 'tableselect' ,
'#header' => $header ,
'#options' => $options ,
'#empty' => t ( 'No content available.' ),
2009-11-03 05:27:18 +00:00
);
2007-08-20 07:03:08 +00:00
}
2009-11-14 07:58:50 +00:00
// Otherwise, use a simple table.
else {
$form [ 'nodes' ] = array (
'#theme' => 'table' ,
'#header' => $header ,
'#rows' => $options ,
2009-12-02 14:56:32 +00:00
'#empty' => t ( 'No content available.' ),
2009-11-14 07:58:50 +00:00
);
}
2010-10-06 13:38:40 +00:00
$form [ 'pager' ] = array ( '#markup' => theme ( 'pager' ));
2007-08-20 07:03:08 +00:00
return $form ;
}
2008-01-29 11:08:17 +00:00
/**
2011-11-28 11:44:25 +00:00
* Form validation handler for node_admin_nodes () .
2008-02-06 19:38:28 +00:00
*
2011-11-28 11:44:25 +00:00
* Checks if any nodes have been selected to perform the chosen
2008-01-29 11:08:17 +00:00
* 'Update option' on .
2011-11-28 11:44:25 +00:00
*
* @ see node_multiple_delete_confirm ()
* @ see node_multiple_delete_confirm_submit ()
* @ see node_admin_nodes ()
* @ see node_admin_nodes_submit ()
* @ see node_filter_form ()
* @ see node_filter_form_submit ()
2008-01-29 11:08:17 +00:00
*/
function node_admin_nodes_validate ( $form , & $form_state ) {
2009-10-24 21:39:40 +00:00
// Error if there are no items to select.
if ( ! is_array ( $form_state [ 'values' ][ 'nodes' ]) || ! count ( array_filter ( $form_state [ 'values' ][ 'nodes' ]))) {
2008-01-29 11:08:17 +00:00
form_set_error ( '' , t ( 'No items selected.' ));
}
}
/**
2011-11-28 11:44:25 +00:00
* Form submission handler for node_admin_nodes () .
*
* Executes the chosen 'Update option' on the selected nodes .
2008-02-06 19:38:28 +00:00
*
2011-11-28 11:44:25 +00:00
* @ see node_multiple_delete_confirm ()
* @ see node_multiple_delete_confirm_submit ()
* @ see node_admin_nodes ()
* @ see node_admin_nodes_validate ()
* @ see node_filter_form ()
* @ see node_filter_form_submit ()
2008-01-29 11:08:17 +00:00
*/
function node_admin_nodes_submit ( $form , & $form_state ) {
$operations = module_invoke_all ( 'node_operations' );
$operation = $operations [ $form_state [ 'values' ][ 'operation' ]];
// Filter out unchecked nodes
$nodes = array_filter ( $form_state [ 'values' ][ 'nodes' ]);
if ( $function = $operation [ 'callback' ]) {
// Add in callback arguments if present.
if ( isset ( $operation [ 'callback arguments' ])) {
$args = array_merge ( array ( $nodes ), $operation [ 'callback arguments' ]);
}
else {
$args = array ( $nodes );
}
call_user_func_array ( $function , $args );
2012-06-13 01:37:07 +00:00
cache_invalidate ( array ( 'content' => TRUE ));
2008-01-29 11:08:17 +00:00
}
else {
2008-12-20 18:24:41 +00:00
// We need to rebuild the form to go to a second step. For example, to
2008-01-29 11:08:17 +00:00
// show the confirmation form for the deletion of nodes.
$form_state [ 'rebuild' ] = TRUE ;
}
}
2011-11-28 11:44:25 +00:00
/**
* Multiple node deletion confirmation form for node_admin_content () .
*
* @ see node_multiple_delete_confirm_submit ()
* @ see node_admin_nodes ()
* @ see node_admin_nodes_submit ()
* @ see node_admin_nodes_validate ()
* @ see node_filter_form ()
* @ see node_filter_form_submit ()
*/
2009-09-18 00:12:48 +00:00
function node_multiple_delete_confirm ( $form , & $form_state , $nodes ) {
2007-08-20 07:03:08 +00:00
$form [ 'nodes' ] = array ( '#prefix' => '<ul>' , '#suffix' => '</ul>' , '#tree' => TRUE );
// array_filter returns only elements with TRUE values
foreach ( $nodes as $nid => $value ) {
2009-04-25 16:33:48 +00:00
$title = db_query ( 'SELECT title FROM {node} WHERE nid = :nid' , array ( ':nid' => $nid )) -> fetchField ();
2008-01-29 11:08:17 +00:00
$form [ 'nodes' ][ $nid ] = array (
'#type' => 'hidden' ,
'#value' => $nid ,
'#prefix' => '<li>' ,
2008-04-14 17:48:46 +00:00
'#suffix' => check_plain ( $title ) . " </li> \n " ,
2008-01-29 11:08:17 +00:00
);
2007-08-20 07:03:08 +00:00
}
$form [ 'operation' ] = array ( '#type' => 'hidden' , '#value' => 'delete' );
$form [ '#submit' ][] = 'node_multiple_delete_confirm_submit' ;
2009-05-24 17:39:35 +00:00
$confirm_question = format_plural ( count ( $nodes ),
'Are you sure you want to delete this item?' ,
2009-05-15 03:58:35 +00:00
'Are you sure you want to delete these items?' );
2009-05-24 17:39:35 +00:00
return confirm_form ( $form ,
2009-05-15 03:58:35 +00:00
$confirm_question ,
2009-07-30 19:24:21 +00:00
'admin/content' , t ( 'This action cannot be undone.' ),
2009-05-15 03:58:35 +00:00
t ( 'Delete' ), t ( 'Cancel' ));
2007-08-20 07:03:08 +00:00
}
2011-11-28 11:44:25 +00:00
/**
* Form submission handler for node_multiple_delete_confirm () .
*
* @ see node_multiple_delete_confirm ()
* @ see node_admin_nodes ()
* @ see node_admin_nodes_submit ()
* @ see node_admin_nodes_validate ()
* @ see node_filter_form ()
* @ see node_filter_form_submit ()
*/
2007-08-20 07:03:08 +00:00
function node_multiple_delete_confirm_submit ( $form , & $form_state ) {
if ( $form_state [ 'values' ][ 'confirm' ]) {
2009-05-20 05:39:45 +00:00
node_delete_multiple ( array_keys ( $form_state [ 'values' ][ 'nodes' ]));
$count = count ( $form_state [ 'values' ][ 'nodes' ]);
watchdog ( 'content' , 'Deleted @count posts.' , array ( '@count' => $count ));
2010-12-09 02:16:21 +00:00
drupal_set_message ( format_plural ( $count , 'Deleted 1 post.' , 'Deleted @count posts.' ));
2007-08-20 07:03:08 +00:00
}
2009-07-30 19:24:21 +00:00
$form_state [ 'redirect' ] = 'admin/content' ;
2007-08-20 07:03:08 +00:00
}