diff --git a/includes/base.inc b/includes/base.inc index 2d2ceb5..e3f52c2 100644 --- a/includes/base.inc +++ b/includes/base.inc @@ -55,6 +55,16 @@ class views_object { function option_definition() { return array(); } /** + * Collect this handler's option definition and alter them, ready for use. + */ + function altered_option_definition() { + $definition = $this->option_definition(); + $type = !empty($this->is_plugin) ? 'plugin' : 'handler'; + drupal_alter("views_{$type}_option_definition", $definition, $this); + return $definition; + } + + /** * Views handlers use a special construct function so that we can more * easily construct them with variable arguments. */ @@ -74,7 +84,7 @@ class views_object { * feature that will likely disappear at some point. */ function set_default_options() { - $this->_set_option_defaults($this->options, $this->option_definition()); + $this->_set_option_defaults($this->options, $this->altered_option_definition()); // Retained for complex defaults plus backward compatibility. $this->options($this->options); @@ -105,7 +115,7 @@ class views_object { } if (!isset($definition)) { - $definition = $this->option_definition(); + $definition = $this->altered_option_definition(); } if (!empty($this->view)) { @@ -202,7 +212,7 @@ class views_object { function export_options($indent, $prefix) { $output = ''; - foreach ($this->option_definition() as $option => $definition) { + foreach ($this->altered_option_definition() as $option => $definition) { $output .= $this->export_option($indent, $prefix, $this->options, $option, $definition, array()); } @@ -274,7 +284,7 @@ class views_object { * Unpacks each handler to store translatable texts. */ function unpack_translatables(&$translatable, $parents = array()) { - foreach ($this->option_definition() as $option => $definition) { + foreach ($this->altered_option_definition() as $option => $definition) { $this->unpack_translatable($translatable, $this->options, $option, $definition, $parents, array()); } } diff --git a/views.api.php b/views.api.php index edbb03f..b0ccff9 100644 --- a/views.api.php +++ b/views.api.php @@ -712,6 +712,50 @@ function hook_views_plugins_alter(&$plugins) { } /** + * Alter existing plugin option definitions. + * + * This can be used to edit default or add new option definitions to existing + * plugins. The reason for doing this is that only overriding the relevent form + * with hook_form_alter() is insufficent because submitted form values will be + * removed if they haven't been declared as an available option. + * + * An alternative approach you could also take is to extend each plugin + * individually. However if your goal is to override many, or even all plugins, + * this results in a lot of additional code and files. This makes it a lot more + * troublesome to maintain the codebase, as well as interoperability with other + * modules. + * + * @see views_plugin_argument_default::option_definition() + * @see hook_views_handler_option_definition_alter() + * @see hook_form_alter() + */ +function hook_views_plugin_option_definition_alter(&$options, $plugin) { + $options['option_name'] = array('default' => ''); +} + +/** + * Alter existing handler option definitions. + * + * This can be used to edit default or add new option definitions to existing + * handers. The reason for doing this is that only overriding the relevent form + * with hook_form_alter() is insufficent because submitted form values will be + * removed if they haven't been declared as an available option. + * + * An alternative approach you could also take is to extend each handler + * individually. However if your goal is to override many, or even all handlers, + * this results in a lot of additional code and files. This makes it a lot more + * troublesome to maintain the codebase, as well as interoperability with other + * modules. + * + * @see views_handler::option_definition() + * @see hook_views_plugin_option_definition_alter() + * @see hook_form_alter() + */ +function hook_views_handler_option_definition_alter(&$options, $handler) { + $options['option_name'] = array('default' => ''); +} + +/** * Register View API information. * * This is required for your module to have its include files loaded; for