18

A Drupal newbie, so correct me if my understand is wrong, but normally, when a Block is created by Views, the machine name of the block is appended to the Views' machine name.

i.e. "article_listing_view-block_1"

When using block_load($module, $block_id) function, the way I've been doing it is to call it thus: $block = block_load("views", "article_listing_view-block_1");

However, for some very odd reason, one particular Block with the machine name:

"flag_comments_as_offensive-block_1"

has a hashed machine ID of:

"92a591f5a81d13a3dd5492f073f9e135"

I say "hashed" because the machine ID changes based directly on the machine-name of the block. If I change it from block_1 to block, it will change, and when I revert back from block to block_1, it will revert the machine ID back to the above. So there's a direct correlation between the machine name and the "hashed" ID it generates.

Instead of calling block_load("views", "machine name"), I have to use the hashed machine ID, which isn't a problem but it did take me a long time to figure out. The way I figured it out was to go into Structure -> Blocks and hover over the "Configure" link and look at the URL. I noticed that all my other Blocks have a URL that included its machine ID, but for this particular block, it was the hashed machine ID. Once I put in the machine ID into block_load, viola, it worked like a charm!

So I guess the question boils down to: What's going on, and why is Drupal hashing my machine name? Is this a bug, or an error on my part?

2 Answers 2

22

This is because the block module expects a 'delta' (block id) up to 32 characters long. But a view block display can have up to 65 characters: up to 32 characters from the view name and 32 characters from the display name and an hyphen '-' between them.

When the delta exceeds the 32 characters limit, Views will hash it through md5 — it is not a random string. You can safely use it for CSS and jQuery selectors.

2
  • most of my answer comes from drupal.org/node/346602 Oct 30, 2011 at 22:41
  • Thanks! I knew it wasn't random, but I wasn't exactly sure what was going on either. This explains it :).
    – Peter
    Oct 30, 2011 at 23:05
4

Views machine names are only hashed if the name is over 32 characters in length.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.