Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
follow-up to: #254491: Standardize static caching
see last patch examples: http://drupal.org/node/254491#comment-1430180 and also: http://drupal.org/node/224333#static_variable_api
Apply this conversion pattern to includes/form.inc to convert all static variables there. Pay close attention to any place a reset parameter is provided and add a call to drupal_static_reset() where appropriate (e.g. in any calling function that uses the reset parameter)
Comment | File | Size | Author |
---|---|---|---|
#23 | jamesan_422362-23.patch | 6.21 KB | JamesAn |
#19 | jamesan_422362-19.patch | 5.92 KB | JamesAn |
#17 | jamesan_422362-17.patch | 4.49 KB | JamesAn |
#13 | jamesan_422362-13.patch | 5.87 KB | JamesAn |
#6 | jamesan_422362-6.patch | 7.03 KB | JamesAn |
Comments
Comment #1
JamesAn CreditAttribution: JamesAn commentedComment #3
JamesAn CreditAttribution: JamesAn commentedOops. I missed something. I'll get to it tomorrow.
Comment #4
pwolanin CreditAttribution: pwolanin commentedComment #5
pwolanin CreditAttribution: pwolanin commentedPer discussion w/ catch - if you have a variable name more complex than just __FUNCTION__, use a ':' to separate the suffix (this will avoid colliding with any other valid function name). e.g. :
Comment #6
JamesAn CreditAttribution: JamesAn commentedTry, try, try again!
Comment #7
pwolanin CreditAttribution: pwolanin commentedThis patch seems to add a couple resets that were not present in the existing code, such as:
Can you explain the reasoning behind this?
Comment #8
JamesAn CreditAttribution: JamesAn commentedSorry for the lack of explanation. Those resets were supposed to be there in the first place.
form_options_flatten() resets on every call by default, unlike some of the other reset features. That wasn't taken into account in the first patch, but it's reflected here with additional reset calls.
Comment #9
pwolanin CreditAttribution: pwolanin commentedIf all current calls to it reset, maybe that logic should be preserved, rather than requiring an extra function call each time - probably need input from eaton, chx, or some other FAPI guru.
Comment #10
pwolanin CreditAttribution: pwolanin commentedexplanation from chx:
chx suggests we open a separate issue to clean up function form_options_flatten(), but leave it alone in this patch.
Comment #11
Dries CreditAttribution: Dries commentedI think it is bad form for function A to blow out the static variable from function B. Regular static variables can't do that. Only tests should blow away a static variable from underneath another function. If function A blows out a static variable from function B, we might as well start using goto's. Bring back the $reset parameter please -- it makes for more readable and predictable code.
Comment #12
pwolanin CreditAttribution: pwolanin commented@Dries - part of the point was to eliminate the reset parameters that make for odd and unpredictable function signatures. We absolutely want to be able to externally clear the static cache - see the taxonomy module now. For example, we clear cached data about vocabularies whenever a vocabulary is saved or deleted. This is exactly what we want to be able to do.
These static variables are just a temporary cache - the only effect of wiping them is the cost of rebuilding the data.
Comment #13
JamesAn CreditAttribution: JamesAn commentedOk. The patch ignores the reset parameter in form_options_flatten() and adds a comment referencing this discussion.
Comment #14
JamesAn CreditAttribution: JamesAn commented%*&@#$^!!
I'm sure I flipped the status switch here. Methinks sometimes the status is not switched if I select a change and then upload the file. =\ Or maybe I'm just forgetful.. -.-
Comment #15
JamesAn CreditAttribution: JamesAn commentedI've opened an issue for form_options_flatten() at #437018: convert form_options_flatten() in form.inc to use new static caching API. I've proposed a solution there as well.
Comment #16
pwolanin CreditAttribution: pwolanin commentedMinor improvement needed - this does not conform to our normal code style:
Code comments before the function should be 1-line doxygen describing the function.
You could include a show comment within the function body summarizing why the conversion was not done, but I would not reference the issue directly. Generally those references in code are only in rare cases where we are working around a bug expected ot be fixed later.
Comment #17
JamesAn CreditAttribution: JamesAn commentedSorry for the delay.. here's the fixed patch.
The comment is moved into the function and says:
Comment #19
JamesAn CreditAttribution: JamesAn commentedHrm. That patch I uploaded didn't even include all the changes.
Here's the correct patch.
Comment #20
Dries CreditAttribution: Dries commenteddrupal_static_reset('form_set_error')
a developer can't discover because it doesn't have API documentation,form_set_error(NULL, '', TRUE)
is a bit ugly. Better than callingdrupal_static_reset('form_set_error')
orform_set_error(NULL, '', TRUE)
is calling something likeform_clear_error()
-- this can be documented and would be nice, clean and intuitive.Comment #21
eojthebraveThis comment,
Should probably be something like
Comment #22
eojthebraveOops. Changing status to needs work.
Comment #23
JamesAn CreditAttribution: JamesAn commented@Dries, form_clear_error() sounds like a decent compromise to me.
@eojthebrave, thanks for catching that typo! I do that occasionally.. ^^"
Try, try, try again...
Comment #24
JamesAn CreditAttribution: JamesAn commentedtestbot?
Comment #25
Dries CreditAttribution: Dries commentedLooks like a nice clean-up to me. Will commit later unless someone objects.
Comment #26
catchLooks fine to me, and form_clear_error() seems like a decent pattern we can use elsewhere (I think we're already doing that elsewhere when there's more than one static which needs to be cleared).
Comment #27
Dries CreditAttribution: Dries commentedI agree that this is an acceptable pattern ... Committed to CVS HEAD.