Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
base system
Priority:
Critical
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
23 Apr 2014 at 09:32 UTC
Updated:
18 Aug 2014 at 13:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
larowlanComment #3
larowlanMissed a '
Comment #5
larowlanrender callbacks have to be strings
Comment #7
sunComment #8
jibranWhy are we using @ sign here?
Comment #9
larowlanWe use the @ to distinguish from other callables that php can interpret
Comment #11
larowlanactually ran some tests locally this time
Comment #12
dawehnerYeah for being able to use services all over the place!
Let's not reinvent the wheel here and just use the controller resolver.
This sadly is needed at the moment because there are callbables like 'Drupal\comment\CommentViewBuilder::attachNewCommentsLinkMetadata' which sadly don't implement ContainerFactoryInterface
but EntityControllerInterface
Comment #13
larowlansweet!
Comment #14
wim leersIf we do this for
#post_render_cachecallbacks, then we should also do it for all other types of callbacks (#pre_render,#process,#post_render…). catch said that also — see #2118703-45: Introduce #post_render_cache callback to allow for personalization without breaking the render cache.Comment #15
wim leersAlso: what do we really win by supporting this? Let's explain the rationale in the issue summary.
Why are static methods insufficient? My best guess: because static methods can only access things in the container via
\Drupal::getContainer(), thus breaking/circumventing dependency injection?Comment #16
wim leers#2266275: Don't use the #post_render_cache callback as an array key was closed, but was related to this.
Comment #17
wim leersI'm now effectively seeing use cases for
#pre_rendercallbacks being service methods in core also.Updating title.
Comment #18
dawehner@Wim Leers
One point is consistency, we do support the same pattern all over in core now, the other one is what you said before: you want to potentially have nice unit-testable code.
Comment #19
wim leers#18: Yep, I understand it now — it just wasn't clear initially :)
Comment #20
wim leersStraight reroll. This was broken completely by several patches that went in lately.
Comment #22
wim leersAnd now with support for
#pre_renderand#post_render.Comment #24
wim leers#22's impressive mass test failure was caused by a stupid typo.
I've now added a use case for
#pre_render: I've movededitor_pre_render_format()toelement.editor:preRenderTextFormat(i.e. a newelement.editorservice; for providing functionality related to Drupal render elements, which is the case here). I also know thateditormodule has very strict tests in this area, so if it passes, we can rest assured.There are zero uses for
#post_renderin Drupal core, hence I can't convert anything there.Comment #25
wim leersThis blocks #1805054: Cache localized, access filtered, URL resolved, and rendered menu trees. Bumping to critical.
(Not having this would require expanding the public API of
MenuTreeInterfacemore than necessary.)Comment #26
andypostPlease remove
is it fine to have services for render?
This looks great, in light of #2188287: Split CommentManager in two that name could be reused to render "forbidden message" as well
Comment #27
wim leers#26
#post_render_cacheas well, see #2118703-45: Introduce #post_render_cache callback to allow for personalization without breaking the render cache. It wouldn't make sense to only support this for one callback category.EntityViewBuilderis also a rendering service, for example. That being said, I don't thinkCommentPostRenderCachemakes a whole lot of sense as a separate service. Maybe larowlan just wanted to use that as an example? I hope larowlan can chime in on that.Comment #28
larowlanCommentPostRenderCache makes sense because it has no place being a static method on CommentFormatter and it means we can kill comment_add()
+1 RTBC from me but I wrote too much to make the actual change - @dawehner?
Comment #29
jibranNice. RTBC for me . We need a change record or update an existing one.
Comment #30
tstoecklerHere and below: Why the
strpos()check?The controller resolver handles
$class::$methodstrings just fine. Or if it doesn't, then that's a bug.Or is this just for performance? Then we should add a comment, I think.
Comment #31
wim leers#30: Please see dawehner's comment in #12:
Comment #32
catchLet's add an inline comment for the strpos check, I can see someone 'fixing' that if we don't.
Comment #33
dave reidWould this work if my callback is inside a plugin, not a "service"?
Comment #34
catch@Dave you can use a static method on a plugin now and that should work.
The render system has no way to instantiate your plugin itself, so it can only handle static methods or services.
It is probably feasible to have a class that is both a plugin and also registered as a service - but those would be two separate class instances (and it confused me just typing that).
Comment #35
dave reidLooks like this will need a conflict merge after #2217877: Text filters should be able to add #attached, #post_render_cache, and cache tags landed.
Comment #36
wim leersStraight reroll. No changes were necessary for #2217877 actually, it was #2275491: CKEditor does not support the "readonly" attribute that broke this.
Comment #37
dave reidTrying this out in contrib with https://github.com/drupal-media/entity_embed/pull/38 and confirmed this seems to be working well.
Comment #38
wim leersBack to RTBC per #29 and #37.
Comment #39
chx commentedif (is_string($callable) && strpos($callable, '::') === FALSE) {
element.editor:preRenderTextFormat
*confused* the first is two : the second is : How does this work?
Comment #40
wim leers#39: Ugh, you're right. This was introduced in #11, and only noticed now :(
It doesn't cause any fails because it's a bug that only exists in the if-test to throw an exception… which has no test coverage.
Will fix, unless somebody beats me to it.
Comment #41
dave reidIt would be nice to enhance the test coverage for the various types of callbacks that could be used: function, static method on a class, and service method.
Comment #42
wim leers#41: I agree. But that's only really feasible when we can write unit tests. And that will only be the case once #2239457: Move main complexity of drupal_render() into Drupal\Core\Render\Render lands. So please help review that :)
Comment #44
wim leersInstead of having a special version of the same logic that is used elsewhere, let's just use the exact same logic again:
Much simpler.
No interdiff, because #2228763: Create a comment-type config entity and use that as comment bundles, require selection in field settings form broke this.
Comment #45
wim leersBack to RTBC per #28, #29 and #37.
Comment #46
chx commentedI will leave this as RTBC but that's really convoluted and repeated code, you know? Why can't we do
$callable = \Drupal::service('controller_resolver')->getControllerFromDefinition($callback);? If we can't , follow up with that pleaaaaaase.Comment #47
wim leers#46: Yes, I'd love that too, but — again — see #31/#12. Let's do that in a follow-up.
Comment #49
catchYeah agreed on that as a follow-up.
Committed/pushed to 8.x, thanks!
Comment #50
wim leersComment #52
wim leersFinally filed that follow-up: #2323301: Deprecate the "two double colons" check in Renderer::doCallback().