Closed (fixed)
Project:
Chaos Tool Suite (ctools)
Version:
8.x-3.x-dev
Component:
CTools Blocks
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
2 Sep 2015 at 17:01 UTC
Updated:
18 Dec 2017 at 19:00 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dsnopekMake title a little clearer.
Comment #3
dsnopekI've started working on this!
Comment #4
dsnopekHere's a first pass at this! It needs to do all the field configuration stuff, and generate better admin labels for the blocks, but it does render fields! :-)
Comment #5
dsnopekI fiddled with this a bit during the in-between times today. All it does is include better category and block labels.
Comment #6
dsnopekAnd once you start, it's hard to stop. :-) Here's a patch which starts to figure out information about available field formatters. Ok, time to go to bed!
Comment #7
dsnopekThis has it storing and using the formatter options that apply to all formatters. Still haven't gotten the actual formatter settings form loading via AJAX yet.
Comment #8
dsnopekAlright! This finally loads the formatter settings form via AJAX and allows those values to be saved and used. It also sets a label for the entity context and makes it required. I think this is ready for wider review!
Comment #10
dsnopekI read through the patch and found some little things to clean up. I promise I won't touch this anymore until someone else can review it. :-)
Comment #11
dsnopekThose test failures were wizard failures. Probably something that needs to be updated for latest HEAD - I'd guess connected with the "Dynamic Page Cache" changes.
Comment #13
dsnopekComment #14
dsnopekBlergh! My interdiff from before was correct, but the main patch was the same as the last one. This one should be correct.
Comment #16
dsnopekStupid wizard tests! Marking as NR - hopefully for the last time today. :-)
Comment #17
dsnopekHere's an issue to fix the wizard tests #2573413: Fix wizard tests
Comment #18
dsnopekChatted with EclipseGC about this on IRC. He told me it's possible to add constraints to the context definition for the entity bundle, so that the block won't be available for entity bundles that don't have the given field. What he didn't know is if you can put multiple constraints for the same value.
Here's some example code from
src/Plugin/Condition/NodeType.php:We'll need to some code that calls
->addConstraints()in the deriver.Comment #19
dsnopekSo, the BundleConstraint can take multiple bundles (in fact, it converts the string to an array). But setting this constraint makes it so that Page Manager won't list the blocks as an option to add when overriding the node/% path.
This is from this code in
ContextHandler::getMatchingContexts():Basically, since the contexts from Page Manager don't have the same constraints, it decides that the context is not available, and doesn't return the block as an option. But Page Manager can't add constraints about the bundle, because in the admin UI, it still doesn't know the specific entity.
So, I'm not sure we can add this to the context definition...
Comment #20
dsnopekHere's the change to this patch that would add the bundle constraint mentioned in #19 just for reference
Comment #21
dsnopekHere's a new version of this patch which has the deriver descend from EntityDeriverBase.
Since the "bundle constraint thing" (from #18, #19 and #20) ended up not being workable (although, not having the constraint doesn't hurt anything as far as I can tell) I think this now addresses all the informal review from EclipseGC in IRC! So, setting back to Needs Review.
Comment #22
dsnopekBah! This is a Git failure on my part, but my last patch in #21 accidentally included the "bundle constraint thing" change which is represented in the interdiff in #20. Here's what the patch should have been. The interdiff from #21 is still correct. Sorry for the confusion!
Comment #23
tim.plunkettCan you put all of these getters at the bottom of the class? Just for readability's sake.
I think it's fine to just do
$this->configuration['formatter']['label'] = ...here, BlockBase::setConfiguration() does nested merges, which we don't need.This should be the first method after __construct/create, IMO
I think this should be
Comment #24
dsnopekAlight! Here's a new patch that addresses all of Tim's points in #23. The interdiff is super messy because code is moved around, but it is what it is.
Comment #25
jonhattan...entity field.
Wrong doctring.
If
$plugin_base_idis not to be used, this also does the joblist(,$entity_type_id,$field_name) = ... I think it is clearer.This is the same array as the one returned by
$this->entity->getComponent($field_name);(used in buildFieldRow()). See below.I wonder if we can leverage
EntityViewDisplayEditForm::buildFieldRow() here instead of building a very similar form.
entity field again.
Comment #26
tedbowI just found this issue. I was helping Field as Block module basically do this.
#2513246: New approach for fields as block
I created an issue on that module to let them know this might be included in CTools
#2603044: Similar functionality will be included in CTools
Comment #27
dsnopek@tedbow: Thanks! I didn't know there was a whole project for that...
In any case, CTools will definitely do this (it did it in D7 too, we just didn't use core blocks in D7), it's just a question of nailing down the implementation. Also, we see CTools as an incubator for core, so it's possible we'll propose this for inclusion in core in a point release (like 8.1, 8.2, 8.3, etc..).
Comment #28
dsnopekJust a note to self: Do we need to specifically implement
::blockAccess()? Marking as "Needs work" to figure that out and to address the review in #25.Comment #29
dsnopekComment #30
tedbowOne side effect of this change is the "Place Block" modal on the core blocks page becomes overwhelming with all of the Blocks this adds.
As you can see in this screenshoot most of the first screen is taken up my "Content Field" blocks. If I scroll there is another page of this. And then there are a bunch of user ones at the end. And this is just on a test site where I haven't actually added any fields through the Field UI. I also don't any contrib modules that define their own entity types.
I know there is now a search box but I think it will be overwhelming for a lot of new site builders and might lead them to think "Place Block" is mainly just for fields.
Since CTools is likely to become effectively required for most Drupal 8 sites(because it so useful and many modules will depend on it) then I think there should be some consideration for how these changes will affect sites that aren't using Page Manager/Panels.
Right now I see that CTools has no submodules. Is that the plan for Drupal 8 or would it make sense to have some functionality like this that would be sub-modules that modules like Panels could require(or suggest is that possible in D8?) but that not every site would have to automatically turned on just because they have a module that depends on CTools.
Anyways I feel like I am rambling but thought I would put this out there for feedback.
Comment #31
dsnopekThe plan is also for CTools to include improvements to the core block UI, because there are several problems (not just this one) once contrib starts including more blocks and conditions. For example, enabling the Rules module totally breaks the core block UI too.
Tomorrow I'll start making some new issues for the UI improvements! I was hoping to get this one in first and work on the UI stuff second (because CTools is still in -alpha), but I'd be fine with doing it the other way around if necessary. :-)
Comment #32
tedbow@dsnopek,
Re:
Ok cool I didn't know that.
No need to on my account ;). Looking forward to see what the UI improvements are.
Comment #33
dsnopekI created a meta issue for improvements to the core block UI:
#2604162: [meta] Improvements to core block UI
It's got the 3 issues we've discussed in the past, but this is the one that applies to this situation:
#2604178: Modify core block UI to seperate blocks into categories with tabs
Comment #34
dsnopekHere's a new patch to address the review from #25! Thanks!
Regarding points #4 and 5: I really don't know how we'd reuse code from Views, and actually, even if I knew how I'm not sure it'd be a good idea coupling this to Views code since this functionality doesn't depend on views.
Still TODO:
::blockAccess()Comment #35
dsnopekThis patch should finally handle access correctly! It also switches away from the deprecated
EntityManagerInterfaceand uses the two services it actually needs.Also, I moved my remaining tasks up into the issue summary.
Comment #36
dsnopekActually, we can access the entity context from
::blockAccess()so we don't need to check twice!Comment #37
dsnopekHere's a patch that moves this code into a new ctools_block module, with no other functional changes. I'm not including an interdiff because it's just moving code.
Comment #38
dsnopekHere is a patch that adds the boilerplate for writing the tests, but none of the actual tests. I put some @todo's in the
EntityFieldBlockTestfor the sort of tests we need to write. All of them are hardcoded to fail for now!Comment #39
dsnopekOk, apparently what I did in #36 is wrong, because we don't actually have access to the entity from context in
::blockAccess(). Sorry, @phenaproxima!Comment #40
phenaproximaBehold, for I have written tests.
Let it be known that the render cache test does not pass; but according to @dsnopek this is unsurprising. I'd fix it myself but I don't know enough about the render pipeline to make short work of it.
Comment #41
jonhattanre #34. @dsnopek points 4,5 in #25 are not about views, but field_ui module.
Comment #42
tim.plunkettHmm, what made you come to that conclusion in #39?
a) blockAccess should ABSOLUTELY have access to the entity context.
b) It does, in my testing.
I made this change to ctools, and put a breakpoint in blockAccess and $entity was fully populated.
Comment #43
dsnopekRe #42: EclipseGC, phenaproxima and I were getting a fatal error that was fixed by making the change in #39. I'll dig into this now and see if I can't get to the bottom of why that works for you and not us, and why get a fatal for stuff that is working for us. :-)
Also, I added a TODO to the issue summary about the config schema so we don't forget about that!
Comment #44
tim.plunkettOkay I misunderstood and was testing via the Page Manager UI.
This patch is on top of #40.
Comment #45
dsnopekThanks, Tim! The config schema stuff is hard, even without two core bugs. :-) Unfortunately, I don't think testbot will run our tests because ctools_block is a new module added in this patch, so the TEST/FAIL patches won't do their thing. :-/
@jonhattan: re #41 - ah, ok, sorry, I misunderstood! I'll look into it!
Comment #46
dsnopekThis gets the render cache tests passing! It also shows what needs to be changed to fix #2631120: "Entity view" block showing first entity rendered on all pages . However, I think one part of the test isn't really testing anything:
Since the body is displayed on the node view page anyway, it'll always find it here. We need to look specifically at the block somehow (or use a different field that isn't displayed on the node view page).
On the other tests too, I think we should test not just that the block label is there, but that the contents look right. We could use a similar or the same approach for that.
Comment #47
dsnopekUnassigning for now...
Comment #48
phenaproximaAt the beginning of that test method, the body component is specifically removed from the entity view display in order to ensure that the test is meaningful. :)
Comment #49
phenaproximaFixed a fatal error caused by a missing sanity check in EntityFieldDeriver.
Comment #51
dsnopekBlergh! Tests are failing because my last patch (which phenaproxima's is based on) is missing Tim's config schema. :-/ Here's a patch that adds it back. At least testbot is running the tests for ctools_block now. :-)
re #48:
Aah, sorry, I missed that. Actually, since we're creating a special content type for this and providing the config for the display, maybe we should just always hide all the fields from normal display?
I'll do something like this is in the next patch!
Comment #52
dsnopekAlright! This patch removes the fields from normal display in the config bundled with the tests, so if we see the content, we're sure it's from the block. So, I added tests for the actual content where that made sense. Since we aren't actually uploading an image, this made the image field test kinda useless, so I removed that for now (rather than spend time figuring out how to do that - let's just get this patch committed!).
As far as I'm concerned this is ready enough to be merged - we can address anything else in follow-ups.
Comment #53
chx commentedWhat I do not readily understand is -- why a separate block for each field? Why not one block per entity type with the field name as a setting?
Comment #54
tedbowI also wondered about @chx question. See my comment and screenshot in #30 about how many blocks this produces and how it seems to take over the block add page.
@dsnopek did mention some UI improvements that would make the that situation better. I didn't follow up about that.
Comment #55
dpi#53
Field as Block is a shining example of how it should be done.
Comment #56
dsnopek@chx: I think the main reason is this is how we did it in Drupal 7, and we're working (slowly) towards replicating the experience in Panopoly where you have the blocks divided clearly by category.
That user experience works really well for us, where users drill down in conceptual areas. For example, first they say, "I want to put something with users, so they click 'User'" and get a list of those blocks, which includes both fields and other user-y things, without the user really needing to know the difference between say a "field" and a "view" that takes a user context - they just know they want things that come from users. If they had to select a "User field" or "Entity field" block and then configure it, it requires them to know Drupal-y things like what a field and an entity are.
@tedbow: the issue to replace the current block selection UI, with an experience more like D7 Panopoly is #2604178: Modify core block UI to seperate blocks into categories with tabs
Comment #57
eclipsegc commentedOk, added a number of changes to the code base that make access more reliable and remove those same checks in the build process (since they're no longer needed there). Also updated the caching process to be more inline with contextual plugins, and removed the block dependency. I am also, after having worked with this, completely unconvinced of a need for a separate module for this block. Core's block UI has a search feature for finding the block you want anyway, which works quite nicely even in the presence of this patch. I'm version heavily leaning toward removing the module and just adding the block to ctools directly.
Eclipse
Comment #59
eclipsegc commentedThis should get tests passing.
Eclipse
Comment #60
dsnopekFor the most part these changes look great! As far as I'm concerned this is RTBC, but I'm too close to this patch to do the honors. :-)
One minor thing (that you can feel free to ignore):
This is cool! However, it kind of sucks having to set each of those #cache values independently.
What if we implement
CacheableDependencyInterface(we're already implementing it's methods) and then did something like:That should be sufficient and it's friendlier to read.
That said, it's probably slightly slower and really doesn't matter. :-)
Comment #61
eclipsegc commentedVery minor addition in this patch.
In general I'm happy with what's here, however I'm not happy with putting it in ctools_block. I want it in ctools directly. To that end, I'm going to timebox an effort on #2604178: Modify core block UI to seperate blocks into categories with tabs and see if I can't get something committed to ctools that makes browsing blocks nicer and easier.
Eclipse
Comment #63
eclipsegc commentedCommitted and pushed.
#2604178: Modify core block UI to seperate blocks into categories with tabs Proved larger than I was hoping (but not larger than I expected). To that end this has been committed now. I have every intention of moving it OUT of ctools_block and using that module for something other than just wrapping this. I'm hoping that we'll have some time between the latest release and our next release and that we can solving this before an alpha containing this code is out.
Comment #64
dsnopekWoohoo! Thanks. :-) I somehow missed this yesterday..
Comment #66
jmev commentedSorry, but I'm a bit unsure how to use this. I've applied the patch and there are still no fields showing up in the page manager when I try to add blocks. Can you tell me what I am missing?
Thanks.
Comment #67
miiimooo@jmev (You've probably worked this out by now) you have to enable the Chaos tools block module too (ctools_blocks) - no need to apply a patch this is the current version (8.3.0-alpha24) and works freshly installed with page manager (8.1.0-alpha23), panels (8.3.0-beta4) and layout plugin (8.1.0-alpha22)
Comment #68
netsliverHi,
I have a field in taxonomy, it doesn't appear on blocks list.
Someone managed to use it with fields on the terms?
Regards