Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Dave Reid’s picture

Status: Active » Needs review
Issue tags: +Crazy-ass wackiness
Dave Reid’s picture

Status: Needs review » Needs work

This needs to also run _block_get_renderable_array() after running _block_render_blocks().

lee20’s picture

Subscribing to this crazy-ass wackiness! Looking to use block tokens to embed blocks, views, etc directly into node content using the token filter module. Might take a stab at a revised patch if I get to it.

Dave Reid’s picture

Title: Block tokens » Embed block tokens

Realizing that I'm probably going to move this to an [embed:*] or [insert:*] namespace for tokens since we need to reserve [block:*] for if we're running token replacement about a specific block.

Dave Reid’s picture

I'm also wondering if these embedable token should be put into Token filter.

ocamp’s picture

hey, just wondering whats happened to this?

Is it a module or not?

Thanks

jpstrikesback’s picture

+1 is better than a follow in this instance

nitrospectide’s picture

I was looking for just this solution. It doesn't look like this ever made it into Token or Token Filter. Anyone know?

Is it in any of the dev modules?

jpstrikesback’s picture

This needs to also run _block_get_renderable_array() after running _block_render_blocks().

Why is that?

jpstrikesback’s picture

Oooooh, for titles and contextual links and goodies...this is rather sick...trying some stuff to get that in

jpstrikesback’s picture

And let's see if this does it

jpstrikesback’s picture

Status: Needs work » Needs review
jpstrikesback’s picture

Quick change so that the list of tokens includes user created blocks

Status: Needs review » Needs work

The last submitted patch, 776952-token-blocks-D7-14.patch, failed testing.

jpstrikesback’s picture

Never mind that last patch, late evening haze (was working in the wrong local token folder)

nitrospectide’s picture

jpstrikesback: Does this sudden flurry of activity mean a patch against the current version might be forthcoming?

Dave Reid: If the patch is good, is there a chance of this being rolled into dev?

jpstrikesback’s picture

Nitrospectide: that one in #12 is against the latest dev, give it a shot, seems to work well

nitrospectide’s picture

jpstrikesback: What I'm most interested in right now is the user created blocks. It looks like your #14 includes that.

jpstrikesback’s picture

Actually #12 does it fine, I just didn't see the results in the token list until a few cache clears later. #14 is a dud :)

pfrilling’s picture

The patch in #12 is working for me.

jpstrikesback’s picture

Status: Needs work » Needs review

@Dave Reid : Any thoughts on #12?

jpstrikesback’s picture

#12: 776952-token-blocks-D7-12.patch queued for re-testing.

Deciphered’s picture

