Skip to content
Snippets Groups Projects
Commit a01d869a authored by Marc van Gend's avatar Marc van Gend
Browse files

Issue #1961636 by aaronbauman, marcvangend | ttronslien: Fixed block delta...

Issue #1961636 by aaronbauman, marcvangend | ttronslien: Fixed block delta value lengths grow out of control.
parent 292e8a13
No related branches found
No related tags found
No related merge requests found
<?php
/**
* Implements hook_install().
* Double the maximum length of the delta fields because fieldblock delta's
* can easily get longer than 32 characters.
*/
function fieldblock_install() {
_fieldblock_db_alter_block_delta_length(64);
}
/**
* Implements hook_schema_alter().
* Informs Drupal about the fact that we have altered the database.
*/
function fieldblock_schema_alter(&$schema) {
$schema['block']['fields']['delta']['length'] = 64;
$schema['block_role']['fields']['delta']['length'] = 64;
$schema['block_node_type']['fields']['delta']['length'] = 64;
}
/**
* Implements hook_uninstall().
*/
function fieldblock_uninstall() {
// Restore database alterations.
_fieldblock_db_alter_block_delta_length(32);
// Delete variables.
$entities = entity_get_info();
// Loop over the entity types.
......@@ -45,6 +23,9 @@ function fieldblock_uninstall() {
}
}
/**
* Legacy helper function to undo drupal core schema alter.
*/
function _fieldblock_db_alter_block_delta_length($length) {
// Alter block table.
db_drop_unique_key('block', 'tmd');
......@@ -90,4 +71,16 @@ function _fieldblock_db_alter_block_delta_length($length) {
'primary key' => array('module', 'delta', 'type'),
)
);
}
\ No newline at end of file
}
/**
* Update legacy fieldblock deltas to use md5 identifier.
* Reset drupal core block schema.
*/
function fieldblock_update_7100() {
$blocks = db_query("SELECT bid, delta FROM {block} WHERE module = 'fieldblock'");
foreach ($blocks as $block) {
db_query("UPDATE {block} SET delta = :new_delta WHERE bid = :bid AND delta = :old_delta AND module = 'fieldblock'", array(':new_delta' => md5($block->delta), ':bid' => $block->bid, ':old_delta' => $block->delta));
}
_fieldblock_db_alter_block_delta_length(32);
}
......@@ -116,7 +116,7 @@ function fieldblock_get_block_list() {
// Loop over the fields defined in the variable.
foreach ($fieldblock_settings as $field_name => $field_label) {
// Build the fieldblock info.
$fieldblock_id = $variable_name .'-'. $field_name;
$fieldblock_id = md5($variable_name .'-'. $field_name);
$fieldblocks[$fieldblock_id] = t('@field field (from @type: @bundle: @view_mode)', array(
'@field' => $instances[$entity_type][$bundle][$field_name]['label'],
'@type' => $entity_type,
......@@ -149,6 +149,7 @@ function fieldblock_block_view($delta = '') {
$fieldblocks_storage[$delta]['#label_display'] = 'hidden';
}
$block['content'] = $fieldblocks_storage[$delta];
$block['fieldblock_name'] = $fieldblocks_storage[$delta]['fieldblock_name'];
}
return $block;
......@@ -184,9 +185,20 @@ function fieldblock_field_attach_view_alter(&$output, $context) {
// and store the field's render array for later use.
foreach ($fieldblock_settings as $field_name) {
if (isset($output[$field_name])) {
$fieldblock_id = $variable_name .'-'. $field_name;
$fieldblock_name = $variable_name .'-'. $field_name;
$fieldblock_id = md5($fieldblock_name);
$fieldblocks_storage[$fieldblock_id] = $output[$field_name];
hide($output[$field_name]);
$fieldblocks_storage[$fieldblock_id]['fieldblock_name'] = $fieldblock_name;
}
}
}
/**
* Give fieldblocks a meaningful html id in spite of the hashed block deltas.
*/
function fieldblock_preprocess_block(&$variables) {
if ($variables['block']->module == 'fieldblock') {
$variables['block_html_id'] = drupal_html_id('block-' . $variables['block']->fieldblock_name);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment