Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Bojhan’s picture

I can confirm on a clean install, I dont have the "Edit" menu item.

Wim Leers’s picture

Title: Toolbar doesn't show the inline editing icon. » Toolbar doesn't show the "Edit" tab
Assigned: Unassigned » Wim Leers
Status: Active » Postponed (maintainer needs more info)

Please provide steps to reproduce.

Wim Leers’s picture

Crosspost.

@Bojhan: thanks!

@aspilicious: I'd like to get steps to reproduce from you as well, if you have a different way to reproduce it, that would help significantly in tracing the root cause.

aspilicious’s picture

Status: Postponed (maintainer needs more info) » Active

Clean install. Same as Bojhan. Nothing in the toolbar.

Wim Leers’s picture

#4: And you created some content? Without any content, there is nothing to edit, and the "Edit" tab will not appear.

aspilicious’s picture

I suggest testing yourself. Yes I created content.

1) Clean install
2) Created an article

Wim Leers’s picture

Status: Active » Postponed (maintainer needs more info)
  1. I did a clean D8 HEAD install.
  2. Created an article (while still logged in as uid 1).
  3. The "Edit" tab appears (while still logged in as uid 1), in Chrome & Firefox.
aspilicious’s picture

I can't give you more info than this...
I asked in irc and several people have this problem.
Maybe it's a server issue but I see this on my windows localhost and on a linux server.

Running on php 5.3.13

EDIT:
- css and js gets all loaded

Wim Leers’s picture

Very odd :/

Can you verify in your browser's developer tools that an AJAX request is made to edit/metadata, which should return some JSON similar to this:

{"node:1:field_image:und:full":{"label":"Image","access":true,"editor":"form","aria":"Entity node 1, field Image"},"node:1:body:und:full":{"label":"Body","access":true,"editor":"direct-with-wysiwyg","aria":"Entity node 1, field Body","format":"filtered_html","formatHasTransformations":false},"node:1:field_tags:und:full":{"label":"Tags","access":true,"editor":"form","aria":"Entity node 1, field Tags"}}

I'm on PHP 5.3.8, but I very, very much doubt PHP version differences will cause this.

aspilicious’s picture

I discovered that the button is just hidden: "icon icon-edit edit-nothing-editable-hidden edit-init-processed" when I remove edit-nothing-editable-hidden the button is there.

Wim Leers’s picture

It's always there, but only if something editable exists on the page, it gets unhidden. The JSON of #9 is what tells Edit's JS whether something editable exists on the page.

aspilicious’s picture

Aha found the cause in the inspector:

Fatal error: Call to undefined method Drupal\field\FieldInstance::getFormatter() in /data/sites/drupal8.somethingssomething.dev/www/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php on line 61

aspilicious’s picture

Status: Postponed (maintainer needs more info) » Active

Ok this is all caused by http://drupal.org/node/1852966
Can we have tests for this so we wont break this again in the future?

yched’s picture

Status: Active » Needs review
FileSize
776 bytes

I'm not sure how to write a test for this, but here is the code fix.

yched’s picture

FileSize
1.05 KB

It seems more reasonable to account for the cases where the field is hidden, even though it's not supposed to happen ?

yched’s picture

FileSize
3.65 KB

OK, drop that.

What we need is a formatter plugin_id.
What the current code does is build the data-edit-id value in the original HTML request based on the $view_mode. Then the ajax 'metadata' request has to re-run the same logic as in the intial HTML request to figure "ok, so what was the the formatter used for this field in this entity in this view mode ?".

That's fragile, and currently the code actually fails to reproduce the exact same "view mode --> formatter" logic that happens in EntityRenderController::viewMultiple(). But the view_mode itself is irrelevant here, it's only used to retrieve the formatter.

So, much more robust: at field_preprocess time, we do know the plugin_id of the formatter being used to render the field, we can just put that info in the data-edit-id directly. No need to reproduce some complex logic to retrieve it again in the ajax request.

Wim Leers’s picture

WOOT! Thanks, yched! Much appreciated! I was working on this myself, but failing (I was using entity_get_display()->getComponents() and was not getting any results :/).

The patch in #14 should be sufficient, because if the setting marks a field to be hidden from display, then the no metadata will be requested for it either.

And yes, Edit really needs more tests. I'm working on a test for Edit's metadata aspect right now.

Wim Leers’s picture

In #17, I crossposted.

What you're saying in #16 makes sense, at least on first sight. I'd love to make it simpler, of course :) However, I don't see why the "view mode --> formatter" logic is fragile?

That being said, on second sight, your proposal is insufficient, because the primary reason for choosing to send the "view mode" to the client side is because that is necessary to re-render the field using field_view_field() once a field has been successfully modified through in-place editing. And that function needs $view_mode. You didn't modify that part (EditController.php/fieldForm()) in #16, and because of your other changes in #16, it'd be impossible to pass the view mode to it.

