This module works well when one field is marked as a block, but when I've assigned two or more fields in one content type to be blocks I got the following error when going to configure the block (/admin/structure/block)
PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'delta' at row 1:
INSERT INTO {block} (module, delta, theme, status, weight, region, pages, cache) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => fieldblock [:db_insert_placeholder_1] => fieldblock-node-undergraduate_programs-default-field_my_career_major [:db_insert_placeholder_2] => lakehead [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => -1 [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => 4 ) in drupal_write_record() (line 7106 of PATH/includes/common.inc).
PATH has the actual path of the common.inc file
The error no longer exist if I drop back to only one field being a block.
Drupal Core to 7.21
Comment | File | Size | Author |
---|---|---|---|
#3 | fieldblock-delta-hashes-1961636-3.patch | 3.83 KB | marcvangend |
#2 | fieldblock-fix_delta_lengths-1961636.patch | 2.67 KB | AaronBauman |
Comments
Comment #1
AaronBaumanthis is not actually related to the number of field blocks, rather the length of the fieldblock's delta.
'fieldblock-'. $entity_type .'-'. $bundle .'-'. $view_mode . '-' . $field_name
can easily go over 32 characters, needs to be truncated and unique-ified in a different way.Unfortunately, since block delta column definition is unlikely to change, this may mean a join table for fieldblock identifier / block delta.
edit:
looking at the .install file, i see this module already alters the core block table to delta = 64.
However, the delta above is length 69, and has potential to grow even longer:
"fieldblock" - 10
entity_type - (no limit?)
bundle - 32
view_mode - 32
field_name - 32
---------------------
106 + ?
Comment #2
AaronBaumanAttached patch changes fieldblock deltas to md5() identifiers, implements fieldblock_update_1() to change existing deltas to md5()s, reverts changes to drupal core schema, and gets rid of hook_install() and hook_schema_alter()
Comment #3
marcvangendThanks for your patch, Aaron, and my apologies that it took me so long to review it.
When I wrote the module, I noticed that the block deltas could easily grow beyond 32 characters. I was hoping that 64 would be enough, but you proved me wrong :-)
Your patch didn't completely work for me: the blocks didn't show up on the page anymore. This happened because the field's render arrays were still stored in the static cache under their old deltas instead of their hash strings.
Although I regret that this solution will turn human-readable block deltas into cryptic md5 hashes, I think it's the best option we have. I decided to implement the MODULENAME_preprocess_block function to keep at least human-readable html id's.
Here's my new patch, I would appreciate your review.
Comment #4
AaronBaumanworks for me.
the preprocess_block function is a nice touch.
Comment #5
marcvangendThanks. I'll roll a new release asap.
Comment #6
marcvangendCommitted and pushed. New stable release coming up.