1

This is my first time attempting at writing a custom module i had a quick look over the api but forgive me if its wrong

We have been having some small issues regarding the drupal core blocks, the main page content block completely disregards the weigh assigned to it, and we are stumped for clues, no help or ideas have been found from posting on drupal or extensively searching google.

The final option we have is to manually overwrite the weight, i threw this together quickly

 <?php
 funtion hook_block_info_alter() {
$blocks['Main page content'] = array(
    'weight' => ('-9999'),
    );
 }
 ?>

Would that successfully overwrite the weight of the main page content block?

1

Very nearly, but not quite.

  1. You're missing the function arguments in your hook implementation, so there's nothing there to actually alter.
  2. The blocks array is keyed by module, then block delta, so you would need to access the block using those instead of the title as you currently are.
  3. You're trying to overwrite the system main block in it's entirety rather than changing a property on it.
  4. You've spelt function wrong ;)

Try:

function MYMODULE_block_info_alter(&$blocks, $theme, $code_blocks) {
  $blocks['system']['main']['weight'] = -9999;
}
  • Hi thanks for that, you mentioned in point 3 im overwriting it entirely rather than change a value, what would be the correct way of just changing the value? edit wait just read you provided i guess that is right as your selecting the weight from the block and setting it to -9999, rather thank building a new array – James Kirkby Aug 10 '12 at 10:57
  • yep thought so just edited my comment, il try it out and let you know if it works out thanks!! – James Kirkby Aug 10 '12 at 10:59
  • Undoubtably the module is correct but its not forcing the behaviour im expecting, il show you the specific issue bit.ly/NdHAZg from NFASP Network Scotland: Events to the read more link is a custom block from a view Then from A Scottish Studio to join this network. is the main page content. The custom block is being inserted directly after the content title and forcing the main page content to the bottom of the area any ideas as to why this is? – James Kirkby Aug 10 '12 at 11:25
  • Not a clue I'm afraid, except to say that what you describe definitely isn't Drupal's default behaviour, so there must be a custom/contrib module (or theme) causing a problem somewhere. Have you tried disabling your theme to see if the problem still exists? – Clive Aug 10 '12 at 12:19
  • Yes we disabled all additional modules and reverted back to the garland theme still the block completely disregards the weight assigned, we've decided to just sort this out with css for the time being so we can progress, i created an issue with drupal core awaiting a response. but you did help me understand custom modules so thanks for that!! – James Kirkby Aug 10 '12 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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