When creating a block view, in admin/build/block, the block delta is a random number (e.g. ac8536acce787695ba4e20e4ec062933), instead of a clean string id (e.g. block-views-myblock-block_1), though when using views_get_view, the delta is correct, so we may have 2 differents deltas for the same view display.

Comments

merlinofchaos’s picture

Status: Active » Closed (works as designed)

This is not a random ID, it's an md5 hash. The reason md5 hash is used here is that it is guaranteed to be 32 characters or less.

The 'delta' field of a block is limited to 32 characters. However, the only guaranteed unique way of identifying a view and a display takes as many as 65 characters (32 characters for the view name, up to 32 characters for the display id, and a character to separate them, which is a dash). If this combination is 33 characters or longer, an md5 hash is used instead. It was the only solution I could come up with that functioned.

If you don't like the md5 hash, use shorter view names.

jide’s picture

I understand now. Now that you say it, it remembers me something, i must have read it somewhere in the docs or in the code. Clever.

This means it is possible to get the md5 from the view id, that's good news !

Thanks for your answer, and obviously for your great work.

merlinofchaos’s picture

Yep, if you check out views_block() you should see the code that does that and you should be able to reproduce the md5 assuming you know the view name and block ID that is needed.

I wish this were cleaner, but it works.

DrupalGideon’s picture

If the block delta is less than 32 characters, how would I use hook_block_view_MODULE_DELTA_alter() ? The hyphen separator can't be used in a function name.

The only way I've gotten around this is making sure my machine name is long so it is hashed, but that really makes for an ugly function name!