Wim Leers’s picture

Initial unit tests, that would have caused this API change and resulting breakage to be detected by the testbot.

Note that the test can be cleaned up further. Also note that I'm using a mocked access checker because the entity type that the field_test unit tests use is *not* "node", and the Entity Access API for non-nodes is not yet ready, heck, even Node.module doesn't even implement it (#1862750: Implement entity access API for nodes).

yched’s picture

@Wim Leers: the problem is that we're reproducing / duplicating the logic contained in EntityRenderController to route "view mode" to "a formatter used for a field in an entity". And that logic is not trivial and might change (see the discussion in #1875970-11: Pass EntityDisplay objects to the whole entity_view() callstack about displays per entity), so having it in several places for "recompute the formatter to get the metadata" & "recompute the formatter to redisplay the field" is less than ideal.

But ack for the need for view mode. Then yes, #14 or #15 is what we want for now.
I'll try to see if I can think of a way to streamline that.

Status: Needs review » Needs work

The last submitted patch, edit_metadata_fix_plus_tests-1876992-19.patch, failed testing.

Wim Leers’s picture

Title: Toolbar doesn't show the "Edit" tab » Toolbar doesn't show the "Edit" tab: fix by using new entity display settings, add tests
Status: Needs work » Needs review
Issue tags: +Spark
FileSize
14.06 KB

#20: I agree that it's less than ideal, but for me personally (not being an expert in Field API internals, nor knowledgeable with the envisioned target architecture), it's hard to see a clean solution in the current state of the code base. If you say that field_view_field() will accept a formatter, then I'd be happy to get rid of all references to $view_mode! :)

Until that is possible, let us please focus on the bug at hand here (which completely breaks Edit!). I don't want to have both the view mode and formatter type in the field annotations. It'd require (a lot of) changes in the JS too. Let's make that change once we can apply it consistently.

In #19, I said that the tests could be cleaned up further. Well, I've done that now. There's now an EditTestBase class for the common parts.

Status: Needs review » Needs work

The last submitted patch, edit_metadata_fix_plus_tests-1876992-22.patch, failed testing.

Wim Leers’s picture

Odd. I'll reroll tomorrow.

TwoD’s picture

Had to reroll for testing something else, and I'm not sure this is 100% accurate since I can't run the tests right now, but it does fix the issue. Hope you don't mind. ;)

TwoD’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, edit_metadata_fix_plus_tests-1876992-25.patch, failed testing.

yched’s picture

re @Wim #22
Sorry if my #20 was not clear. But sure, #14 is the correct fix, and it's what we should get in.

I'll try to see if I can come with a way to make the three code paths (initial rendering, metadata ajax callback, post-edit field re-rendering) less separate, but that's for another issue.
It's actually not that bad, the three code paths all rely on entity_get_render_display($entity, $view_mode) (= give me the display options to use when rendering this entity in this view mode). It's just that this function might change a bit in the future to allow more flexibility for contrib, and I need to keep the Edit.module use cases in mind.

If you say that field_view_field() will accept a formatter, then I'd be happy to get rid of all references to $view_mode! :)

field_view_field() *does* accept an array of display options (basically a formatter plugin_id + a couple other params including an array of formatter settings) instead of a view mode. But this won't work for your case - you'd need the whole display options array serialized in the data-edit-id string, not just the formatter plugin id. So that's a no go, it has to be field_view_field($view_mode).

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
14.66 KB

#25: Of course I don't mind — thanks :)

#28: Thanks for the confirmation! And yes, I know that field_view_field() accepts an array of display options, but as you already say, that's not the same as a simple formatter plug-in id.

The problem was that I was generating this patch on a system with already other patches committed (locally). My bad. Nothing changed functionally between #22, #25 and this one, except I expect this one to be green. I'm hoping that yched can RTBC It.

Status: Needs review » Needs work
Issue tags: -Spark

The last submitted patch, edit_metadata_fix_plus_tests-1876992-29.patch, failed testing.

yched’s picture

Status: Needs work » Needs review
Issue tags: +Spark
yched’s picture

Status: Needs review » Needs work
+++ b/core/modules/edit/lib/Drupal/edit/MetadataGenerator.phpundefined
@@ -9,6 +9,7 @@
+use Drupal\entity\Plugin\Core\Entity\EntityDisplay;

My bad, but this "use" statement is actually not needed.
Other than that, tests look fine, this should be RTBC.

28 days to next Drupal core point release.

yched’s picture

Status: Needs work » Needs review

Oops, status change was unintentional, but - well, there you go :-)

swentel’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.18 KB
14.15 KB

Looks good to me and it effectively brings back the edit button.

Remove the use statement and changed a comment (80 chars violation, unless that's allowed ?)

Wim Leers’s picture

#32: oh, heh, right! :)
#34: good catch.

This one is good to go!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the fast turnaround on this, folks! Another major bug bites the dust. :)

Committed and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.