Problem/Motivation
Some argument handlers provide their own default argument handling, like the Date argument. The Date argument handler does so by extending the list of of options in the defaultArgumentForm. An exception is however thrown on saving the form.
Steps to reproduce
- Create a new view
/admin/structure/views/addusing (node) content - Under advanced tab, add new Contextual filter, select Created date (
node.created) - On "When the filter value is not available", select "Provide default value", on the drop-down select "Current date".
- Try to submit this form.
Result: A fatal error occurred on dblog: Drupal\Component\Plugin\Exception\PluginNotFoundException: The "date" plugin does not exist.
Proposed resolution
Get the date handlers in line with the other default argument handlers.
Add a 'Current date', a "Current node's creation time" and "Current node's update time" default argument handler.
Remaining tasks
Add a follow-up for improving caching - see #114#3555138: Default date argument handlers: correct cacheability (contexts, tags, max-age)Add a follow-up to make this work for all entity-types using a deriver - see #176#3555139: Generalize "Current entity created/updated time" via plugin deriver (all entity types)Confirm if this works with date time range fields - see #157
User interface changes
API changes
Data model changes
Release notes snippet
Problem
Steps to reproduce:
Proposed resolution
| Comment | File | Size | Author |
|---|---|---|---|
| #213 | 2325899-212.patch | 30.03 KB | percoction |
| #210 | 2325899-210.patch | 30.02 KB | idflood |
| #208 | 2325899-10.2.5-184.patch | 28.23 KB | foodslover |
| #204 | 2325899-nr-bot.txt | 90 bytes | needs-review-queue-bot |
Issue fork drupal-2325899
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
casey commentedComment #2
casey commentedComment #3
dawehnerOh right!
I guess we need a test to ensure that at least the date argument handler works as expected. An thrown exception isn't that nice.
Comment #4
dawehner.
Comment #5
lendudeTook a look at the fix and the code and I'd like to propose to take this in another direction.
Instead of just skipping past miss configuration, why not just provide the date default_argument_handler?
I can see a case for only providing the 'current date' default argument handler for date fields, but no such restraints are in place for the other default argument handlers, so why make an exception for date? (it's not like providing the current user id to a date field makes sense, but it's possible at the moment).
So I would propose to just get date in line with the other default argument handlers. With some changes to the current setup:
- lose support for "Current node's creation time"
- lose support for "Current node's update time"
no idea why those should have support in core, and if we do want them in core, let's give them proper default argument handlers and tests and such (but i'd say just toss them out)
This probably needs more work but let me know if this would be a good direction to take this.
Comment #7
dawehner@Lendude
It is great to see your engagement in views!
Right, you understood why we had this odd code. In an additional issue we could think about a type for argument plugins similar as we have
for display plugins, to limit it.
PS: We have a test.
Let's fix the 'deafult' typo here :)
Comment #8
lendude@dawehner, learning a ton by diving into views, great fun! Thanks for all the reviewing and great feedback.
fixed typo, added a description to the 'date format' field with a link to php.net
Comment #9
benjy commentedThis patch only had cosmetic changes since @dawehner RTBC'd in #7.
Comment #11
lendudeLangcode settings needed to go. Rerolled.
Comment #12
jhedstromPatch still applies, and as #9 notes, this only has cosmetic changes and rerolls since RTBC in #7.
I added a beta phase evaluation to the issue summary.
I also bumped this to major since a fatal error through the UI seems major.
Comment #15
lendudeRerolled, needed to account for #2429447: Use data table as views base table, if available., so base table of the test view changed to node_field_data.
Thanks for adding the beta evaluation.
Comment #16
jhedstromBack to RTBC assuming bot goes green.
Comment #17
lendudeUpdated issue summary to reflect the new proposed solution.
Comment #18
alexpottSo we're removing functionality here that people might be using - are we sure that we want to do that?
Comment #19
lendudeAdding default argument handlers for "Current node's creation time" and "Current node's update time" to core doesn't make a lot of sense to me, these are not things you want to be showing for every view (even those not showing nodes at all), and are they really 'core' functionality? (not in my mind, these sounds like fringe cases, and if nodes get dedicated handlers, why not users and other entities?).
So to justify keeping the functionality, I'd say we'd need what @dawehner suggested in #7, some way to limit the default argument handlers shown. But until that exists, I'd feel that getting the 'Current date' working is more important then supporting "Current node's creation time" and "Current node's update time" in core.
So, what to do?
- Toss "Current node's creation time" and "Current node's update time" from core and move them to some contrib module
- Support "Current node's creation time" and "Current node's update time" in core as default argument handlers (probably in the node module?).
- Develop some way to limit the default argument handlers shown and keep supporting "Current node's creation time" and "Current node's update time" in core
- Develop some way to limit the default argument handlers shown and toss supporting "Current node's creation time" and "Current node's update time" from core anyway
I'd be for option 4, but curious what others think.
Comment #20
slashrsm commentedI found this bug when working on a project. #15 fixed problem for me as I was using "date" default argument.
However, I understand concerns @alexpott had in #18 and agree that we should keep existing features in. Based on that I'd suggest keep "Current node's update time" and "Current node's creation time" and add limit functionality in a follow-up. That would be option 3 in #19 I believe.
Comment #21
webflo commentedStraight reroll
Comment #22
lendudeKickin' the testbot into gear. This still needs work, but lets see if it passes.
Comment #23
lendudeThis patch adds the handlers for "Current node's update time" and "Current node's creation time". Tested manually but need some real tests, but don't feel like doing that right now.
lets see what this does.
Comment #24
lendudeClean up of #23, "Current node's update time" and "Current node's creation time" handlers are blatant copies of the "current node id" handler. Was looking at using the tests for node->id handler as a base for the two date handlers but alas:
So that is gonna take a little more effort then copy/paste.
Comment #25
geertvd commentedWe have some test coverage for this in #2567773: Can't select "current date" as default option in a date contextual filter, I'm going to move that here.
Comment #26
geertvd commentedAh seems like test coverage for the "date" argument default handler is already ok in this patch.
I'll add some more for "node_changed" and "node_created" and create a follow up for the todo mentioned in #24
Comment #27
geertvd commentedHow are the argument defaults that fetch something from a current node (like node_created, node_changed and node) actually supposed to work?
What's the current node? When I add the node id in the path it's being seen as the argument value, so my argument_default never gets called.
Even worse, when I use the node_created argument, I'm getting an error saying
Exception: The timestamp must be numeric. in Drupal\Component\Datetime\DateTimePlus::createFromTimestamp() (line 165 of /var/www/html/core/lib/Drupal/Component/Datetime/DateTimePlus.php).That's should probably be a different issue though.
I added the view I'm testing with in case my explanation doesn't make much sense. Maybe I'm just seeing this all wrong.
Comment #28
lendudeMy manual test case was adding a block display, and showing that block next to a node and showing all nodes that were created on the same date as the node you are watching.
The whole node_created and node_changed feel like such fringe use cases, that's why I argued in #5 to just toss them from core. But @alexpott in #18 seemed to mean that we shouldn't be removing functionality from core anymore (and I see his point).
Comment #29
geertvd commentedYea I figured a block display was the only use case. That makes it pretty annoying to test. Will take a stab at that later today.
Comment #30
hauruck commentedRe-roll: After updating to RC1 with this patch and running DB update we got the following error from system.install system_update_8004:
Failed: Drupal\Component\Plugin\Exception\PluginNotFoundException: The "date" plugin does not exist. in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 57 of /var/www/zeitraumexit/src/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).
Solution: Since the class CacheablePluginInterface no longer exists it has been replaced with CacheableDependencyInterface.
Comment #31
lendudethanks for the reroll! Let's kick the testbot into gear.
Comment #33
clemens.tolboomI get this on a 'Created week' with 'provide default value' as 'Current date'. Guess that's the same.
What about Comment, Term and User with 'Current date' as I get the same error there on http://drupal.d8/admin/structure/views/ajax/handler/comment/default/argu...
Comment #34
mpdonadioThis should probably use the date.formatter service instead of the native date function? Also elsewhere in the patch.
Bad ordering. Should be alphabetical.
This doesn't make a lot of sense. The argument plugins that use this will define the format that they need, which you can get with the getFormula() method.
Relying on the request date means this isn't properly cacheable.
This is weird inheritance, and I think you could say it violates SOLID.
Technically, this would introduce a BC break if these handlers existed, and would require a upgrade path. I also think this would be a regression from Drupal 7.
This somewhat of a partial review as I don't think the approach is quite right.
Comment #35
mpdonadioI hope #34 didn't come off as being negative. The patch is good, but at this point the changes to argument/Date.php are a bit radical.
I'm going to work on my objections :)
Comment #36
mpdonadioStill needs test coverage for the node create and changed plugins. This is going to fail. Not sure how/why the NullArgument handler is being used here? Manual testing seems fine.
Comment #38
mpdonadioSee what is gong on now. Working on this.
Comment #39
mpdonadioI think this will come up green, but it still needs some test coverage.
- the current date through the date argument plugins works when I do manual testing, but this should have proper test coverage
- the node creation/updated defaults need tests through both paths
I also looked at the exported config a lot, and I think that removing the defaultArgumentForm() is OK and not a BC break nor a regression from Drupal 7. So, we have kinda looped back back to #30, but w/o the settings form + some stuff that I identified. I attached that interdiff for reference.
Feedback appreciated.
Comment #40
lendudeNo time right now for a proper code review, but on first glance it looks a lot better then it was. I agree that removing the defaultArgumentForm is not a regression from D7, this is how it works in D7 too as far as I can tell. So this looks like the right path to take for minimal/no migration impact.
I feel an update of the issue summary is needed to make clear that we are not really removing functionality (the ability to provide own default handlers), just getting date default argument handlers in line with the plugin system. But can't think of the proper wording right now....
Back to 'needs work' for the tests.
Comment #41
lendudetests for the 'current node X time' default argument handlers.
Comment #42
mpdonadioThe new tests look good. I'm a little confused by my own comment, though, from a few months ago:
Do you think the testing is ArgumentDefaultTest::testArgumentDefaultDate() is adequate? Also
These tests need to be added back in, and these changes aren't in the interdiff?
Comment #43
lendude@mpdonadio thanks for looking at it!
#42.1-5 sorry, found that I left those in, changed it, rerolled the interdiff and then promptly uploaded the old version of the patch....
The test coverage in ArgumentDefaultTest::testArgumentDefaultDate() matches that of the other default arguments handlers, so I think it should be fine. But since ArgumentDefaultTest is a webtest already anyway extending the tests to do a drupalGet en see if the actual filtering works should be fairly trivial should we feel the need.
Comment #46
lendudeduh, .patch interdiff
Comment #47
twistor commentedRe-roll.
Comment #48
dawehnerIMHO we should implement this not just for nodes but for every entity with
EntityChangedInterfaceComment #49
dawehnerComment #50
lendude@dawehner you are pointing to the 'Current node changed time' default argument handler, so do you mean make a default argument handler for 'Current comment changed time' and 'Current user changed time'? I don't really see a use case for the node version (we just added those from a BC standpoint), let alone for the other entities. That would just clutter up the default argument selector more.
Or do you mean something else?
Comment #52
owenbush commentedRe-rolled the patch from #47 for Drupal 8.1.x
Comment #53
mpdonadioGo testbot, go.
Comment #54
howards commentedmanual reroll to 8.2.x
Comment #56
howards commentedOops!
EDIT: The patches in #54 and here were a manual reroll of the patch in #52 as it would no longer apply to 8.1.x, including back when it was tested. (Applied against various commits around June 21, 2016 and failed in two different hunks.)
Patched against 8.1.x-dev (commit a734cfae, "back to -dev" after release of Drupal 8.1.9)
Patched against 8.2.x-dev (commit 0e65dfa4)
EDIT #2: Nevermind, #52 patched with fuzz; I guess I grabbed the wrong one in testing... Ugh...
Comment #57
howards commentedComment #58
mpdonadioAssuming the additional tests I queued come up green, I think this is a good reroll. I have this question on a few issues, and still haven't gotten a definitive answer: we have a schema addition, so do we need an empty hook_update_N() to force a rebuild so it gets read in?
Comment #59
howards commentedI don't know enough to say whether or not hook_update_N() applies. However, I can try to provide additional information based on whether things work without using
drush si -y. (I assume that's the threshold as to whether hook_update_N() is necessary.)I just installed 8.2.x @ 04953c5a and tried to reproduce the original issue. I was presented with the ability to create default arguments listed in the proposed resolution, but actually saving them wouldn't work. I could save with "fixed value" but I could not save (e.g. the Views contextual argument overlay window would not disappear after clicking "Apply") with current date, current node's creation time, or current node's update time.
Then I applied the patch:
And the options for current date, or node creation/update time disappeared.
Afterward, I reversed the patch and the current date and node creation/update options reappeared.
I highly doubt this answers the question of "do we need hook_update_N()" but might highlight another issue. Hmm... (I will do more research and attempt to figure out what's going on.
Comment #60
howards commentedI reinstalled 8.2.x @ 04953c5a with the patch applied prior to installation. (e.g. patch was applied and then
drush8 si -y standard --account-name='admin' --account-pass='admin'and everything seems to work. Again, I don't know enough about hook_update_N(), but it appears as though it's needed because the patch applied after Drupal has been installed has had unintentional effects. Installing Drupal with the patch previously applied gave a somewhat different order of default arguments:EDIT: I was able to save everything and have the Views overlay window disappear when adding a contextual argument.
EDIT 2: Do the previous two comments answer the question of whether or not hook_update_N() is necessary? I hope this is enough information to determine whether or not the update is necessary.
Comment #61
howards commentedIs there anything else I can do to test this issue and provide more information? Is it just writing an update_hook(), or as @mpdonadio put it, "an empty update_hook()"? (I will try, but will probably fail like 100 times before it works; I R TEH ID10T. Nobody wants 10,000 notifications of failure, let alone a dumbass who can't seem to get
core/scripts/run-tests.shto work correctly without a million failures.)I'm stupid, but I try... *smirk*
Comment #62
mradcliffeThank you for the screenshots and manual testing, howards! One thing that really helps the committers is to be able to see these manual test results in the issue summary.
The next step would be to ask in IRC (#drupal-contribute) regarding this issue and see if anyone there is able to answer @mpdonadio's question. Perhaps @dawehner could shed some light?
Comment #63
howards commentedUpdating issue summary with manual test results.
Comment #64
cilefen commented@timplunkett, @alexpott, @dawehner, @xjm and I discussed this in a triage session at DrupalCon Dublin. A fatal in the UI is major priority normally so we are keeping that status.
Comment #65
cilefen commentedComment #66
howards commentedIs there anything I can do to help the process?
Comment #67
mpdonadioBased on the manual tests, it sounds like we do need the empty update hook to force a cache clear to read the schema additions. Here is a quick patch. Manual testing process would be
- Install 8.2.x (has to be 8.2.x HEAD, update hook won't work otherwise)
- Apply patch
- Run and apply updates from update.php
- Test to see if everything works as expected
I did this quickly, but someone should recheck this methodically.
Comment #68
howards commentedI reinstalled from HEAD (56188d7f), added a date field to
articleand created a number of nodes with arbitrary dates (authored on and field_date) from yesterday, today, and tomorrow (local time). Afterward, I added a view and tried to add contextual argument, much to the same previous result. (Views contextual arguments would save/disappear with "fixed value" but not with current date, current node's creation time, or current node's update time.) I applied the patch and checked saving arguments again; similar disappearance as previously demonstrated.Then, I ran
/update.phpto run the empty views_update hook and again tried saving with expected results. I was able to save contextual arguments without issue. I was also able to test the Views output.For the tests, I set up multiple views with Block displays to see which nodes were returned. I set up nine blocks: one for each combination of "authored on", "changed", and an arbitrary field_date against each of "node created time, node changed time, and current date." I used block placement to display all of the blocks on all pages and started browsing through the previously created nodes to see which appeared in which blocks. The nodes appropriately displayed in each of the blocks according to which node was viewed. (e.g. nodes created on Sunday appeared with other nodes created on Sunday, nodes with field_date set to Tuesday appropriately appeared with other nodes' field_dates set to Tuesday. etc.)
Everything seemed to work as expected. It all appears to work well with the empty
hook_update()for having the schema reload. I will provide screenshots of methodical testing if necessary, but would take a bit of explanation as to which node is displayed and its expected Views results.Setting RTBC. Thanks for everything!
Comment #69
mpdonadioComment #70
alexpottAll of these methods are on the parent class therefore there is no API change here. Nice.
We're adding at least three new views plugins - do we have test coverage for everything?
Comment #71
lendude+++ b/core/modules/views/src/Tests/Plugin/ArgumentDefaultTest.php
@@ -125,6 +126,25 @@ public function testArgumentDefaultFixed() {
+ function testArgumentDefaultDate() {
tests the current date
tests both the current node plugins
we seem to be missing the two 'current node' schema here though.
Comment #72
lendudeoops, just overlooked them!
Comment #73
alexpottIs this logic tested for each plugin?
Comment #74
Anonymous (not verified) commentedSuper works, many thanks! It seems left quite little bit!
We can make a new logic in separate Feature request issue, if these tests are not enough?
Or maybe transfer logic by get $format to static method, and testing it? Example like DateHelper:
Comment #75
mattltThis commit…
https://www.drupal.org/commitlog/commit/2/6663917e5c3e2d614ae98777d80dae...
…uses the same update version in `views.install` .
Looks like the patch needs to be updated.
Thanks,
•• matt
Comment #76
mpdonadioThis no longer applies, and for conflicts outside the function below.
This should be changed to an empty hook_post_update_NAME(), since we are trying to avoid empty hook_update_N() in core just to trigger rebuilds.
Comment #77
jofitzRe-roll.
Comment #79
jofitzCorrected update hook number.
Comment #80
mpdonadioStill needs to be rerolled. From https://www.drupal.org/pift-ci-job/586765 / https://dispatcher.drupalci.org/job/drupal_patches/389/See the comment in #76. Instead of using a hook_update_N() in views.install, this should be changed to a post-update hook in views.post_update.php
Crosspost with #79, but the comment still applies. This should be a post update hook and not and update_N.
Comment #81
jofitzAlready done.
Comment #82
mpdonadioSee the comment near the end of #76. Instead of using a hook_update_N() in views.install, this should be changed to a post-update hook in views.post_update.php. We are really trying to avoid empty hook_update_N just to trigger rebuilds; instead we need to do them in post-update hooks.
Comment #83
jofitzSorry, my mistake, didn't read it properly. Thanks for your patience.
Comment #84
balagan commentedI have applied the patch, and it seems that the 'current node created time' uses Y-M-D, whereas I would think it should use timestamp, or a time including seconds.
Comment #86
lendudeFirst step to addressing @alexpotts feedback in #73, also some CS cleanup.
Comment #87
edysmpI have tested the "Current date" contextual filter successfully. Thanks
Comment #88
dagmarRerolled after:
Comment #90
dagmarPatch only applies to 8.4.x
Comment #91
pwolanin commentedpatch applies to 8.3.x with fuzz. Here as .txt
Comment #92
mpdonadioargument/Date implements ContainerFactoryPluginInterface
and then we remove the create method, which ContainerFactoryPluginInterface requires
I'm confused why this is working; I don't see where the create method is coming from now. I am also curious whether this is a BC break. Asking because this has potentially gotten entangled with #2627512: Datetime Views plugins don't support timezones, which was extending this class, and the two patches don't work with each other right now.
Not sure which patch has to do what.
?
Comment #93
pwolanin commentedThe very base plugin class also implements ContainerFactoryPluginInterface and the base form of create() so it doesn't actually need to be added here.
Assuming the other patch goes in first, I think the fix here will be easy.
Comment #94
mian3010 commentedRerolled to 8.2.7
Comment #96
mpdonadio#94, 8.2.7 is no longer supported, and 8.3.1 is coming out later today. This issue is currently against 8.4.x.
#88 is the patch that need to be reviewed. Just triggered retests.
Comment #97
sk33lz commented#88 no longer applies cleanly in 8.4.x. Changing to Needs Work.
Comment #98
Anonymous (not verified) commentedRerolled. This patch contains next changes:
ArgumentDefaultTest in new place (this is reason of
Patch Failed to Apply)Aye!)
And still tasks:
#73 with partial of test coverage in #86.
#92 looks like good point about BC break. Do we really need to delete the
create()here?#94: Thanks, @mian3010! This is really useful (especially two months ago) to solve the problem on 8.2.x sites, where these handlers are needed.
Comment #99
mian3010 commentedRe-rolled for 8.3.3 (in case anybody, like me, needs the patch on that version)
Comment #100
purushotam.rai commentedAbove patch was solving issue partially. While executing update 8300 of block_content, I was facing issue "Date" plugin not found. Combined #99 patch and #2567773: Can't select "current date" as default option in a date contextual filter resolved my issue.
Thanks
Comment #102
olofbokedal commentedI can't get the patch from #99 to work. Applied just fine, but the `Current date` default argument isn't available as an option for a regular date field. I tried to change the `default_argument_type` in the exported config file and imported the new config, but then I got the same error again: `The "date" plugin does not exist`.
I ran update.php, and also cleared the Views cache manually, but there's no difference.
Comment #103
tacituseu commented8.4.x is the target and #98 is still the one to review, at the very least add
-do-not-test.patchto those 'helpful' patches to not disturb the issue.Comment #104
Anonymous (not verified) commented#98 tasks:
#100: Thanks for the info. Perhaps this should be considered in more detail. But I have no experience with this.
#102: You are right. This occurs due to incorrect preparation date. Regular date field don't use getDateFormat() (and as result getDateField). This diff between 'created' and 'field_test2':
But the heroes from the #2627512: Datetime Views plugins don't support timezones seem to have already overcome this problem! After that patch all work and query looks like:
Comment #106
Anonymous (not verified) commentedChanges:
A small but important correction, so the idea of the tests in #73 was fair. And looks, it is done, but it needs to review.
Current patch does not include the #100, because I still do not have enough experience to do a review of this.
Comment #108
idflood commentedApplied patch in #106 with drupal-composer, ran update.php and it fixed the issue.
Comment #109
pifagor+1
Comment #110
lendudeI think this not getting cached is important enough to warrant a test. Just hit a page that uses this and making sure it's marked uncachable, something like that?
Comment #111
Anonymous (not verified) commented#100: Is it still relevant? It seems no one complained about it anymore. Especially since almost a year has passed, during this time there were many fixes. One of which could solve the problem.
#110: make sense, done!
Comment #112
rhache commented@vaplas This is issue is certainly not fixed. Yesterday I tried to do a contextual filter on the current date (for a date field) and it simply won't work.
Comment #113
Anonymous (not verified) commentedMy question to #100 was about error:
"Date" plugin not found.@purushotam.rai suggests adding an next check to fix it:
But I can not reproduce this problem, perhaps it has already been fixed. Test attached to the #100 passed with the current patch, too.
All other feedback was addressed.
@rhache, have you checked these filters after applying the patch (#106 or #111, it does not matter) and running the /update.php?
Comment #114
richgerdesI came across this issue in 8.5 and am able to reproduce this on a fresh install of 8.6.x-dev. The patch in #111 did successfully apply and solved the issue. However, some feedback.
I don't think that using a 0 cache age is the correct approach here. The cache age can be determined using the seconds until the date change. This can be done using
strtotime('tomorrow') - time(). As users can set individual timezones this should then have the cache context for the current user, and use their timezone to calculate the max cache age.Also reading through the comments, I noticed #48. I think this is a very valuable thing to consider as well since it would provide wider support for the functionality.
Marking this as needs works since it should either get tests added or have a proper cache context implemented.
Comment #116
acbramley commentedThe "Date" plugin not found error still exists at least on 8.5.7, reproducable by selecting "Current date" as the argument default for a date contextual filter eg "Content: node.field_event_start_date (year)" where field_event_start_date is a date field.
Confirmed that #111 fixes it.
Comment #117
lamigo commentedThe "Date" plugin not found error still exists at least on 8.6.3, reprodicable by selecting "Current date" as the argument default for a date contextual filter eg "Content: node.field_event_start_date (year)" where field_event_start_date is a date field.
Confirmed that #111 fixes it.
Comment #118
konfuzed commentedCan confirm this bug is still present on a very simple 8.6.4 installation today. Path 2325899-111 fixed it for a year/week contextual filter implementation.
Comment #119
kmaniConfirmed that #111 fixes it.
Comment #120
joachim commented> IMHO we should implement this not just for nodes but for every entity with EntityChangedInterface
> Also reading through the comments, I noticed #48. I think this is a very valuable thing to consider as well since it would provide wider support for the functionality.
Yes, but... doing this would require a derivative plugin, which would mean the plugin ID would change from 'node_created' to something like 'entity_created:node', which would require a hook_update_N() to convert existing views that use 'node_created' as their argument default setting. Which rather complicates this patch.
It would be better to leave to a follow-up.
Comment #121
joachim commented> I don't think that using a 0 cache age is the correct approach here. The cache age can be determined using the seconds until the date change. This can be done using strtotime('tomorrow') - time(). As users can set individual timezones this should then have the cache context for the current user, and use their timezone to calculate the max cache age.
Is that not also out of this issue's scope?
Comment #122
joachim commentedIs this necessary?
These plugins have no configuration, so isn't it fine for them to just use the wildcard default:
It's what the current_user ViewsArgumentDefault plugin does.
While we're rerolling, both of these sentences read badly. Something like 'Provides the created time of the current node as default argument value.' assuming that's under 80 chars.
This method is defined in ArgumentDefaultPluginBase, so the docblocks here should be @inheritdoc.
For the two node plugins, move the text to an inline comment as it's informative.
Comment #123
lendudeStraight reroll for now, just to see what this does now.
Comment #124
lendudeAddressed #122.
Also moved the date format in the 'current date default argument' to a class variable so that it is easy to create default arguments for different formats (like month/year/week) by just extending that class and overriding that variable.
Comment #125
lendude...sigh...
Comment #127
wombatbuddy commentedConfirmed that #125 fixes it.
Comment #128
rutiolma+1 for patch #125
Comment #130
rensingh99 commentedHi,
I had applied the patch with Drupal 8.9.x and it's throwing an error.
I have corrected that and made it compatible with 8.9.x.
Below is my review:
Before applying the patch
1) I have created the view for the 'page' content type and tried to add the 'Authored on' field in CONTEXTUAL FILTERS. But I was not able to apply these filters.
2) Then I reviewed dblog and I notice the below error.
After applying the patch
1) I ran update.php
2) Then I tried to add the 'Authored on' field in CONTEXTUAL FILTERS and I have added this field successfully.
3) Also, the view was working perfectly after applying the patch.
I also checked the patch with the coder module and corrected the errors from the list.
I was unable to fix one error because both class names are the same in core/modules/views/src/Plugin/views/argument_default/Date.php and \Drupal\views\Plugin\views\argument\Date.php
Below is the output screenshot of the coder.
Thanks,
Ren
Comment #131
clemens.tolboomAs @rensingh99 found in #130 and the failing test(s) for 8.9.x (Patch Failed to Apply) in #125 I added ... this needs work.
Comment #132
rensingh99 commentedHi,
I had missed the patch to attach in my comment. Here is my updated patch
Thanks,
Ren
Comment #134
joos commented#125 worked for me
Comment #135
rensingh99 commentedComment #136
rensingh99 commentedComment #137
clemens.tolboomSo we have patches in comments
- #125 for D8.7.x RTBCed
- #132 for D8.8.x and D8.9.x still needs work
Comment #138
rensingh99 commentedHi,
Patch #132 was failing due to fix in Remove the core key from views configuration.
I have corrected that.
Thanks,
Ren
Comment #139
rensingh99 commentedComment #140
rensingh99 commentedComment #141
jungleReroll the patch in #138
Comment #142
jungleFix coding standard and deprecated assertions
Comment #143
jungleComment #145
jungle$defaultTheme is required in DateArgumentDefaultTest
Comment #147
muaz7731Hi, test out the patch from #145 with drupal core 8.8.6. it works. need to clear cache first to have the filter display. Thanks @jungle
set as RTBC
Comment #148
muaz7731I'm not sure what version to put this. maybe 8.8.x-dev?
Comment #149
dwwThanks, but this can't be RTBC if the patch fails to apply.
We need fresh patches for 9.1.x, 9.0.x and 8.9.x.
Quick skim looks like this is probably too potentially disruptive for 8.8.x, but it does have the "Triaged D8 major" tag, so maybe. ;) A separate 8.8.x patch for that branch (or maybe re-test #145 if that's still legit for 8.8x.) would be good, just in case.
Thanks,
-Derek
Comment #150
sokru commentedReroll from #145.
D9 patch applies cleanly to both 9.0.x and 9.1.x branch.
Comment #152
jungleFixing test failure and one CS violation of the patch for 9.x in #150
Comment #154
jungle#152 looks like a random failure, re-queued.
Comment #155
nno commentedApplied #150 to Drupal 8.9.4 to create views for "Today's day in history" with two contextual filters:
Content: node.field_date (day) / Provide default value = Current date
Content: node.field_date (month) / Provide default value = Current date
Works like a charm. Thank you.
Comment #156
jungleChanges of assertEqual -> assertEquals were wrong, have not swapped $expected and $actual, my bad. and some of them are out of scope/irrelevant.
The bug exists still in 9.1.x, manually tested. Due to my limited knowledge to views, I have no idea how to push this forward next :(. Thanks @Lendude's replies on slack.
Comment #157
solide-echt commentedHi, as one of the maintainers for Calendar I have a question since that contrib is very much dependent on date contextual argument handling:
Is the 9.x patch *supposed* to work for datetime_range too? From my manual testing it doesn't. The error is:
SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid value "T1" for "HH24" DETAIL: Value must be an integer.: SELECT "node_field_data"."created" AS "node_field_data_created", "node_field_data"."nid" AS "nid" FROM {node_field_data} "node_field_data" LEFT JOIN {node__field_date_range} "node__field_date_range" ON node_field_data.nid = node__field_date_range.entity_id AND node__field_date_range.deleted = :views_join_condition_0 WHERE ((TO_CHAR((TO_TIMESTAMP(node__field_date_range.field_date_range_value, 'YYYY-MM-DD HH24:MI:SS') + INTERVAL '7200 SECONDS'), 'MM') = :node__field_date_range_field_date_range_value_month)) AND (("node_field_data"."status" = :db_condition_placeholder_1) AND ("node_field_data"."type" IN (:db_condition_placeholder_2))) ORDER BY "node_field_data_created" DESC NULLS LAST LIMIT 10 OFFSET 0; Array ( [:node__field_date_range_field_date_range_value_month] => 10 [:db_condition_placeholder_1] => 1 [:db_condition_placeholder_2] => contact [:views_join_condition_0] => 0 )I'll try dig in deeper, the HH24:MI:SS format looks odd.
Kind regards,
Eric
Comment #159
pdenooijer commentedWorks like a charm. This bug should be fixed for all minor versions of 9.
Comment #160
clemens.tolboomReset version according to comment #158 and set to Needs review for test on 9.2.x and both #156 and #157 suggests some may still be wrong
Comment #161
pdenooijer commentedAs far as I can see is this a bugfix and not a disruptive change. So this can be merged to the current Drupal branch.
Rerolled the patch to branch 9.1.x as it had conflicts.
Comment #163
anmolgoyal74 commentedTried to handle the failed test cases.
Comment #164
pdenooijer commentedThanks @anmolgoyal74 for fixing what I missed. Uploaded a new patch that fixes the deprecation warnings in the 9.2.x branch.
Comment #165
pdenooijer commentedComment #166
mfgr commentedWorking like a charm on my website (v. 9.1.4). I hope this will be integrated into Core....
Comment #168
quietone commentedTried to review this. I am not able to follow all the steps to reproduce in the Issue Summary. The first is fine, but then the second "Set default argument to "Current date"' I can't. There is no indication where to find this value. I then skimmed the IS and I think the current date is available after applying the patch and in a contextual filter?
Add the patch does not apply to 9.3.x.
Comment #169
sokru commentedReroll for 9.3.x + updated the issue summary with exact steps. No interdiff produced.
Comment #170
ragnarkurm commented@quietone
see the screenshot.

Comment #172
egfrith commentedWhen upgrading from Drupal 8 to Drupal 9, I got the same error: "The "date" plugin does not exist.". This prevented db updates.
I fixed the issue by finding the view in which the current date had been set as a default in a contextual filter, and removing the current date default. It did take a couple of hours, so it would be great if this issue could be fixed, though I don't have expertise to offer in terms of reviewing the patch.
Comment #173
chucksimply commented#169 works for me on 9.3.3. Thanks!
Comment #174
smustgrave commented#169 works for us
Comment #175
smustgrave commentedComment #176
alexpottRather than a specific implementation for nodes it feels as though this should somehow be something generic that leverages \Drupal\Core\Entity\EntityChangedInterface::getChangedTime() - I think we could generate instances for all entity types and do something like
\Drupal\Core\Entity\EntityForm::getEntityFromRouteMatch()to get the entity from the route match. I guess this could be a follow-up.Are we should about this - I would have thought that it would be best add the node as a cacheable dependency - I think we need to vary by the node's cache tags for example.
Oddly there is no generic interface for getCreatedTime() so I think this plugin needs to be entity specific.
This is the changed date and no the create date.
New code should use return type hints.
This should be using the time service and not the REQUEST_TIME server variable.
Comment #177
alexpottThis can be written as...
The @var is not needed because there is the instanceof check. The $argument local variable is unnecessary too.
This can be used elsewhere in the patch too.
Comment #179
damienmckennaRan into a related problem with a custom Search API "date" property field where it returns this error:
FWIW we hit the error displaying the property as a field in a Views block.
Comment #181
davidiio commentedHi everyone,
We were using the last patch in this issue but since we updated Drupal to version 9.5.0 composer indicate
" Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2021-06-28/2325899-169-9.3-169.patch"
When exploring the files I have only one .rej file and here is the content:
Does this could be a problem on our site, anybody experienced the same? The patch must be reworked ?
Comment #182
ruslan piskarov@davidiio, the same issue for me.
Comment #183
skylord commentedHm. It's just an indentation issue.. Try this for 9.5.0.
Comment #184
ludo.rHere's the same patch as #183, with fixed tests.
Comment #185
ludo.rAfter some investigation, I can confirm the following:
So I assume the patch works, I just don't know why the tests which are exactly the same as #169 don't work anymore.
Comment #186
anairamzapHello,
We were using the patch on #169 and we could not apply it when updating to Drupal 9.5.
So I'm adding a re-roll of #169 to apply cleanly on 9.5.x in case is useful
Comment #187
anairamzapok, so... I think I've found the issue with the tests failing. The test fails because the view is never loaded.
Both tests, the one for the plugin at
core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.phpAND the one for node module atcore/modules/node/tests/src/Functional/Views/DateArgumentDefaultTest.phpare trying to use the same view wih idtest_argument_default_datethe problem is the view itself, the config for it, is added on theviews_test_configtest module.If you look at the
DateArgumentDefaultTestsetUp method, is using a different test module:node_test_viewswhich does not provide the expected view and then of course it fails to load it.Now I'm really not sure if we should either:
node_test_viewsmodule.views_test_configmodule.For the second option (which seemed better so we do not duplicate a view config in a different directory) I've tried to load that module in the
DateArgumentDefaultTestsetUp method, something like:but I've got:
So now I'm trying the other approach, but it really doesn't seem like a good idea.
If anyone here could provide some input on this, it would be great :)
Thanks,
Mariana
Comment #189
anairamzapChanging to "needs review" since a MR was provided applying most of the requested changes from last review.
Also in here I'm adding the re-rolled patch for 9.5.x that hopefully now passes the tests...
Comment #190
smustgrave commentedVerified the issue on D10.1 with a standard install following the steps in the issue summary.
Applying MR 3751 fixes the issue
Question for committer will new default value require upgrade paths? Imagine since this was a fatal error and no one could use the functionality the answer is no but want to make sure.
Comment #192
larowlanTried to clean things up a bit.
Started by removing all patches now there is an MR.
Then assigned credits
Removed credits for simply rerolling
It looks like from #157 that this didn't work for datetime range fields?
Adding needs followups tag for #114 and #176
Updated the issue summary after reading all the comments 😩
Reviewing code next.
Comment #193
larowlanLeft a review on the MR, thanks
Comment #194
lendudeDid the constructor property promotion stuff, added some questions, going to look at using a base class or trait which sounds like a good idea
Comment #195
lendudeThink I got everything, lets see if it stays green
Comment #196
smustgrave commentedCan the MR be updated for 11.x
Currently doesn't apply.
Comment #197
irsar commentedEven after applying the patch, views timestamp_formatter postupdate fails. We are trying to upgrade the site from 9.5 to 10.1.
Comment #198
tormiAdding MR !3751 with the latest commit 3b362cc8 as a patch.
Comment #199
irsar commentedThank you! This patch fixed the updb error. But I am getting this error "Drupal\Core\Entity\Query\QueryException: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck(). in Drupal\Core\Entity\Query\Sql\Query->prepare() (line 141 of /app/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php)" when I load any page. Admins pages are working fine. Any idea on what's causing this error? I couldn't figure out what's causing this. Any help would be appreciated
Comment #200
tormi@irsar, what @smustgrave said in #196. I'm also trying to figure out if there's a version I can use for the latest D10.
Comment #201
jon.lund commentedI am having trouble after updating to Drupal 10
When running the update script I get:
views module
Update timestamp_formatter
Failed: Drupal\Component\Plugin\Exception\PluginNotFoundException: The "calendar" plugin does not exist. Valid plugin IDs for Drupal\views\Plugin\ViewsPluginManager are: calendar_week, calendar_month, fullcalendar_view_display, unformatted_summary, default_summary, grid_responsive, opml, grid, default, table, rss, html_list, entity_reference, blazy in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /home/lhvxidmy/public_html/rise/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).
I have tried removing and reinstalling the Calendar and Calendar_View Modules
I have tried uninstalling both as they are not used.
The Calendar View module will uninstall but the Calendar module will not with the following error:
The website encountered an unexpected error. Try again later.
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "calendar" plugin does not exist. Valid plugin IDs for Drupal\views\Plugin\ViewsPluginManager are: calendar_week, calendar_month, fullcalendar_view_display, unformatted_summary, default_summary, grid_responsive, opml, grid, default, table, rss, html_list, entity_reference, blazy in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).
Drupal\Core\Plugin\DefaultPluginManager->getDefinition('calendar') (Line: 16)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('calendar', Array) (Line: 83)
Drupal\Component\Plugin\PluginManagerBase->createInstance('calendar') (Line: 821)
Drupal\views\Plugin\views\display\DisplayPluginBase->getPlugin('style') (Line: 897)
Drupal\views\ViewExecutable->initStyle() (Line: 877)
Drupal\views\ViewExecutable->getStyle() (Line: 476)
Drupal\views\Plugin\views\field\FieldPluginBase->defineOptions() (Line: 372)
Drupal\views\Plugin\views\field\EntityField->defineOptions() (Line: 143)
Drupal\views\Plugin\views\PluginBase->init(Object, Object, Array) (Line: 109)
Drupal\views\Plugin\views\HandlerBase->init(Object, Object, Array) (Line: 136)
Drupal\views\Plugin\views\field\FieldPluginBase->init(Object, Object, Array) (Line: 199)
Drupal\views\Plugin\views\field\EntityField->init(Object, Object, Array) (Line: 899)
Drupal\views\Plugin\views\display\DisplayPluginBase->getHandlers('field') (Line: 510)
Drupal\views\Entity\View->onDependencyRemoval(Array) (Line: 479)
Drupal\Core\Config\ConfigManager->callOnDependencyRemoval(Object, Array, 'module', Array) (Line: 342)
Drupal\Core\Config\ConfigManager->getConfigEntitiesToChangeOnDependencyRemoval('module', Array) (Line: 43)
Drupal\system\Form\ModulesUninstallConfirmForm->addDependencyListsToForm(Array, 'module', Array, Object, Object) (Line: 160)
Drupal\system\Form\ModulesUninstallConfirmForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('system_modules_uninstall_confirm_form', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
The site seems to work fine however I can not remove these errors.
I applied this patch with no effect on the errors.
I may be in the wrong place altogether. Any advice would be much appreciated.
Comment #202
carlos romero commentedPatch on fork
3751.patch
Tested ok drupal 11 and work fine.
Comment #203
carlos romero commentedComment #204
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #205
foodslover commentedupdates- please use the file of Comment#208
Comment #206
foodslover commentedComment #207
foodslover commentedComment #208
foodslover commentedUpon updating to Drupal 10.2.5, it became evident that the current patch (https://www.drupal.org/project/drupal/issues/2325899#comment-14900128) was no longer compatible. In response, I have refined the patch code to ensure its compatibility with the latest Drupal version, 10.2.5. My objective is to make this revised code advantageous for individuals utilizing Drupal 10.2.5 and in need of this particular functionality.
Drupal : 10.2.5
php: 8.2.15
Comment #209
socialnicheguru commented@foodslover is there an interdiff?
Comment #210
idflood commentedI tried to reroll the merge request for drupal 10.2 but I'm not sure of the correct workflow, especially since the current merge request is based on the 10.1 branch.
Here is the commit I made: https://git.drupalcode.org/issue/drupal-2325899/-/commit/d665b876f6c1ab2...
And I'm attaching a patch which should hopefully work on 10.2.6
Comment #211
laura.gatesI applied #210 to 10.2.5 and my affected view allowed me to save without white screening in addition to adding and removing the date contextual filter.
I then updated to 10.2.6 and was able to do the same tests as I did for 10.2.5 without running into any issues.
Comment #213
percoction commentedRerolled the patch against 10.3.x and pushed up a branch to the issue fork. Also added a static patch here
Comment #214
sseto commentedConfirm #213 worked!
Comment #215
cmarcera commented#213 did not resolve the "The "date" plugin does not exist." error in my clean Drupal 10.4.0 install. I am still unable to select 'Current date' as the default for a contextual filter.
My current workaround is using Views Argument Token with the [current-date] token. Glad to have this solution but hope to be able to use the core functionality at some point.
Comment #216
xjmAdding credit for the triage as per @cilefen in #64.
Comment #218
joelpittetI rerolled, diffed the diffs after — no changes other than context lines (and index hashes). And diffed the MR 3751 against #213
Trying to help this along... next I plan to review the unresolved comments, so leaving as Needs Work.
I will hide the other MRs to keep the focus on that one.
Comment #220
joelpittetOk setting back to Needs Review, tests should be passing again.
Comment #221
lendudeWent through this again, looks great, did some more manual testing with it and that also works as expected. I do think we still need to address the 'Needs followup' tag? I think it is still relevant and I don't think any follow ups were ever created.
Comment #222
joelpittetTook care of the follow-ups needed. Just copied the comments mostly to capture the request, hope that is sufficient to unblock this.
#3555139: Generalize "Current entity created/updated time" via plugin deriver (all entity types)
#3555138: Default date argument handlers: correct cacheability (contexts, tags, max-age)
Comment #223
joelpittetRE #157 from @solide-echt
That Postgres error came from parsing dates with a “T” in the middle (the way datetime range fields store them) using a pattern that expected a space. The current code already quotes the “T” correctly in the format string, so that mismatch can’t happen now. I don’t see anything else in this MR that would bring it back, so I think this is resolved.
Edit: I am also maintaining (and trying to bring back to life) the calendar module.
Comment #224
lendudeFollow ups look good, looks ready.
Comment #225
alexpottCommitted and pushed 78ddb1a77b8 to 11.x and 6d419294f32 to 11.3.x. Thanks!
Well done for getting this one over the finish line.