Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedThis 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.
Comment #2
jide CreditAttribution: jide commentedI 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.
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedYep, 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.
Comment #4
DrupalGideonIf 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!