Commit be8fab2f authored by dawehner's avatar dawehner Committed by tim.plunkett

try to make basic plugins possible

parent 2f42adf4
...@@ -379,8 +379,11 @@ function views_ui_add_form($form, &$form_state) { ...@@ -379,8 +379,11 @@ function views_ui_add_form($form, &$form_state) {
// Build the rest of the form based on the currently selected wizard plugin. // Build the rest of the form based on the currently selected wizard plugin.
$wizard_key = $show_form['wizard_key']['#default_value']; $wizard_key = $show_form['wizard_key']['#default_value'];
$get_instance = $wizard_plugins[$wizard_key]['get_instance'];
$wizard_instance = $get_instance($wizard_plugins[$wizard_key]); views_include_handlers();
$manager = new WizardManager();
$info = $manager->getDefinition($wizard_key);
$wizard_instance = $manager->createInstance($wizard_key, $info);
$form = $wizard_instance->build_form($form, $form_state); $form = $wizard_instance->build_form($form, $form_state);
$form['save'] = array( $form['save'] = array(
...@@ -702,9 +705,9 @@ function views_ui_nojs_submit($form, &$form_state) { ...@@ -702,9 +705,9 @@ function views_ui_nojs_submit($form, &$form_state) {
*/ */
function views_ui_wizard_form_validate($form, &$form_state) { function views_ui_wizard_form_validate($form, &$form_state) {
$wizard = views_ui_get_wizard($form_state['values']['show']['wizard_key']); $wizard = views_ui_get_wizard($form_state['values']['show']['wizard_key']);
$manager = new WizardManager();
$form_state['wizard'] = $wizard; $form_state['wizard'] = $wizard;
$get_instance = $wizard['get_instance']; $form_state['wizard_instance'] = $manager->createInstance($wizard['name']);
$form_state['wizard_instance'] = $get_instance($wizard);
$errors = $form_state['wizard_instance']->validate($form, $form_state); $errors = $form_state['wizard_instance']->validate($form, $form_state);
foreach ($errors as $name => $message) { foreach ($errors as $name => $message) {
form_set_error($name, $message); form_set_error($name, $message);
......
...@@ -10,6 +10,24 @@ ...@@ -10,6 +10,24 @@
use Drupal\views\Join; use Drupal\views\Join;
use Drupal\views\ViewsObject; use Drupal\views\ViewsObject;
/**
* Instantiate and construct a new plugin.
*
* @todo
* Figure out what to keep from _views_create_handler.
*/
function _views_create_plugin($type, $plugin_id, $definition) {
$manager = views_get_plugin_manager($type);
$instance = $manager->createInstance($plugin_id);
$instance->set_definition($definition);
// Let the handler have something like a constructor.
$instance->construct();
return $instance;
}
/** /**
* Instantiate and construct a new handler * Instantiate and construct a new handler
*/ */
......
...@@ -37,7 +37,11 @@ function __construct($hook, $plugin_type) { ...@@ -37,7 +37,11 @@ function __construct($hook, $plugin_type) {
* Implements Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinitions(). * Implements Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinitions().
*/ */
public function getDefinitions() { public function getDefinitions() {
$definitions = parent::getDefinitions(); views_include('plugins');
views_include_handlers();
$definitions = module_invoke_all($this->hook);
drupal_alter($this->hook, $definitions);
return $definitions[$this->viewsPluginType]; return $definitions[$this->viewsPluginType];
} }
} }
...@@ -9,12 +9,11 @@ ...@@ -9,12 +9,11 @@
use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Plugin\Discovery\HookDiscovery; use Drupal\views\Plugins\Discovery\WizardDiscovery;
use Drupal\Core\Plugin\MapClassLoader;
class WizardManager extends PluginManagerBase { class WizardManager extends PluginManagerBase {
public function __construct() { public function __construct() {
$this->discovery = new HookDiscovery('views_wizard'); $this->discovery = new WizardDiscovery('views_wizard');
$this->factory = new DefaultFactory($this->discovery); $this->factory = new DefaultFactory($this->discovery);
} }
} }
......
...@@ -273,7 +273,7 @@ protected function build_form_style(&$form, &$form_state, $type) { ...@@ -273,7 +273,7 @@ protected function build_form_style(&$form, &$form_state, $type) {
$style_form =& $form['displays'][$type]['options']['style']; $style_form =& $form['displays'][$type]['options']['style'];
$style = $style_form['style_plugin']['#default_value']; $style = $style_form['style_plugin']['#default_value'];
// @fixme // @fixme
return;
$style_plugin = views_get_plugin('style', $style); $style_plugin = views_get_plugin('style', $style);
if (isset($style_plugin) && $style_plugin->uses_row_plugin()) { if (isset($style_plugin) && $style_plugin->uses_row_plugin()) {
$options = $this->row_style_options($type); $options = $this->row_style_options($type);
......
...@@ -15,6 +15,16 @@ ...@@ -15,6 +15,16 @@
// @todo: Should views_get_plugin_manager be moved to a ceperate file? // @todo: Should views_get_plugin_manager be moved to a ceperate file?
use Drupal\views\Plugins\Type\StylePluginManager; use Drupal\views\Plugins\Type\StylePluginManager;
use Drupal\views\Plugins\Type\DisplayPluginManager;
use Drupal\views\Plugins\Type\AccessPluginManager;
use Drupal\views\Plugins\Type\ArgumentDefaultPluginManager;
use Drupal\views\Plugins\Type\ArgumentValidatorPluginManager;
use Drupal\views\Plugins\Type\CachePluginManager;
use Drupal\views\Plugins\Type\LocalizationPluginManager;
use Drupal\views\Plugins\Type\PagerPluginManager;
use Drupal\views\Plugins\Type\QueryPluginManager;
use Drupal\views\Plugins\Type\RowPluginManager;
use Drupal\views\Plugins\Type\ExposedFormPluginManager;
/** /**
* Advertise the current views api version * Advertise the current views api version
...@@ -1337,12 +1347,40 @@ function views_fetch_plugin_names($type, $key = NULL, $base = array()) { ...@@ -1337,12 +1347,40 @@ function views_fetch_plugin_names($type, $key = NULL, $base = array()) {
*/ */
function views_get_plugin($type, $plugin, $reset = FALSE) { function views_get_plugin($type, $plugin, $reset = FALSE) {
views_include('handlers'); views_include('handlers');
$definition = views_fetch_plugin_data($type, $plugin, $reset); $definition = views_fetch_plugin_data($type, $plugin, $reset);
if (!empty($definition)) { if (!empty($definition)) {
return _views_create_handler($definition, $type); return _views_create_plugin($type, $plugin, $definition);
} }
} }
/**
* Returns the plugin manager used for a certain plugin type.
*
* @param string $type
* The plugin type to use.
*
* @param PluginManagerInterface
*/
function views_get_plugin_manager($type) {
switch ($type) {
case 'style':
$manager = new StylePluginManager();
break;
case 'display':
$manager = new DisplayPluginManager();
break;
case 'localization':
$manager = new LocalizationPluginManager();
break;
case 'row':
$manager = new RowPluginManager();
break;
}
return $manager;
}
/** /**
* Load the current enabled localization plugin. * Load the current enabled localization plugin.
* *
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
use Drupal\views\View; use Drupal\views\View;
use Drupal\views\Plugins\Type\WizardManager;
/** /**
* Implements hook_menu(). * Implements hook_menu().
...@@ -550,7 +551,8 @@ function views_ui_ctools_plugin_directory($module, $plugin) { ...@@ -550,7 +551,8 @@ function views_ui_ctools_plugin_directory($module, $plugin) {
*/ */
function views_ui_get_wizard($wizard_type) { function views_ui_get_wizard($wizard_type) {
ctools_include('plugins'); ctools_include('plugins');
$wizard = ctools_get_plugins('views_ui', 'views_wizard', $wizard_type); $manager = new WizardManager();
$wizard = $manager->getDefinition($wizard_type);
// @todo - handle this via an alter hook instead. // @todo - handle this via an alter hook instead.
if (!$wizard) { if (!$wizard) {
// Must be a base table using the default wizard plugin. // Must be a base table using the default wizard plugin.
...@@ -576,7 +578,7 @@ function views_ui_get_wizard($wizard_type) { ...@@ -576,7 +578,7 @@ function views_ui_get_wizard($wizard_type) {
*/ */
function views_ui_get_wizards() { function views_ui_get_wizards() {
ctools_include('plugins'); ctools_include('plugins');
$wizard_plugins = ctools_get_plugins('views_ui', 'views_wizard'); $wizard_plugins = module_invoke_all('views_wizard');
$wizard_tables = array(); $wizard_tables = array();
foreach ($wizard_plugins as $name => $info) { foreach ($wizard_plugins as $name => $info) {
$wizard_tables[$info['base_table']] = TRUE; $wizard_tables[$info['base_table']] = TRUE;
...@@ -611,13 +613,6 @@ function views_ui_views_wizard_defaults() { ...@@ -611,13 +613,6 @@ function views_ui_views_wizard_defaults() {
// so they are documented. // so they are documented.
'title' => '', 'title' => '',
'base_table' => NULL, 'base_table' => NULL,
// This is a callback that takes the wizard as argument and returns
// an instantiazed Views UI form wizard object.
'get_instance' => 'views_ui_get_form_wizard_instance',
'form_wizard_class' => array(
'file' => 'views_ui_base_views_wizard',
'class' => 'ViewsUiBaseViewsWizard',
),
); );
} }
...@@ -628,22 +623,15 @@ function views_ui_ctools_plugin_type() { ...@@ -628,22 +623,15 @@ function views_ui_ctools_plugin_type() {
return array( return array(
'views_wizard' => array( 'views_wizard' => array(
'child plugins' => TRUE, 'child plugins' => TRUE,
'classes' => array(
'form_wizard_class',
),
'defaults' => views_ui_views_wizard_defaults(), 'defaults' => views_ui_views_wizard_defaults(),
), ),
); );
} }
function views_ui_get_form_wizard_instance($wizard) { function views_ui_get_form_wizard_instance($wizard) {
if (isset($wizard['form_wizard_class']['class'])) { $manager = new WizardManager();
$class = $wizard['form_wizard_class']['class']; $instance = $manager->createInstance($wizard['name']);
return new $class($wizard); return $instance;
}
else {
return new ViewsUiBaseViewsWizard($wizard);
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment