I've built a view with a date contextual filter (an "argument" in Views 2 parlance) that has a default value of "return date('Y-m');". Simple stuff. I can edit the view to see that the default value is still there and it works correctly. However, when I export it the default value is not retained, I just end up with the following:
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['default_argument_type'] = 'php';
$handler->display->display_options['arguments']['date_argument']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['summary_options']['grouping'] = 'field_event_date';
$handler->display->display_options['arguments']['date_argument']['year_range'] = '-3:+3';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'day';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
'field_data_field_event_date.field_event_date_value' => 'field_data_field_event_date.field_event_date_value',
'field_data_field_event_date.field_event_date_value2' => 'field_data_field_event_date.field_event_date_value2',
);
$handler->display->display_options['arguments']['date_argument']['date_method'] = 'OR';
$handler->display->display_options['arguments']['date_argument']['date_group'] = 'date';
You'll notice that 'default_argument_options' is missing.
I was looking through the code and at a guess it looks like either the option_definitions() for 'default_argument_type' should have a custom implementation to automatically include the 'default_argument_options' value, or 'default_argument_options' should have an export setting assigned. I.e., I think it should be either something like this:
function option_definition() {
$options = parent::option_definition();
[...]
$options['default_argument_type'] = array('default' => 'fixed', 'export' => 'export_argument');
$options['default_argument_options'] = array('default' => array(), 'export' => FALSE);
or
function option_definition() {
$options = parent::option_definition();
[...]
$options['default_argument_type'] = array('default' => 'fixed', 'export' => 'export_plugin');
$options['default_argument_options'] = array('default' => array(), 'export' => 'export_plugin');
Comment | File | Size | Author |
---|---|---|---|
#22 | 1202248-date_views_default_arg_options-22.patch | 884 bytes | mikehues |
#16 | date-views-default-arg-options-1202248-16.patch | 846 bytes | james.williams |
#15 | date-views-default-arg-options-1202248-15.patch | 2.54 KB | james.williams |
#2 | export.txt | 4.6 KB | dawehner |
Comments
Comment #1
DamienMcKennaFYI when I changed line 170 of views_handler_argument.inc to:
it outputs the following:
Clearly a custom exporter is needed.
Comment #2
dawehnerAnd there is a custom exporter, it's in handlers/views_handler_argument.inc::export_plugin
Sadly it works for me at the moment, see attachment.
Additional the option definition looks perfect as it is.
Can you give some introductions how to reproduce the problem?
If there is a bug the bug is probably in export_plugin.
Comment #3
DamienMcKenna@dereine: Thanks for testing it. The specific argument field I was working with used the Date module (latest 7.x-2.x-dev codebase) and it does not export the 'default_argument_options' setting.
Comment #4
dawehnerThat's a bug in date
It should do
all the time.
Comment #5
KarenS CreditAttribution: KarenS commentedHey @dereine, *where* exactly should this go? I was totally confused about how Views is handling exports.
Comment #6
muriqui CreditAttribution: muriqui commentedsubscribe
Comment #7
dawehnerThis is fixed already, because 'default_argument_type' was removed.
Comment #8
KarenS CreditAttribution: KarenS commentedDereine, I still have no idea what you are trying to tell me to do.
Comment #9
dawehnerSorry for all this confusion.
This was the old code, afaik.
Based on this it didn't exported default arguments right, but it's fixed already in the current date code. So this issue is fixed.
Comment #10
KarenS CreditAttribution: KarenS commentedI ended up removing all my manual attempts to get export items to display right because Views now seems to pick them up correctly.
Comment #12
Simon Georges CreditAttribution: Simon Georges commentedHi. I'm currently using Calendar, and have modified the Views arguments to use a PHP-based default value (which works perfectly), but the PHP code isn't exported with the View (there is indeed no 'default_argument_options' line in the export).
I currently have Views-3.0-rc3 (released November 16, 2011) and Date-7.x-2.0-alpha5 (released November 29, 2011), both released after this thread was closed, but it seems the bug is still happening...
May I help you investigate in any way ? (I'm willing to provide exports, tests Views modification / code modification if needed).
Comment #13
tim.plunkettThat should have been fixed in September 2011. #1273806: Non-plugin default argument types are not exported
If it persists, please open a Views issue with a paste of your views export.
Comment #14
grendzy CreditAttribution: grendzy commentedI can still reproduce it with a fresh install of the latest dev releases. As requested a new issue is here: #1515764: Exported view missing default_argument_options with date argument and PHP code
Comment #15
james.williams CreditAttribution: james.williams commentedI believe the problem has arisen because date overrides the 'default_argument_type' option definition, which is not yet fixed. The attached patch fixes this, making 'date' the default, but keeping the 'export' => 'export_plugin' part. This makes the plugin then do the exporting of the default_argument_type (in
views_handler_argument_date::export_plugin()
), which itself exports the default_argument_options.Comment #16
james.williams CreditAttribution: james.williams commentedshoot, sorry that patch was against an old version -- here's a rerolled one.
Comment #17
awolfey CreditAttribution: awolfey commentedThe patch in #16 fixed my issue. Thanks James!
In my case the the default argument type (raw) had been exporting, but not the url index. With this patch it now exports correctly.
Comment #18
kbasarab CreditAttribution: kbasarab commented#16 works for me as well.
Comment #19
pdcarto CreditAttribution: pdcarto commented#16 works. This patch should be committed and this ticket closed.
Comment #20
grendzy CreditAttribution: grendzy commented#16 worked for me also.
Comment #21
michielnugter CreditAttribution: michielnugter commentedI can also confirm the posted patch in #16 works. I had a problem with some options not being exported for a date argument and after applying the patch they are exported as they should be.
Comment #22
mikehues CreditAttribution: mikehues commentedEDIT: Nevermind. patch #16 works
I'm seeing this issue with current dev versions date-7.x-2.x-dev and views-7.x-3.x-dev on a clean install of Drupal 7.21.
Reproduce issue:
Install date, views and ctools and enable date, views and views_ui. Do not enable date_views yet. Add a date field to the Page content type, create a view and add the date field as a contextual filter. At this point if you save and export your view, the export will contain the following:
Now enable date_views and re-export your view. You will see that the 'default_argument_options' are missing from the export. The same issue occurs if you remove your "Content" argument and replace it with the newly available "Date" argument for your field in contextual filters.
Proposed solution:
Taking a closer look at the code I noticed that when the date_views module is disabled, the option definition array contains the following on line 193 of views_handler_argument.inc:
$options['default_argument_type'] = array('default' => 'fixed', 'export' => 'export_plugin');
And when date_views is enabled, the default_argument_options value is overridden with:
options['default_argument_type'] = array('default' => 'date');
Updating line 88 of date_views_argument_handler_simple.inc to the following resolves the issue for me:
options['default_argument_type'] = array('default' => 'date', 'export' => 'export_plugin');
EDIT: Nevermind. patch #16 works
Comment #23
dawehnerI still think #16 is a bit cleaner.
Comment #24
mikehues CreditAttribution: mikehues commented@dawehner you are absolutely right. Not sure what I did the first time around, but I must have missed something. I started fresh again and re-applied patch #16. It did in fact solve the issue. Changing the status back to 'reviewed & tested by the community'. Sorry about that :\
Comment #25
heddn+1 on #16. Fixes the problem for me as well.
Comment #26
corbacho CreditAttribution: corbacho commentedThis bug bit me too. It wasn't easy to debug.
#16 works well. It's just 1 line diff, please commit it
Comment #27
caktux CreditAttribution: caktux commentedI concur, please commit and close this issue
Comment #28
awolfey CreditAttribution: awolfey commentedHoping for a commit. Thanks!
Comment #29
cafuego CreditAttribution: cafuego commentedPatch from #16 applied to 7.x-2.x.