function RulesUIController::overviewTable
Generates the render array for an overview configuration table.
Generates the render array for an overview configuration table for arbitrary rule configs that match the given conditions.
Note: The generated overview table contains multiple links for editing the rule configurations. For the links to properly work use RulesUIController::config_menu($base_path) to generate appropriate menu items for the path at which the overview table is displayed.
Parameters
array $conditions: An array of conditions as needed by rules_config_load_multiple().
array $options: An array with optional options. Known keys are:
- 'hide status op': If set to TRUE, enable/disable links are not added. Defaults to FALSE.
- 'show plugin': If set to FALSE, the plugin is not shown. Defaults to TRUE.
- 'show events': If set to TRUE, the event column is shown. Defaults to TRUE if only reaction rules are listed.
- 'show execution op': If set to TRUE an operation for execution a component is shown for components, as well as a link to schedule a component if the rules scheduler module is enabled.
- 'base path': Optionally, a different base path to use instead of the currently set RulesPluginUI::$basePath. If no base path has been set yet, the current path is used by default.
Return value
array A renderable array.
File
-
ui/
ui.controller.inc, line 193
Class
- RulesUIController
- Controller class for the Rules UI.
Code
public function overviewTable($conditions = array(), $options = array()) {
$options += array(
'hide status op' => FALSE,
'show plugin' => TRUE,
'show events' => isset($conditions['plugin']) && $conditions['plugin'] == 'reaction rule',
'show execution op' => !(isset($conditions['plugin']) && $conditions['plugin'] == 'reaction rule'),
);
// By default show only configurations owned by rules.
$conditions += array(
'owner' => 'rules',
);
if (!empty($options['base path'])) {
RulesPluginUI::$basePath = $options['base path'];
}
elseif (!isset(RulesPluginUI::$basePath)) {
// Default to the current path, only if no path has been set yet.
RulesPluginUI::$basePath = current_path();
}
$entities = entity_load('rules_config', FALSE, $conditions);
ksort($entities);
// Prepare some variables used by overviewTableRow().
$this->event_info = rules_fetch_data('event_info');
$this->cache = rules_get_cache();
$rows = array();
foreach ($entities as $id => $entity) {
if (user_access('bypass rules access') || $entity->access()) {
$rows[] = $this->overviewTableRow($conditions, $id, $entity, $options);
}
}
// Assemble the right table header.
$header = array(
t('Name'),
t('Event'),
t('Plugin'),
t('Status'),
array(
'data' => t('Operations'),
),
);
if (!$options['show events']) {
// Remove the event heading as there is no such column.
unset($header[1]);
}
if (!$options['show plugin']) {
unset($header[2]);
}
// Fix the header operation column colspan.
$num_cols = isset($rows[0]) ? count($rows[0]) : 0;
if (($addition = $num_cols - count($header)) > 0) {
$header[4]['colspan'] = $addition + 1;
}
$table = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('None.'),
);
$table['#attributes']['class'][] = 'rules-overview-table';
$table['#attached']['css'][] = drupal_get_path('module', 'rules') . '/ui/rules.ui.css';
// @todo Hide configs where access() is FALSE.
return $table;
}