Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ValeriiVasyliev/913130d7e9ec25b3be7fcc693281e491 to your computer and use it in GitHub Desktop.
Save ValeriiVasyliev/913130d7e9ec25b3be7fcc693281e491 to your computer and use it in GitHub Desktop.
Add column to admin/content for Drupal 7
<?
function MYMODULE_form_node_admin_content_alter(&$form, &$form_state, $form_id) {
$column_alias = 'my_cool_column';
$column_title = 'Header of my cool column';
// Load the nodes. This incurrs very little overhead as
// "$nodes = node_load_multiple($nids);" has already been run on these
// nids in node_admin_nodes(). The static cache will be used instead of
// another db query being invoked
$nodes = node_load_multiple(array_keys($form['admin']['nodes']['#options']));
// Add another column to the table header
$form['admin']['nodes']['#header'][$column_alias] = array('data' => t($column_title));
// Loop through the rows in the table and add our cool column
foreach ($form['admin']['nodes']['#options'] as $nid => $row) {
// Add data for the new column
$form['admin']['nodes']['#options'][$nid][$column_alias] = 'cool data'
}
}
<?
// колонка в админке
function bp_mixin_form_node_admin_content_alter(&$form, &$form_state, $form_id) {
// Load the nodes. This incurrs very little overhead as
// "$nodes = node_load_multiple($nids);" has already been run on these
// nids in node_admin_nodes(). The static cache will be used instead of
// another db query being invoked
$nodes = node_load_multiple(array_keys($form['admin']['nodes']['#options']));
// Grab a list of all user ids that have been responsible for changing the node
$cats = array();
$cats_titles = array();
$query = bp_getrootcats(null);
foreach($query as $item)
$cats_titles[$item->tid] = $item->name;
// Add another column to the table header
$form['admin']['nodes']['#header']['category'] = array('data' => 'Категория');
$form['admin']['nodes']['#header']['series'] = array('data' => 'Серия');
// Loop through the rows in the table and add the category column
foreach ($form['admin']['nodes']['#options'] as $nid => $row) {
// Add data for the new column
$node = $nodes[$nid];
$title = isset($node->field_catalog) ? $cats_titles[ $node->field_catalog[LANGUAGE_NONE][0]['tid'] ] : '';
$form['admin']['nodes']['#options'][$nid]['category'] = $title;
$form['admin']['nodes']['#options'][$nid]['series'] = isset($node->field_series) ? $node->field_series[LANGUAGE_NONE][0]['value'] : '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment