Fetch a handler from the data cache.
$table: The name of the table this handler is from.
$field: The name of the field this handler is from.
$type: The type of handler. i.e, sort, field, argument, filter, relationship
$override: Override the actual handler object with this class. 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($table, $field, $type, $override = NULL) {
// Get the plugin manager for this type.
$manager = drupal_container()
->get("plugin.manager.views.{$type}");
$data = views_fetch_data($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.
}
}
}
// Finally, use the 'broken' handler.
debug(t("Missing handler: @table @field @type", array(
'@table' => $table,
'@field' => $field,
'@type' => $type,
)));
return $manager
->createInstance('broken');
}