function views_get_handler in Views (for Drupal 7) 8.3
Same name and namespace in other branches
- 6.3 views.module \views_get_handler()
- 6.2 views.module \views_get_handler()
- 7.3 views.module \views_get_handler()
Fetch a handler from the data cache.
Parameters
$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.
Return value
views_handler An instance of a handler object. May be views_handler_broken.
15 calls to views_get_handler()
- DisplayPluginBase::getHandlers in lib/
Drupal/ views/ Plugin/ views/ display/ DisplayPluginBase.php - Get a full array of handlers for $type. This caches them.
- GroupByNumeric::init in lib/
Drupal/ views/ Plugin/ views/ sort/ GroupByNumeric.php - Init the handler with necessary data.
- HandlerAllTest::testHandlers in lib/
Drupal/ views/ Tests/ Handler/ HandlerAllTest.php - Tests most of the handlers.
- HandlerTest::testBreakPhrase in lib/
Drupal/ views/ Tests/ Handler/ HandlerTest.php - Tests Drupal\views\Plugin\views\HandlerBase::breakPhrase() function.
- HandlerTest::testBreakPhraseString in lib/
Drupal/ views/ Tests/ Handler/ HandlerTest.php - Tests the breakPhraseString() method.
File
- ./
views.module, line 1283 - Primarily Drupal hooks and global API functions to manipulate views.
Code
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');
}