function data_get_views_handler_options in Data 8
Same name and namespace in other branches
- 6 data.views.inc \data_get_views_handler_options()
- 7 data.views.inc \data_get_views_handler_options()
Return all available field handlers.
Parameters
$type: Optional: the view handler type whose options should be provided ('field', 'filter', 'sort', 'argument'). If omitted, a full array keyed on type is returned.
$reset: Boolean to reset the static cache.
Return value
An array suitable for use as options in a FormAPI element.
File
- ./
data.views.inc, line 54 - Views hooks and utility functions.
Code
function data_get_views_handler_options($type = NULL, $reset = FALSE) {
static $handlers;
if (!isset($handlers) || $reset) {
$handlers = array();
module_load_include('inc', 'views', 'includes/base');
module_load_include('inc', 'views', 'includes/handlers');
module_load_include('inc', 'views', 'includes/cache');
// The types of handler we are interested in.
// If we wanted everything, we'd get it from view::display_objects().
$handler_types = array(
'field',
'filter',
'argument',
'sort',
'relationship',
);
// Get all of Views' data, wherein every field defines its handler.
$views_data = _views_fetch_data();
$handlers = array_fill_keys($handler_types, array());
foreach ($views_data as $table => $table_definition) {
foreach ($table_definition as $field => $field_definition) {
// Skip the table definition itself.
if ($field == 'table') {
continue;
}
foreach ($handler_types as $handler_type) {
if (isset($field_definition[$handler_type]['handler'])) {
$handler = $field_definition[$handler_type]['handler'];
$handlers[$handler_type][$handler] = $handler;
$current_handler = $handler;
// Work up the class's parentage, as there are many handler classes
// not actually used by any views data fields.
$finished = FALSE;
while (!$finished) {
// Try to find the parent class name of the current Views handler.
$parent_handler = get_parent_class($current_handler);
switch ($parent_handler) {
case FALSE:
// Could not auto-load and/or find the parent handler in this scope.
watchdog('data', 'Unable to detect class ancestry of Views handler %handler for %field_name.', array(
'%handler' => $current_handler,
'%field_name' => $table . '.' . $field,
));
// Fall through to finish climbing this class hierarchy.
case 'views_handler':
// Reached the root views_handler class or cannot continue up the
// class hierarchy.
$finished = TRUE;
break;
default:
// Add the class. This is going to be redundant in many cases
// as we'll have either already done this or be about to find
// it in the data, but this function is only called on an admin
// page so performance is not an issue.
$handlers[$handler_type][$parent_handler] = $current_handler = $parent_handler;
break;
}
}
}
}
}
}
// Allow other modules to alter the list of available handlers.
drupal_alter('data_views_handlers', $handlers);
// Sort the final arrays.
foreach ($handlers as $handler_type => &$data) {
ksort($data);
}
}
return isset($type) && isset($handlers[$type]) ? $handlers[$type] : $handlers;
}