Problem/Motivation
In #2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc. we refactored _drupal_add_html_head_link() into the HtmlResponseAttachmentsProcessor class.
_drupal_add_html_head_link() is the only code that calls drupal_http_header_attributes().
Also, all drupal_http_header_attributes() does is to format headers using string manipulation.
Thus, we could fold drupal_http_header_attributes()'s behavior into existing methods within HtmlResponseAttachmentsProcessor.
OR...
We could refactor drupal_http_header_attributes() to be a helper method on HtmlResponseAttachmentsProcessor, since that's the only place its used.
Proposed resolution
- Refactor the behavior of drupal_http_header_attributes() to be a method on HtmlResponseAttachmentsProcessor.
- Write unit tests which prove its behavior is correct.
Remaining tasks
User interface changes
API changes
Data model changes
Beta phase evaluation
| Issue category | Task because it's a refactoring of code that works. |
|---|---|
| Issue priority | Normal because it's inelegant. |
| Prioritized changes | Prioritized for refactoring a zombie function into its proper scope and testability. |
| Disruption | Not disruptive because nothing else calls this function. |
| Comment | File | Size | Author |
|---|---|---|---|
| #62 | 2566619-62-follow-up.patch | 2.06 KB | andypost |
| #57 | 2566619-57.patch | 4.97 KB | andypost |
| #57 | interdiff.txt | 4.75 KB | andypost |
| #50 | 2566619-49.interdiff.txt | 2.58 KB | claudiu.cristea |
Comments
Comment #2
mile23This patch marks drupal_http_header_attributes() as deprecated for removal before the 8.0.0 release.
Comment #3
andypostFits into prioritized https://www.drupal.org/contribute/core/beta-changes#prioritized
"dead code"
Comment #4
mile23It's not dead code until #2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc. is committed.
Comment #5
mile23#2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc. is in, so this is now dead code.
Ignore the previous patch and just remove
drupal_http_header_attributes().Comment #6
joshi.rohit100Okay!
Comment #7
joshi.rohit100removed!
Comment #8
joshi.rohit100sorry! wrong status
Comment #9
joshi.rohit100sorry! wrong status
Comment #12
joshi.rohit100It seems like this function is still in use
Comment #13
andypostYep
Comment #14
mile23Indeed. It's not actually dead code.
Also, the tests were misplaced in a reroll: #2571427: HtmlResponseAttachmentsProcessor tests misplaced during reroll
So I'd suggest postponing this until after the tests are added back, because any refactoring here should add to those tests.
Comment #15
mile23#2571427: HtmlResponseAttachmentsProcessor tests misplaced during reroll is fixed, so let's go. :-)
Comment #16
joshi.rohit100Comment #19
daffie commentedComment #22
sdstyles commentedReroll #7
Comment #25
sdstyles commenteddrupal_http_header_attributes() is still called by HtmlResponseAttachmentsProcessor::processHtmlHeadLink()
Comment #26
mile23Comment #27
marvin_b8 commentedhi,
What should be tested?
it's a protected method.
Comment #28
marvin_b8 commentedComment #29
mile23Thanks.
Let's rename it
formatHttpHeaderAttributes(). 'Drupal' is superfluous.Also a unit test would let us trust what it does.
Thus we need a unit test where we mock
HtmlResponseAttachmentsProcessorand then use reflection to makeformatHttpHeaderAttributes()accessible. Use a@dataProviderto feed in various inputs for$attributesalong with an expected result.Comment #30
alvar0hurtad0Here is the patch in #27 with the fixes on #29 but the mock on 3th paragraph.
Comment #31
mile23Comment #34
joelpittetWe will need keep this function with @deprecated but it can just be a wrapper for a class method.
Comment #35
marvin_b8 commentedA wrapper is not possible because the method is protected
and i'm not sure if it make sense to change this.
reroll #30
Comment #36
marvin_b8 commentedComment #37
joelpittetHaving a duplicate code in core will likely cause fragmentation if there is a bug fix and not remembered(we have one of these issues already in core with render escaping @see
theme_render_and_autoescape()). If we can't make that methodpublicfor whatever reason, might as well make a BC public method that returns the result and marked as@internalor something.Comment #38
dawehnerWhat about the following: a) Use 8.3.x here b) make the method public static but call it @internal and @deprecated, as in 9.x we can call to it internally
Comment #39
marvin_b8 commentedComment #40
dawehnerIs there a reason we don't just copy the existing documentation?
Should be @return string and @param array attributes
Maybe explain why its protected here.
Comment #45
claudiu.cristeaRerolled, adapted to the Drupal deprecation policy and added CR.
Comment #46
claudiu.cristeaI we want to keep the new method protected, we can add a deprecated public static method that just wraps the protected. But I think we can keep it public.
Comment #47
claudiu.cristeaFix a coding standards issue.
Comment #48
andypostLooks ready, only question about docs & interface
Maybe move documentation to
\Drupal\Core\Render\AttachmentsResponseProcessorInterfaceComment #49
claudiu.cristeaMoved.
Comment #50
claudiu.cristeaOh, the patch :)
Comment #52
claudiu.cristeaComment #54
claudiu.cristeaComment #55
longwaveDrupal\Core\Ajax\AjaxResponseAttachmentsProcessorimplements this interface but doesn't implement this method. As this is a static I don't think it needs to be on the interface, it can just be declared on the class only?Comment #56
andypostmakes sense to add test to make sure this error is triggered
Comment #57
andypostPatch
- removes bethod from interface & marks
@internal- fix deprecated message
- adds test coverage
Comment #58
longwaveLooks good!
Comment #59
catchCommitted f577bdc and pushed to 8.7.x. Thanks!
Comment #61
anavarreWe made a typo here FYI - s/nn/in/
Comment #62
andypostFix typo
Comment #63
claudiu.cristeaComment #65
catchPatch was already in, but made the same change locally and committed it.
Comment #66
andypostCR published