2

How to increase the length of the block title of a block?. By default its length is set to 64 characters. Please Help.

Thanks

2 Answers 2

3

That will be tricky. Block titles can only be 64 character. You need to alter the database and make the title field for blocks longer.

Put this in a custom modules .install file.

function mymodule_schema_alter(&$schema) {
  // Change length of title field for block.
  $schema['block']['fields']'title'] = array(
    'type' => 'varchar',
    'length' => 128,
    'not null' => TRUE,
    'default' => '',
    'description' => 'Custom title for the block. (Empty string will use block default title, <none> will remove the title, text will cause block to use specified title.)',
    'translatable' => TRUE,
  );
}

and then alter the block title maxlength attribute in a form alter

$form['block_settings']['title']['#maxlength'] = 128;

Another way is that you put your long title in the content of the block instead of using the "real" block title field.

In Drupal 7 I would hint you to checkout Bean module, but as this is Drupal 6 I'm not sure.

3
  • Although correct, it would be much better to use hook_schema_alter rather than a direct query :)
    – Chapabu
    Jul 31, 2013 at 13:14
  • I've updated the answer to use hook_schema_alter instead. Jul 31, 2013 at 13:20
  • 1
    Now you get an upvote ;-)
    – Chapabu
    Jul 31, 2013 at 13:21
0

I think this is a cleaner way of accomplishing this:

in mymodule.module:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'block_admin_configure') {
    $form['settings']['title']['#maxlength'] = 128;
  }
}

in mymodule.install:

function mymodule_update_1() {
  $alt_spec = array(
    'type' => 'varchar',
    'length' => 128,
    'not null' => FALSE,
  );
  db_change_field('block', 'title', 'title', $alt_spec);
}

Credit goes to the commentors in this thread https://drupal.org/node/664834

Your Answer

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

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