Problem/Motivation
datetime.module declares global constants, which are only available when the module is enabled. This can cause problems in some scenarios in the install/uninstall process.
Proposed resolution
The constants are directly related to the field item, so create DateTimeItemInterface and duplicate the constants there.
Updates usages in code.
Deprecate the module globals.
Remaining tasks
Create DateTimeItemInterface
Move global constants from datetime.module to new interface (see also #2807785: Move global constants from *.module files into interfaces for how to handle b/c).
Update global constant usages to use the ones on the interface.
User interface changes
N/A
API changes
Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface
has been created. There should be no impact on contrib, as field items that extend DateTimeItem or DateRangeItem will inherit the constants.
Global constants in datetime.module are deprecated.
Data model changes
None. The constant values are the same.
Comment | File | Size | Author |
---|---|---|---|
#20 | interdiff-17-19.txt | 1.12 KB | mpdonadio |
#20 | 2826404-19.patch | 51.96 KB | mpdonadio |
#17 | 2826404-17.patch | 50.83 KB | mpdonadio |
Comments
Comment #2
mpdonadioOk, first pass at changes. Didn't move constants from DateTimeItem yet. We will also need a DateRangeItemInterface and move that constant.
Comment #4
mpdonadioThis should fix the current fails, but there is still work todo. For reference, from @klausi on #2807785-22: Move global constants from *.module files into interfaces
Comment #5
mpdonadioI started to move the constants from the items classes to the interfaces, and update usages. Since DateRageItem extends DateTimeItem, the refactoring looks a little weird once you swap out the usages. I am thinking that we keep the scope at #4 for now to keep the parent issue moving, and defer further work.
Thoughts?
Comment #8
jhedstromI some how missed this. It needs a bit of work to catch up to the latest changes in core.
Comment #9
jofitz CreditAttribution: jofitz at ComputerMinds commentedPatch in #4 no longer applies. Re-rolled.
Comment #10
mpdonadioUpdated deprecation messages and found a few more usages. PhpStorm tells me they are all updated. Drafting the CR now.
Comment #11
mpdonadioUpdating title/IS to reflect where this patch went.
Comment #12
jhedstromThis looks good to go!
Comment #14
jofitz CreditAttribution: jofitz at ComputerMinds commentedPatch in #10 no longer applies. Re-rolled.
Comment #15
larowlanThese need to reference the change record
Any reason why we're mixing the concrete Item and the ItemInterface? Should we be consistent? Moving the constant up from the Item to the Interface won't break BC
we can use self:: here
Comment #16
mpdonadio#15-2,
The constants on the Item already exist, and are related to the field type. The current patch adds DateTimeItemInterface, and replicates the storage constants in the global namespace. So, this is question about where to stop with scope for this issue. We can also move the existing constants on the Item, but then we would really should add a DateRangeItemInterface, too, and move that constant.
I'll post the other two comments later tonight.
Comment #17
mpdonadioHere is #15. Per IRC w/ @larowlan, we will do the existing constants as a followup, #2915046: Move DateTimeItem and DateRangeItem constants onto interfaces.
Comment #18
mpdonadioFound a few more usages in comments.
Comment #19
jhedstromI think #18 includes a bunch of un-intentional changes (perhaps diff happened after a coding standard issue was committed). I think this is good to go once fixed to include #17 + #18's interdiff.
Comment #20
mpdonadioNo idea what happened there (I have a shell script to make patches and interdiffs). This looks better.
Interdiff is against #17.
Comment #21
jhedstromRe-confirmed that all the usages of the old globals have been updated to the new class constants. This is great cleanup.
Comment #23
mpdonadioOdd bot problem that looks unrelated to this, https://www.drupal.org/pift-ci-job/794085
Comment #25
xjmThis is a great improvement.
@trigger_error()
in the code path for the deprecated code. I couldn't think of any way to do this. We don't have a section for constants on https://www.drupal.org/core/deprecation. Our Symfony friends http://symfony.com/doc/current/contributing/code/conventions.html don't have an example for this either. So nothing actionable there.I inspected the changed usages with
git diff --staged --color-words="[^[:space:][:punct:]]+|[:punct:]+"
and all look correct.I also confirmed there are no remaining usages of the constants:
Committed and pushed to 8.5.x. Thanks! I published the new change record; let's also update https://www.drupal.org/node/2831620. I added a reference to this issue but did not update it with the additional rows. This can be marked back to fixed once the other CR is updated.
Comment #26
jhedstromI've added those three constants to the CR noted in #25.
Comment #27
xjmThanks @jhedstrom.