Status: Needs review » Needs work
+++ b/token.tokens.incundefined
@@ -17,6 +17,21 @@ function token_token_info_alter(&$info) {
+    'description' => t('Use the blocks in your site as tokens. CRAZY!'),

I think we can lose the excitement, as great as this functionality is the description doesn't need it.

+++ b/token.tokens.incundefined
@@ -913,6 +928,35 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
+      $blocks[] = block_load($module, $delta);

This, along with other code, puts an unnecessary dependency on the Block module. I'll take a swing at removing this dependency as 9 times out of 10 I will have the Block module disabled as Context works better.

Deciphered’s picture

Status: Needs work » Needs review
FileSize
2.34 KB

While maybe not the best solution, this is the quickest, basically I wrapped the Blocks token code with a conditional that checks if the Block module is enabled or if not if it can include the block.module file, given that the Block module is always going to be present (unless someone patches core) it will work.

Otherwise, the solution requires a lot more code to be written to reproduce the functionality of the block module (as Context has done) which is less than ideal.

Status: Needs review » Needs work

The last submitted patch, block_tokens-776952-25.patch, failed testing.

Deciphered’s picture

Status: Needs work » Needs review
FileSize
2.15 KB

Ok, so I'm sure the changes I made shouldn't have caused the tests to fail, I tested it locally and the tests don't seem to work so well either... but failing in things that had absolutely no relevance to the changes I made.

However, I did fail in my local testing, due to what I was testing the token with I failed to notice I was getting a cached result, so it looked like everything was working perfectly with the Block module turned off but it turned out not to be the case.

I've updated the patch with just a simple condition to check for the Block module, so for the moment the functionality will require the Block module, but I will look at changing that as I think this could be extremely awesome, but I think the dependency on the Block module is completely unnecessary.

Deciphered’s picture

Ok, this time for sure, this patch adds the ability to use Block tokens with or without the Block module, it's a mix of the existing code and the approach taken by the Context block reaction code, tests all passed locally and manual testing worked a charm.

Included is an interdiff from the patch at #12.

Deciphered’s picture

It's worth taking into account, the first part of the interdiff, the invocation of _block_rehash(), is something that's needed regardless of making this functionality work without the Block module, if you where to disable and uninstall the Block module and then re-enable and then proceed to try to process any block tokens without going to the Block configuration page then the block_load() function won't have enough information and cause the current functionality to fail.

jcisio’s picture

Status: Needs review » Needs work

I think #27 is in fact better than #28. The trick in #28 while being optimized, duplicates code, makes it unnecessarily difficult to understand, maintain or update.

Deciphered’s picture

@jcisio,

#28 doesn't duplicate code, it adds some additional code based on other concepts, not duplicated code, so that anyone who's not using the Blocks module can still have the blocks rendered via Token, which I believe is very important.

If you think the changes I made are difficult to understand I'd be happy to document them a little better:

 

+    $theme_key = variable_get('theme_default', 'garland');
+    module_load_include('module', 'block', 'block');
+    if (module_exists('block')) {
+      _block_rehash($theme_key);
+    }
+

Most of this needs to be in regardless of making the code work without the Block module, because if the Block module is only just installed and the Block page hasn't been visited then the block_load() won't work properly without _block_rehash() having been run first.

 

-      $blocks[] = block_load($module, $delta);
+      if (module_exists('block')) {
+        $block = block_load($module, $delta);
+      }
+      else {
+        $block = new stdClass;
+        $block->module = $module;
+        $block->delta = $delta;
+        $block->title = '';
+      }
+      $blocks[] = $block;

This is pretty straight forward, if the block module is active then the $block data is pulled from block_load(), otherwise we just stub the $block data manually.

 

+          if (!module_exists('block') && isset($build["{$module}_{$delta}"]['#theme_wrappers'])) {
+            foreach ($build["{$module}_{$delta}"]['#theme_wrappers'] as $key => $value) {
+              if ($value == 'block') {
+                unset($build["{$module}_{$delta}"]['#theme_wrappers'][$key]);
+              }
+            }
+          }

If the Block module isn't enabled and the prepared block element has 'block' as a theme wrapper we remove it otherwise the render process will fail.

 

I don't think that's all that difficult to understand or maintain, but I'm open to alternatives, however I'm not so open to restricting this functionality to only being available for use when the Block module is present, especially when it was so simple to make it work without it.

sime’s picture

path #28 looks cool :)

Pol’s picture

Status: Needs work » Needs review

Patch #28 working.

milesw’s picture

Patch #28 working for me as well. Very useful, thanks!

Pol’s picture

Status: Needs review » Reviewed & tested by the community
Vacilando’s picture

Issue summary: View changes

#28 working nicely; ready to apply to the dev version!

JieXiannn’s picture

So what do you advise an interested user or Bad behavior who's also faceing to do? Wait for a new Bad Behavior dev version? Or wait for a new D7 core update?

Thank you

sol0matrix80’s picture

ive been using this for about 5-6 months now without any issues that i can detect why its not in the current dev version did any one find a problem with it ?

dxx’s picture

Working good for me, ready for include patch in dev release?

mibfire’s picture

It would be good if this could be merged into master finally after 4 years.

Vacilando’s picture

Bump; this is RTBC for over 2 years. Please.

bohemier’s picture

Agreed. Thanks for looking into merging this...

rooby’s picture

A cool addition to this would be tokens like

$module:$delta:subject
$module:$delta:content

To add just parts of the block.

I'd be happy to create follow up tickets though instead of adding to this patch if that is preferred.

drnikki’s picture

I'm guessing since this isn't yet merged into 7 there's no activity on getting this same functionality ready in 8? If there's work being done on an 8.x version (I can't find any), I'd love to help out.

Dave Reid’s picture

Drupal 8 blocks can be embedded using Entity Embed.

ugintl’s picture

FileSize
6.68 KB

Anybody using statuses module? I want to show embedded status update when user shares other user's update. Currently, statuses module allows to use replacement tokens to be used from admin ui and by default, it has @name and @message, which is replaced by the username and status update text of the shared update. Instead of text, I want to show embedded status update. I have tried replacing @message with @status and @message_formatted and @status_themed, but nothing working. I have uploaded the statuses.token.inc file.

Chris Matthews’s picture

Assigned: Dave Reid » Unassigned
Issue tags: -Crazy-ass wackiness

The 7 year old patch in #28 still applied cleanly. The 7.x branch definitely needs some love.