class CacheflushUIController in CacheFlush 7.3
Custom controller for the administrator UI.
Hierarchy
- class \EntityDefaultUIController
- class \CacheflushUIController
Expanded class hierarchy of CacheflushUIController
1 string reference to 'CacheflushUIController'
- cacheflush_ui_entity_info_alter in modules/
cacheflush_ui/ cacheflush_ui.module - Implements hook_entity_info_alter().
File
- modules/
cacheflush_ui/ includes/ cacheflush_ui.class.inc, line 11 - Contains the CacheflushUIController class.
View source
class CacheflushUIController extends EntityDefaultUIController {
/**
* Overrides EntityDefaultUIController::hook_menu().
*/
public function hook_menu() {
$items = parent::hook_menu();
$items[$this->path]['title'] = 'CacheFlush';
$items[$this->path]['access callback'] = 'user_access';
$items[$this->path]['access arguments'] = array(
'cacheflush administer',
);
$items[$this->path . '/add']['file'] = 'includes/cacheflush_ui.forms.inc';
$items[$this->path . '/add']['file path'] = drupal_get_path('module', 'cacheflush_ui');
return $items;
}
/**
* Overrides EntityDefaultUIController::overviewForm().
*/
public function overviewForm($form, &$form_state) {
if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'delete') {
return cacheflush_ui_multiple_delete_confirm($form, $form_state, array_filter($form_state['values']['presets']));
}
$admin_access = user_access('cacheflush administer');
drupal_set_title(t('Presets'));
$form['filters'] = array(
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#title' => t('Filter'),
'#theme' => 'exposed_filters__cacheflush',
'#access' => $admin_access,
);
$form['filters']['container'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'clearfix',
),
),
);
$form['filters']['container']['ops'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'filters',
),
),
);
$form['filters']['container']['ops']['status'] = array(
'#type' => 'select',
'#title' => t('Status'),
'#options' => array(
'all' => t('any'),
1 => t('enabled'),
0 => t('disabled'),
),
'#default_value' => isset($_GET['status']) ? $_GET['status'] : NULL,
);
$form['filters']['container']['ops']['menu'] = array(
'#type' => 'select',
'#title' => t('Menu entry'),
'#options' => array(
'all' => t('any'),
1 => t('Yes'),
0 => t('No'),
),
'#default_value' => isset($_GET['menu']) ? $_GET['menu'] : NULL,
);
$form['filters']['container']['actions'] = array(
'#type' => 'actions',
'#attributes' => array(
'class' => array(
'container-inline',
),
),
);
$form['filters']['container']['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Filter'),
'#name' => 'filters',
);
$form['filters']['container']['actions']['reset']['#markup'] = l(t('Reset'), $_GET['q']);
// Build the 'Otions' form.
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Options'),
'#attributes' => array(
'class' => array(
'container-inline',
),
),
'#access' => $admin_access,
);
$options = array();
foreach (module_invoke_all('cacheflush_ui_operations') as $operation => $array) {
$options[$operation] = $array['label'];
}
$form['options']['operation'] = array(
'#type' => 'select',
'#title' => t('Operation'),
'#title_display' => 'invisible',
'#options' => $options,
'#default_value' => 'enable',
);
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#name' => 'op-submit',
);
$conditions = array();
if (isset($_GET['status'])) {
$conditions['status'] = array(
'value' => $_GET['status'],
'op' => '=',
);
}
if (isset($_GET['menu'])) {
$conditions['menu'] = array(
'value' => $_GET['menu'],
'op' => '=',
);
}
$form['presets'] = $this
->overviewTable($conditions);
$form['pager'] = array(
'#theme' => 'pager',
);
return $form;
}
/**
* Overrides EntityDefaultUIController::overviewFormSubmit().
*/
public function overviewFormValidate($form, &$form_state) {
// Error if there are no items to select.
if (isset($form_state['clicked_button']['#value']) && $form_state['clicked_button']['#name'] == 'op-submit' && (!is_array($form_state['values']['presets']) || !count(array_filter($form_state['values']['presets'])))) {
form_set_error('', t('No items selected.'));
}
}
/**
* Overrides EntityDefaultUIController::overviewFormSubmit().
*/
public function overviewFormSubmit($form, &$form_state) {
$args = array();
if (isset($form_state['values']['status']) && $form_state['values']['status'] != 'all') {
$args['status'] = $form_state['values']['status'];
}
if (isset($form_state['values']['menu']) && $form_state['values']['menu'] != 'all') {
$args['menu'] = $form_state['values']['menu'];
}
$form_state['redirect'] = array(
'path' => $_GET['q'],
'options' => array(
'query' => $args,
),
);
if (isset($form_state['clicked_button']['#value']) && $form_state['clicked_button']['#name'] == 'op-submit') {
$this
->overviewFormOperationSubmit($form, $form_state);
}
}
/**
* Process CacheflushUIController::overviewForm form submissions.
*
* Executes the chosen 'Update Option' on the selected presets.
*/
public function overviewFormOperationSubmit($form, &$form_state) {
$operations = module_invoke_all('cacheflush_ui_operations');
$operation = $operations[$form_state['values']['operation']];
// Filter out unchecked presets.
$presets = array_filter($form_state['values']['presets']);
if ($function = $operation['callback']) {
// Add in callback arguments if present.
if (isset($operation['callback arguments'])) {
$args = array_merge(array(
$presets,
), $operation['callback arguments']);
}
else {
$args = array(
$presets,
);
}
call_user_func_array($function, $args);
cache_clear_all();
}
else {
// We need to rebuild the form to go to a second step. For example, to
// show the confirmation form for the deletion of presets.
$form_state['rebuild'] = TRUE;
}
node_types_rebuild();
menu_rebuild();
}
/**
* Overrides EntityDefaultUIController::overviewTable().
*/
public function overviewTable($conditions = array()) {
$header = array(
array(
'data' => t('ID'),
'field' => 'id',
'sort' => 'DESC',
),
array(
'data' => t('Title'),
'field' => 'c.title',
),
array(
'data' => t('Author'),
'field' => 'c.uid',
),
array(
'data' => t('Status'),
'field' => 'c.status',
),
array(
'data' => t('Menu entry'),
'field' => 'c.menu',
),
array(
'data' => t('Created'),
'field' => 'c.created',
),
array(
'data' => t('Operations'),
),
);
$view_any = user_access('cacheflush view any');
$query = db_select('cacheflush', 'c')
->extend('TableSort')
->orderByHeader($header)
->fields('c', array(
'id',
));
if ($this->overviewPagerLimit) {
$query
->extend('PagerDefault')
->limit($this->overviewPagerLimit);
}
if (isset($conditions)) {
foreach ($conditions as $field => $value) {
$query
->condition('c.' . $field, $value['value'], $value['op']);
}
}
if (!$view_any) {
$query
->condition('c.uid', $GLOBALS['user']->uid, '=');
}
$ids = $query
->execute()
->fetchCol();
$rows = array();
$presets = cacheflush_load_multiple($ids);
foreach ($presets as $preset) {
$row = $operations = array();
$user = user_load($preset->uid);
$row[] = $preset->id;
$row[] = $preset->title;
$row[] = theme('username', array(
'account' => $user,
));
$row[] = $preset->status == 1 ? t('enabled') : t('disabled');
$row[] = $preset->menu == 1 ? t('Yes') : t('No');
$row[] = format_date($preset->created, 'short');
if (cacheflush_ui_access('update', $preset)) {
$operations['update'] = array(
'title' => t('Edit'),
'href' => 'cacheflush/' . $preset->id . '/edit',
'query' => drupal_get_destination(),
);
}
if (cacheflush_ui_access('delete', $preset)) {
$operations['delete'] = array(
'title' => t('Delete'),
'href' => 'cacheflush/' . $preset->id . '/delete',
'query' => drupal_get_destination(),
);
}
$row[] = array(
'data' => array(
'#theme' => 'links__node_operations',
'#links' => $operations,
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
),
);
$rows[$preset->id] = $row;
}
$render = array(
'#type' => 'tableselect',
'#options' => $rows,
'#header' => $header,
'#multiple' => TRUE,
'#empty' => t('No presets available.'),
);
return $render;
}
}