Bring _views_create_handler() and _views_create_plugin() closer together.

8.0.x
Tim Plunkett 2012-07-30 20:40:06 -04:00
parent 3b2195d996
commit 64002e8743
2 changed files with 14 additions and 25 deletions

View File

@ -13,50 +13,39 @@ use Drupal\views\Plugin\Type\ViewsPluginManager;
/** /**
* Instantiate and construct a new plugin. * Instantiate and construct a new plugin.
*
* @todo
* Figure out what to keep from _views_create_handler.
*/ */
function _views_create_plugin($type, $plugin_id, $definition) { function _views_create_plugin($type, $definition) {
$manager = new ViewsPluginManager($type); $manager = new ViewsPluginManager($type);
$instance = $manager->createInstance($definition['plugin_id']);
$instance = $manager->createInstance($plugin_id);
$instance->is_plugin = TRUE; $instance->is_plugin = TRUE;
$instance->plugin_type = $type; $instance->plugin_type = $type;
$instance->plugin_name = $plugin_id; $instance->plugin_name = $definition['plugin_id'];
$instance->set_definition($definition); $instance->set_definition($definition);
// Let the handler have something like a constructor. // Let the handler have something like a constructor.
$instance->construct(); $instance->construct();
return $instance; return $instance;
} }
/** /**
* Instantiate and construct a new handler * Instantiate and construct a new handler
*/ */
function _views_create_handler($definition, $type = 'handler', $handler_type = NULL) { function _views_create_handler($type, $definition) {
if (!empty($definition['plugin_id'])) { $manager = new ViewsPluginManager($type);
$manager = new ViewsPluginManager($handler_type); $instance = $manager->createInstance($definition['plugin_id']);
$handler = $manager->createInstance($definition['plugin_id']);
}
else {
// @todo: remove this else, once all instances got converted.
$handler = new $definition['handler']($definition, $definition['handler']);
}
$handler->set_definition($definition); $instance->is_handler = TRUE;
$instance->handler_type = $type;
$handler->is_handler = TRUE; $instance->set_definition($definition);
$handler->handler_type = $handler_type;
// let the handler have something like a constructor. // let the handler have something like a constructor.
$handler->construct(); $instance->construct();
return $handler; return $instance;
} }
/** /**
@ -76,7 +65,7 @@ function _views_prepare_handler($definition, $data, $field, $type) {
} }
} }
return _views_create_handler($definition, 'handler', $type); return _views_create_handler($type, $definition);
} }
/** /**

View File

@ -1290,7 +1290,7 @@ function views_get_handler($table, $field, $key, $override = NULL) {
'table' => $table, 'table' => $table,
'field' => $field, 'field' => $field,
); );
return _views_create_handler($broken, 'handler', $key); return _views_create_handler($key, $broken);
} }
/** /**
@ -1369,7 +1369,7 @@ function views_get_plugin($type, $plugin_id, $reset = FALSE) {
$manager = new ViewsPluginManager($type); $manager = new ViewsPluginManager($type);
$definition = $manager->getDefinition($plugin_id); $definition = $manager->getDefinition($plugin_id);
if (!empty($definition)) { if (!empty($definition)) {
return _views_create_plugin($type, $plugin_id, $definition); return _views_create_plugin($type, $definition);
} }
} }