Closed (won't fix)
Project:
Drupal core
Version:
8.0.x-dev
Component:
wscci
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
15 Nov 2011 at 12:04 UTC
Updated:
29 Jul 2014 at 20:09 UTC
I am a little surprised the addLayer only allows new self and no way to spawn a different class.
| Comment | File | Size | Author |
|---|---|---|---|
| add_different_classes_to_layers.diff | 1.03 KB | chx |
Comments
Comment #1
Crell commentedThat makes sense, I think. Should we pass in a class name, though, or an actual object? (And then call ->setParent() on that object, which if we type check against the interface we can guarantee it will have anyway.)
Comment #2
Stalski commentedWe need to be sure the object passed is a instance of DrupalContextInterface so it's must be the object, no?
Edit: But I like the ability of layering different classes.
Comment #3
Crell commentedIf we wanted to enforce it in the signature, yes, it would have to be an object.
Comment #4
chx commentedYeah for that reason smthing like
at which point , of course, the question is, do we even need this? Just create a new Context derivative instance and setParent and begone?
Comment #5
Crell commentedNo, I was thinking more like:
So in typical usage you'd just call addLayer() as you do now and there is no API change at all. But you could pass in anything that implements the right interface instead if you had some reason to.
Comment #6
Stalski commentedAgreed.
Comment #7
chx commentedHeh, #4 and #5 is the exact same code aside from the Context vs ContextInterface which is of course what I meant :) But the question remains. If I have a new SuperContext class then
vs
Comment #8
pounardI guess both are OK, as long as the addLayer function doesn't do more than it does now. Calling the addLayer() still is best.
Comment #9
Crell commentedI think I would somewhat rather option 2 from #7, as it makes it clear you're adding a new layer on top of a specific object. It also fits the degenerate case better, which is "whatever class you are, that's cool, just add another of yourself". With option 1, you always have to specify the class to use, which means lots more hard-coding.
I also think addLayer() is more descriptive than setLayer(), since you're adding to the stack/linked-list, not simply changing a value. It will change itself back at the appropriate time, by design.
Comment #11
Crell commentedComment #12
chx commentedOh of course i meant addLayer, that was a typo from setParent. I will roll a patch.
Comment #13
webchickPer catch, and blessed by Larry, moving this and all other WSCCI issues to the Drupal core queue.
Comment #14
Crell commentedNo longer relevant.