Fetch a handler from the data cache.
array $item: An associative array representing the handler to be retrieved:
string $type: The type of handler. i.e, sort, field, argument, filter, relationship
string|null $override: (optional) Override the actual handler object with this plugin ID. Used for aggregation when the handler is redirected to the aggregation handler.
views_handler An instance of a handler object. May be views_handler_broken.
function views_get_handler($item, $type, $override = NULL) {
$table = $item['table'];
$field = $item['field'];
$optional = isset($item['optional']) ? $item['optional'] : FALSE;
// Get the plugin manager for this type.
$manager = Views::pluginManager($type);
$data = Views::viewsData()
->get($table);
if (isset($data[$field][$type])) {
$definition = $data[$field][$type];
foreach (array(
'group',
'title',
'title short',
'help',
'real field',
'real table',
) as $key) {
if (!isset($definition[$key])) {
// First check the field level
if (!empty($data[$field][$key])) {
$definition[$key] = $data[$field][$key];
}
elseif (!empty($data['table'][$key])) {
$definition[$key] = $data['table'][$key];
}
}
}
// @todo This is crazy. Find a way to remove the override functionality.
$plugin_id = $override ?: $definition['id'];
// Try to use the overridden handler.
try {
return $manager
->createInstance($plugin_id, $definition);
} catch (PluginException $e) {
// If that fails, use the original handler.
try {
return $manager
->createInstance($definition['id'], $definition);
} catch (PluginException $e) {
// Deliberately empty, this case is handled generically below.
}
}
}
if (!$optional) {
//debug(t("Missing handler: @table @field @type", array('@table' => $table, '@field' => $field, '@type' => $type)));
}
// Finally, use the 'broken' handler.
return $manager
->createInstance('broken');
}