Closed (fixed)
Project:
Page Manager
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
11 Jun 2014 at 02:27 UTC
Updated:
6 Aug 2015 at 17:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
berdirFirst attempt at this...
Currently displayed directly on the page manager edit form, should probably move to a dialog similar to other stuff.
Currently limited to entities, with autocomplete, then it stores the UUID and then exposes it as a special context class that loads the entity when accessed.
Not possible to remove context again...
Comment #3
berdir1: static-context-2284005-1.patch queued for re-testing.
Comment #5
berdirDidn't test the schema...
Comment #7
berdir...
Comment #8
rlmumfordIn Drupal 7, the static contexts are stored as part of the variant, thus each variant can have a different set of static contexts/relationships. I'm not sure, but from this patch it looks like the config is being stored at the page level.
Comment #9
berdirRe-rolled with the new context definition objects.
@rlmumford: This is a very early proof of concept, I'm fine with moving this to displays, just keeping it up to date to get some initial feedback and looking for input on how to implement it better.. not sure how extendable this should/needs to be.
Comment #10
berdirRe-roll.
Comment #13
berdirAnother re-roll.
Comment #14
frega commentedMinor reroll as FormStateInterface cannot be accessed like an array. Patch and interdiff attached.
Comment #16
berdirThanks. Patch is much smaller, I think you lost the new files in the re-roll.
I would do $input = $form_state->getValue(array('static', 'selection') here.
And directly access it from $form_state below as well.
Or $static_values = getValue('static') and then get all the values from there.
Comment #17
frega commentedRerolled (with missing files) as per suggestions from #15.
Comment #18
tim.plunkettI need to review this properly. Here it is as a reroll for now.
Still needs tests.
Comment #19
dasjoFrom a site builders perspective this looks pretty good.
I was able to add a static context based on a node:
You can then use it for placing content on the block page, e.g.:
- Entity view (Content)
- Entity view (User)
Also if you have multiple contexts of the same type available, you get to select which context to choose from:
Comment #20
rlmumfordThis seems to work on the whole except the autocomplete controller doesn't work with users as
is an empty string. That means the autocomplete throws a fatal error.
Is there a generic entity autocomplete we can use in drupal core?
Comment #21
berdirI stole the autocomplete from dynamic entity reference, which has adapted the entity reference selection plugins now, which probably fixed this for them. That doesn't really work for us, though, I think.
There is no generic autocomplete, a thing we could try is to special case users. Or consider to add a label key to users even if they also have a label callback.
Comment #22
rlmumfordLooked into this further, there is no core autocomplete and the User entity type does not provide any keys that we can search against. I guess this leaves a couple of options:
Comment #23
rlmumfordHi Berdir,
Only just saw your reply. That makes sense, I'm not very keen on adding a work around for Users if we don't allow future module developers to provide a similar work around for their entity types.
Comment #24
rlmumfordHere's a potential way round it. I don't know what you think, it allows us to introduce a special case for users without us embedding it somewhere completely out of reach.
Comment #26
rlmumfordI'm pretty sure that test failure is a failure that is already in the code.
I'm pretty sure you're not allowed to just set the admin theme anymore. I'm going to set this back to needs review and we should probably open another issue up for that bug.
Comment #27
rlmumfordSee #2409321: Update Page Manager Tests for new Immutable Config.
Comment #29
tim.plunkettWhy are we doing this on entity_type_build? Is it really better than just checking getKey('label') on runtime?
$snake_case, please.
Tab, should be spaces
Users, not User's
Missing docblock
Can we use [] everywhere please?
$this->t()
Inject this
What's the plan for this?
Comment #30
rlmumfordThe problem outlined in #20 can probably now be resolved using the EntityAutocomplete service introduced in #1959806: Provide a generic 'entity_autocomplete' Form API element
Comment #31
berdirIt is a bit more complicated due to the dynamic entity type, but I think dynamic_entity_reference solved this issue as well, so I'll look how they did it.
Comment #32
rlmumfordHere's a patch. I've updated it to use the entity.autocomplete_matcher service, which removes the need for the hacky stuff added in the previous patch.
@tim.plunkett I believe I've addressed all your concerns. For (9) I just removed the function, I'm not sure whether the form needs the validation handler as if the entity selected doesn't work it just does nothing.
General Question: Do we want to move the 'Add Static Context' stuff into a dialog and move the form into a method on the EntityLazyLoadContext class so that different plugins can be selected?
Comment #33
berdirI didn't check this yet, but I think there's a lot more that we can simplify with the autocomplete now that core has the entity_reference field type. I stole a lot of the code from dynamic_entity_reference initially, so we should look at what they did: https://www.drupal.org/project/issues/dynamic_entity_reference, specifically this issue: https://www.drupal.org/node/2411981. Which, as you can see, no longer needs a custom autocomplete controller.
Alternatively, we could also just add some #ajax on the entity type selection and then replace the autocomplete widget with an ajax callback. The we don't need custom JS at all I think.
+1 on moving it to a modal, it uses a lot of space right now.
I don't really get the second part, or how you want to do it. We certainly need to allow adding other things as well, and make that pluggable somehow, but I don't think adding something to EntityLazyLoadContext would help, as that is already entity specific.
I guess a proper UI/workflow would look like this:
1. An [Add context] button that opens a modal
2. That allows to select you what kind of context, this needs to be pluggable/extendable somehow. Right now, it would just be Entity.
3. After selecting that, then you get the current form with type and autocomplete selection
I'm not sure how much we want to do in this issue for 2. Defining an API/Event/plugins for this might delay this quite a bit, the best option might be to simply hardcode the form for the moment, and refactor it in a follow-up issue.
Comment #34
rlmumfordAttached is a patch that puts the Add Static context form into a dialog as well as adding "Edit" and "Delete" operations.
I've also added methods to the Page class for CRUD on static contexts. I'm not very happy with these, but they work for now and can be made to use a PluginCollection if/when we make the Static Contexts bit pluggable.
I meant that we the EntityLazyLoadContext would become an example of a "ConfigurableContext" Plugin. Is that clearer?
I agree with this. We can make the plugin in another issue. The plugin probably want's to be provided by another module/core anyway? Configurable contexts are going to be used by other modules (I'm thinking mini-panels) that don't depend on Page Manager at the moment.
Comment #35
berdirgoal is still to get rid of this I think :)
That's a lot of code (and methods) just to avoid looking at $this->static_context directly, IMHO, that's not worth it?
and it's not yet used here.
this shouldn't be needed anymore unless we still call it from the new methods, but I guess not?
I'll see what I can do about those missing tests :)
Comment #36
Anushka-mp commentedTests added to test the static context.
Some bugs found and fixed.
Comment #37
berdirInvalid entity, not entity type.
Also, bonus points for something like @entity_type_label, based on $entity_type->getLabel()
As discussed, add a comment here, that viewing a user does not not actually display anything that we can identify as belonging to the right user. But just by showing that the block is here and is being rendered should be enough to test that the context is working.
I'm not sure if the name should be editable and what happens if you do that.
Comment #38
Anushka-mp commentedEntity type label added instead of 'entity'. comment added in the test as suggested.
the name also edited and asserted.
Comment #39
Anushka-mp commentedComment #40
mrjmd commentedFixed some wording and removed trailing whitespace from patch in #38.
Comment #41
Anushka-mp commentedAs discussed with Berdir,
Custom autocorrect plugins dropped and the entity_autocomplete form element used.
formValidation dropped from StaticContextFormBase (no longer required)
Tests corrected accordingly and comment modification from #40
Comment #43
Anushka-mp commentedMessed up patch! Interdiff is fine
Comment #45
Anushka-mp commentedHm.. I dropped a test line accidentally. added it again
Comment #46
Anushka-mp commentedComment #47
berdirAre these still used?
This is a left-over, can be removed.
The details element here seems strange. It made sense when it was part of the whole page, but it doesn't server a purpose here. I'd drop this completely.
I'm not sure what this is, drupalLogin() only has one argument?
Comment #48
Anushka-mp commentedLeftovers dropped. context form element dropped and changes made to the forms and tests accordingly. the second argument should be inside the createUser method :-)
Comment #51
Anushka-mp commentedComment #54
wim leers#2375695-22: Condition plugins should provide cache contexts AND cacheability metadata needs to be exposed pointed out that it's not clear how to make this set the right cache contexts. Could you explain in a bit more detail the obstacles you're seeing?
Comment #55
mglamanReroll to get an applicable patch.
Comment #57
s_leu commentedHere's a re-roll of the patch which passes all tests.
Comment #58
s_leu commentedAdding another patch that includes a basic test for the static context feature.
Comment #59
s_leu commentedRemoved the accidentally included patch file from the patch.
Comment #60
berdirJust reviewing the interdiffs.
Might be useful to add a comment here. Something like // Ensure that the entity is loaded before checking if it exists.
Not sure we need the asserts here.
Let's also create a second node and add + display them both, so we can test with multiple static contexts.
We're not taking over anything anymore, so remove that part from the comment.
The drupalGet() + asserts here can be removed I think. Then you're already on the right page and don't have to load gain.
Comment #61
s_leu commentedOk applied the changes as suggested.
Comment #66
berdirLooks pretty good. Some feedback below.
We could also store this keyed by the machine name I guess. Not sure what's better, that would make some of the methods easier to implement and the machine name has to be unique anyway.
Does routing.yml have similar comments elsewhere? If not then I'm not sure we should keep it.
As commented before, This method is a left-over from the old code and can be removed.
placeholder should use label, not name. Possibly elsewhere too.
In case we change to key the contexts by name then this would have to just store the machine name and fetch it from the page if needed.
machine name is also required.
We can remove the [] here.
Looks like there were already some tests here, let's remove them, we don't need both. I prefer using nodes as they are easier to validate that they actually show up.
Just like the existing test, this should also testing editing and deleting static context. You could e.g. switch one context to use the other node and then you should see the same node twice on the page.
Comment #67
s_leu commentedI replaced this for the static context related output. But there are other parts of code which use this wrong pattern, for example it can be found in src/Form/PageDeleteForm.php:
I applied the other suggested changes and combined the tests.
Comment #68
berdirI think is finally close. A few more minor things below.
I think I was unclear here :) What I was saying is we shouldn't add a document like this *unless* other places in that file alraedy do it. They clearly do, so we should keep them and re-add ours.
This can also be simplified to directly work on $this->static_context now.
I think this can be simplified a bit to:
// The machine name of an existing context is read-only.
$name is an empty string for the add form so you can just use $name I think?
One empty line should be enough ere.
Comment #69
s_leu commentedHere's another patch with the suggested changes.
I agree, it was a bit unclear. I interpreted "other places" as other modules, for example core modules which don't use such comments, so i removed them. Anyway, re-added them now.
Comment #70
tim.plunkettLooking good!
Can the substr call be on another line, either with a very clear variable name, or a comment?
Also I guess these value classes aren't injectable, but maybe have a getEntityManager() protected method, so would could one day unit test this?
Most of the places in this class we don't bother with $this->get() and none of these other methods do either...
Shouldn't this use the getStaticContexts() method?
Can we be more clear here and use parent::__construct($entity_query) instead?
Missing docblocks and spaces between ) and {
Why do we care what the name is?
Comment #71
berdir1. We can actually inject I think since we create those objects ourself.
6. That's a left-over from an old test where we used the user as context. Can be reverted.
Comment #72
s_leu commentedHere's the new patch including the suggested changes/improvements
Comment #73
berdirI think this addresses #70, time to get it in? :)
Comment #74
tim.plunkettI went to commit this today, but noticed that the autocomplete for adding a static context is completely non-functional (at least for me).
Can you double check that for me?
Comment #75
berdirThat seems to be a core issue: #2536456: Autocomplete is broken (its JS is not loaded). So they're probably broken everywhere, not just here.
Comment #76
tim.plunkettYep, that was exactly it. Thanks for your patience!
Posting a patch with my tweaks, assuming it passes I'll commit this.
Comment #77
tim.plunkettDI++
This was the wrong interface
This doesn't say it returns NULL, should it?
Every EntityForm gets the entity manager via setter injection.
Comment #78
berdirChanges look good, missed the missing injection in StaticContexts.
Comment #80
tim.plunkettHmm, why didn't this fail before?
Comment #82
tim.plunkettOh well, committed anyway :)
Thanks all for pushing on this!