Hi Guys

There is a big problem with editable_block() changing the structure of the render array for the blocks.

When you are generating a block, or altering one, and add a "#prefix" and a "#suffix" elements to the render array, inside content, what you would expect is Drupal to print them before and after what gets printed from block.tpl.php

Because context gets the "content" of the block and nests it inside a second "content" the prefix and suffix that where intended for the whole block, are now only wrapping the nested "content" element.

structure before editable_block().

  $block->content['#prefix'] = 'fo';
  $block->content['#suffix'] = 'fo';

structure after editable_block().

  $block->content['content']['#prefix'] = 'fo';
  $block->content['content']['#suffix'] = 'fo';

Whats worst is that this will only happen for users who have permission to edit the block, which not only changes your expected output but changes it for some users and not for others.

My question would be, why does the "context" element have to be separated from the "content" element?

Note for committer: When this is committed there needs to be a notice in the release notes for the next version that it changes the array structure as it will possibly break peoples sites if they are working around this current behaviour in their theme.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jm.federico’s picture

PCateNumbersUSA’s picture

I am having the same problem.

tekante’s picture

Adding tag for tracking

tekante’s picture

The main issue is that the content is already rendered so adding a sibling key to content (context in this case) doesn't actually result in that markup being added to the page and when using the inline editor blocks aren't saved. Attached is a patch which moves prefix and suffix as well to see how that works for you.

ttkaminski’s picture

Status: Active » Needs review
FileSize
1.91 KB

I agree that this is a major issue. The problem is that modules and themes that alter the page content need to know, in a deterministic fashion, where the page element occur. If the location of the page elements start moving around based on permissions, things start breaking. The patch in #1 prevents the nesting, which is a step in the right direction, but breaks the inline editing of the context blocks (as mentioned in #4). The patch in #4 doesn't fix anything, because the nesting still happens.

My solution is to implement a theme_wrapper that inserts the proper markup for each block. This handles the case in #4, and does not modify the existing render array stucture. Please review.

rooby’s picture

Status: Needs review » Needs work

This is great.

I added this patch so that I could stop the a tag from being added at all and only then did I realise that I had been working around this problem (my code broke when I added this patch because I was working around the extra content array).

Can someone clarify for me what this link is actually for and when it is used?
It seems to be for inline context editing, am I right?

If so it should not even be added if inline editing is not being used.

I am not using inline editing and these links are never actually visible, but having them in the markup causes me problems (I need to wrap my block content in a link but links in links = bad).

If I'm not way off track I will open a new ticket regarding not adding the link when it shouldn't be added.

Nit pick code review (I think it's probably RTBC after this):

+++ b/plugins/context_reaction_block.inc
@@ -299,15 +299,7 @@ class context_reaction_block extends context_reaction {
-      }
+      $block->content['#theme_wrappers'][] = 'context_block_edit_wrap'; ¶

Trailing space.

+++ b/theme/context_reaction_block.theme.inc
@@ -128,3 +128,11 @@ function template_preprocess_context_block_browser_item(&$vars) {
+/**
+ * Theme wrapper for editable blocks

Comments should end with a full stop.
Theme functions generally should be:
@ingroup themeable

Also, when this is committed there needs to be a notice in the release notes for the next version that it changes the array structure as it will possibly break peoples sites if they are working around this current behaviour.

rooby’s picture

Deleted erroneous post.

rooby’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
2.24 KB

I have made the extremely minor changes mentioned in #6.

Since I didn't actually do any of the functionality for this patch I'm RTBCing it so it can hopefully get more attention and a commit.

rooby’s picture

Issue summary: View changes

Small clarification at the end

tekante’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.91 KB
711 bytes

The patch in 8 (and the patch in 4) suffer from a problem where a block uses a render array for content with a prefix and suffix to wrap it in a div makes the block non positionable using the inline editor. Attached is an adjustment of #8 to change the items selector along with a small module providing blocks of various forms for testing. See if this works for you and if not it would be helpful to amend the test module with a block that demonstrates the structure of any blocks that are still problematic.

rooby’s picture

Status: Needs review » Reviewed & tested by the community

#9 is working for me on a couple of sites.

The changes make sense.

Back to RTBC for maintainer review.

rooby’s picture

Issue summary: View changes

Adding note to the committer about making a notice in the release notes about this change in the next release.

colan’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Committed in f1a8021.

I'll add a note to the release notes.

Status: Fixed » Closed (fixed)

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