Moodle

Patch to allow a center position for Moodle blocks

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: 1.7
  • Fix Version/s: 2.0
  • Component/s: Blocks
  • Labels:
    None
  • Affected Branches:
    MOODLE_17_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

With this pacth the blocks can be moved to the center column over the sections area.
Using the same arrow icons on edit mode, if you move left a block that is currently at the right position then it will move to the center position.

Few modifications needed:

  • /index.php
    /// aartiles: Added a center blocks position
    if (blocks_have_content($pageblocks, BLOCK_POS_CENTER) || $editing) { blocks_print_group($PAGE, $pageblocks, BLOCK_POS_CENTER); }
  • /lib/blocklib.php
    //aartiles: New block position BLOCK_POS_CENTER
    define('BLOCK_POS_CENTER', 'c');
  • /lib/pagelib.php
    //aartiles: Added new block position BLOCK_POS_CENTER
    function blocks_get_positions() { return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT, BLOCK_POS_CENTER); }

//aartiles: Changes done for complain with a center blocks position
function blocks_move_position(&$instance, $move) {
if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) { return BLOCK_POS_CENTER; } else if($instance->position == BLOCK_POS_CENTER && $move == BLOCK_MOVE_RIGHT) { return BLOCK_POS_RIGHT; } else if ($instance->position == BLOCK_POS_CENTER && $move == BLOCK_MOVE_LEFT) { return BLOCK_POS_LEFT; } else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) { return BLOCK_POS_CENTER; } }
return $instance->position;
}

Issue Links

Activity

Hide
Raül Fernández added a comment -

Great patch Alfredo!
But, can I put the block in the bottom of the page? now the block is positioned at the top of the page...

Raül

Show
Raül Fernández added a comment - Great patch Alfredo! But, can I put the block in the bottom of the page? now the block is positioned at the top of the page... Raül
Hide
Sajith Nair added a comment -

Great Patch.
I was desperatly looking something like this

Sajith

Show
Sajith Nair added a comment - Great Patch. I was desperatly looking something like this Sajith
Hide
Sean Farrell added a comment -

Seems to work in 1.8, but not a couple of extra changes to the course format files, and perhaps some other pages which use blocks

./course/format/weeks/format.php
and
./course/format/topic/format.php

both need an extra bit to match the change to index.php

I wanted to make it appear below the heading and general section, but above the numbered / weeks sections, so tried adding just above the comment marked : 'Now all the normal modules by week'

// sean - http://tracker.moodle.org/browse/MDL-6748
// added bit to move block to centre
if (blocks_have_content($pageblocks, BLOCK_POS_CENTRE) || $editing) { echo '<tr><td colspan="3">'; blocks_print_group($PAGE, $pageblocks, BLOCK_POS_CENTRE); echo '</td></tr>'; echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>'; }
//end of added bit
/// Now all the normal modules by week
/// Everything below uses "section" terminology - each "section" is a week.

similarly for topics but relevant section marked : /// Now all the normal modules by topic

Show
Sean Farrell added a comment - Seems to work in 1.8, but not a couple of extra changes to the course format files, and perhaps some other pages which use blocks ./course/format/weeks/format.php and ./course/format/topic/format.php both need an extra bit to match the change to index.php I wanted to make it appear below the heading and general section, but above the numbered / weeks sections, so tried adding just above the comment marked : 'Now all the normal modules by week' // sean - http://tracker.moodle.org/browse/MDL-6748 // added bit to move block to centre if (blocks_have_content($pageblocks, BLOCK_POS_CENTRE) || $editing) { echo '<tr><td colspan="3">'; blocks_print_group($PAGE, $pageblocks, BLOCK_POS_CENTRE); echo '</td></tr>'; echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>'; } //end of added bit /// Now all the normal modules by week /// Everything below uses "section" terminology - each "section" is a week. similarly for topics but relevant section marked : /// Now all the normal modules by topic
Hide
Denton added a comment -

Here are the following changes that I made to get the center position working for v1.9.4

  • /index.php

/// denton: defined column widths (this may already be defined elsewhere in v1.9.4
/// but I did not end up finding out where

/// Bounds for block widths on this page
define('BLOCK_L_MIN_WIDTH', 120);
define('BLOCK_L_MAX_WIDTH', 120);
define('BLOCK_C_MIN_WIDTH', 400);
define('BLOCK_C_MAX_WIDTH', 600);
define('BLOCK_R_MIN_WIDTH', 120);
define('BLOCK_R_MAX_WIDTH', 120);

/// denton: added $preferred_width_center declaration to existing declarations for left and right

$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
BLOCK_L_MAX_WIDTH);
$preferred_width_center = bounded_number(BLOCK_C_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_CENTER]),
BLOCK_C_MAX_WIDTH);
$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
BLOCK_R_MAX_WIDTH);

/// aartiles: Added a center blocks position
if (blocks_have_content($pageblocks, BLOCK_POS_CENTER) || $editing) { //echo '<td style="width: '.$preferred_width_center.'px;" id="middle-column">'; blocks_print_group($PAGE, $pageblocks, BLOCK_POS_CENTER); //echo '</td>'; }

  • /course/format/weeks/format.php (my changes were for Week view, similar changes will be needed if viewing by Topics)

/// denton: defined centre variables

$lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
$lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
$cmin = (empty($THEME->block_c_min_width)) ? 400 : $THEME->block_c_min_width;
$cmax = (empty($THEME->block_c_max_width)) ? 600 : $THEME->block_c_max_width;
$rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
$rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;

/// denton: added BLOCK_C_MIN_WIDTH and BLOCK_C_MAX_WIDTH

define('BLOCK_L_MIN_WIDTH', $lmin);
define('BLOCK_L_MAX_WIDTH', $lmax);
define('BLOCK_C_MIN_WIDTH', $cmin);
define('BLOCK_C_MAX_WIDTH', $cmax);
define('BLOCK_R_MIN_WIDTH', $rmin);
define('BLOCK_R_MAX_WIDTH', $rmax);

/// denton: added $preferred_width_center

$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
BLOCK_L_MAX_WIDTH);
$preferred_width_center = bounded_number(BLOCK_C_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_CENTER]),
BLOCK_C_MAX_WIDTH);
$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
BLOCK_R_MAX_WIDTH);

/// aartiles: Added a center blocks position
/// denton: here's probably the trickiest part: depending on your theme, you may also want to call a custom divclass
/// (I've called it csl_class) to differentiate between sideblock (for left and right blocks) and the newly
/// created middleblock
/// I've also made changes to my CSS file, which is noted below

if (blocks_have_content($pageblocks, BLOCK_POS_CENTER) || $editing) { echo '<div class = "csl_class">'; blocks_print_group($PAGE, $pageblocks, BLOCK_POS_CENTER); echo '</div>'; }

  • /lib/blocklib.php

/// aartiles: New block position BLOCK_POS_CENTER
define('BLOCK_POS_CENTER', 'c');

  • /lib/pagelib.php

/// aartiles: Added new block position BLOCK_POS_CENTER
function blocks_get_positions() { return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT, BLOCK_POS_CENTER); }

/// aartiles: Changes done for complain with a center blocks position
function blocks_move_position(&$instance, $move) {
if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) { return BLOCK_POS_CENTER; } else if($instance->position == BLOCK_POS_CENTER && $move == BLOCK_MOVE_RIGHT) { return BLOCK_POS_RIGHT; } else if ($instance->position == BLOCK_POS_CENTER && $move == BLOCK_MOVE_LEFT) { return BLOCK_POS_LEFT; } else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) { return BLOCK_POS_CENTER; } }
return $instance->position;
}

  • /theme/theme_name/styles_color.css

/// denton: added the following lines to the end of my css document
/// don't forget to double check your widths and make sure that the right .header background
/// is also added

.csl_class .sideblock .header { width: 490px; }

.csl_class .sideblock .header .title { background:transparent url(images/block_header_center.gif) no-repeat scroll center bottom; min-height:26px; text-align:center; }

.csl_class .sideblock .content { width: 490px; }

.csl_class .sideblock .content .message { text-align: center; }

Notes:

I think I may have overdefined some of the center width variables, but I can't be bothered going back and checking.
To move your block, simply turn editing on and use the arrows!

Thanks again to Alfredo for doing all the hard bits.

Show
Denton added a comment - Here are the following changes that I made to get the center position working for v1.9.4
  • /index.php
/// denton: defined column widths (this may already be defined elsewhere in v1.9.4 /// but I did not end up finding out where /// Bounds for block widths on this page define('BLOCK_L_MIN_WIDTH', 120); define('BLOCK_L_MAX_WIDTH', 120); define('BLOCK_C_MIN_WIDTH', 400); define('BLOCK_C_MAX_WIDTH', 600); define('BLOCK_R_MIN_WIDTH', 120); define('BLOCK_R_MAX_WIDTH', 120); /// denton: added $preferred_width_center declaration to existing declarations for left and right $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH); $preferred_width_center = bounded_number(BLOCK_C_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_CENTER]), BLOCK_C_MAX_WIDTH); $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH); /// aartiles: Added a center blocks position if (blocks_have_content($pageblocks, BLOCK_POS_CENTER) || $editing) { //echo '<td style="width: '.$preferred_width_center.'px;" id="middle-column">'; blocks_print_group($PAGE, $pageblocks, BLOCK_POS_CENTER); //echo '</td>'; }
  • /course/format/weeks/format.php (my changes were for Week view, similar changes will be needed if viewing by Topics)
/// denton: defined centre variables $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width; $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width; $cmin = (empty($THEME->block_c_min_width)) ? 400 : $THEME->block_c_min_width; $cmax = (empty($THEME->block_c_max_width)) ? 600 : $THEME->block_c_max_width; $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width; $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width; /// denton: added BLOCK_C_MIN_WIDTH and BLOCK_C_MAX_WIDTH define('BLOCK_L_MIN_WIDTH', $lmin); define('BLOCK_L_MAX_WIDTH', $lmax); define('BLOCK_C_MIN_WIDTH', $cmin); define('BLOCK_C_MAX_WIDTH', $cmax); define('BLOCK_R_MIN_WIDTH', $rmin); define('BLOCK_R_MAX_WIDTH', $rmax); /// denton: added $preferred_width_center $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH); $preferred_width_center = bounded_number(BLOCK_C_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_CENTER]), BLOCK_C_MAX_WIDTH); $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH); /// aartiles: Added a center blocks position /// denton: here's probably the trickiest part: depending on your theme, you may also want to call a custom divclass /// (I've called it csl_class) to differentiate between sideblock (for left and right blocks) and the newly /// created middleblock /// I've also made changes to my CSS file, which is noted below if (blocks_have_content($pageblocks, BLOCK_POS_CENTER) || $editing) { echo '<div class = "csl_class">'; blocks_print_group($PAGE, $pageblocks, BLOCK_POS_CENTER); echo '</div>'; }
  • /lib/blocklib.php
/// aartiles: New block position BLOCK_POS_CENTER define('BLOCK_POS_CENTER', 'c');
  • /lib/pagelib.php
/// aartiles: Added new block position BLOCK_POS_CENTER function blocks_get_positions() { return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT, BLOCK_POS_CENTER); } /// aartiles: Changes done for complain with a center blocks position function blocks_move_position(&$instance, $move) { if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) { return BLOCK_POS_CENTER; } else if($instance->position == BLOCK_POS_CENTER && $move == BLOCK_MOVE_RIGHT) { return BLOCK_POS_RIGHT; } else if ($instance->position == BLOCK_POS_CENTER && $move == BLOCK_MOVE_LEFT) { return BLOCK_POS_LEFT; } else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) { return BLOCK_POS_CENTER; } } return $instance->position; }
  • /theme/theme_name/styles_color.css
/// denton: added the following lines to the end of my css document /// don't forget to double check your widths and make sure that the right .header background /// is also added .csl_class .sideblock .header { width: 490px; } .csl_class .sideblock .header .title { background:transparent url(images/block_header_center.gif) no-repeat scroll center bottom; min-height:26px; text-align:center; } .csl_class .sideblock .content { width: 490px; } .csl_class .sideblock .content .message { text-align: center; } Notes: I think I may have overdefined some of the center width variables, but I can't be bothered going back and checking. To move your block, simply turn editing on and use the arrows! Thanks again to Alfredo for doing all the hard bits.
Hide
Denton added a comment -

update for v1.9.4

Show
Denton added a comment - update for v1.9.4
Hide
Denton added a comment -

Also wanted to add that I may have made changes to theme/config.php which could affect how this patch works with your setup. I've included it in the zip file

Show
Denton added a comment - Also wanted to add that I may have made changes to theme/config.php which could affect how this patch works with your setup. I've included it in the zip file
Hide
samuel perez added a comment -

Great info.
We had the frontpage configured to show the last 10 messages on news phorum

I was tired of seeing big messages (very long page) introduced by my boos in the news phorum, so I decided that the latest news block was a perfect replace (so it just shows the subject) to put in the central part of the front page, with this information i did it.

thanks!

Show
samuel perez added a comment - Great info. We had the frontpage configured to show the last 10 messages on news phorum I was tired of seeing big messages (very long page) introduced by my boos in the news phorum, so I decided that the latest news block was a perfect replace (so it just shows the subject) to put in the central part of the front page, with this information i did it. thanks!
Hide
luke bridges added a comment -

Have uploaded a 1.9.7 patch to the clone of this issue

Show
luke bridges added a comment - Have uploaded a 1.9.7 patch to the clone of this issue
Hide
luke bridges added a comment -

1.9.8 patch uploaded in clone issue

Show
luke bridges added a comment - 1.9.8 patch uploaded in clone issue
Hide
Martin Dougiamas added a comment -

Moodle 2.0 now supports this properly via page layouts.

Show
Martin Dougiamas added a comment - Moodle 2.0 now supports this properly via page layouts.
Hide
Owen Grubbs added a comment -

How exactly does Moodle 2.0 support this property via page layouts? Can someone give an example? When I select a block for display, I see a screen that asks me what region I want the block to be displayed in, but the only options are Left and Right. Should Center also be an option? The class code seems to indicate that the valid regions come from the theme layout. Can someone point me to documentation for how to make this work. Thanks.

Show
Owen Grubbs added a comment - How exactly does Moodle 2.0 support this property via page layouts? Can someone give an example? When I select a block for display, I see a screen that asks me what region I want the block to be displayed in, but the only options are Left and Right. Should Center also be an option? The class code seems to indicate that the valid regions come from the theme layout. Can someone point me to documentation for how to make this work. Thanks.
Hide
Matthew Pincus added a comment -

I downloaded and installed this patch and I am very happy with it. However, when I'm using the school's computers, after login, the center and right blocks disappear including the edit page button. This happens in both updated versions of firefox and ie and on all school computers. Any suggestions?
Matthew

Show
Matthew Pincus added a comment - I downloaded and installed this patch and I am very happy with it. However, when I'm using the school's computers, after login, the center and right blocks disappear including the edit page button. This happens in both updated versions of firefox and ie and on all school computers. Any suggestions? Matthew
Hide
Pandeeswari added a comment -

Hi, I am using moodle 2.0, this patch is not allowed in moodle2.0. I couldn't find how to make any one of the block in center of the page on moodle. There are default regions are right and left, but we need center also. how can i modify that. can any one help me..? Thanks...

Show
Pandeeswari added a comment - Hi, I am using moodle 2.0, this patch is not allowed in moodle2.0. I couldn't find how to make any one of the block in center of the page on moodle. There are default regions are right and left, but we need center also. how can i modify that. can any one help me..? Thanks...
Hide
Anuraj Anand added a comment -

Center position for moodle blocks(version: moodle 2.2)

On edit mode, click on the move button, then you will be able to move the block to the center position.

Modifications needed:

lib/blocklib.php
//Define new block position.
line 46
define('BLOCK_POS_RIGHT', 'side-post');
+ define('BLOCK_POS_CENTER', 'center');
-------------------------------------------------------------

theme/[your_theme]/layout/general.php
//add the following lines.
line 7
$hassidepost = $PAGE->blocks->region_has_content('side-post', $OUTPUT);
+ $hascenter = $PAGE->blocks->region_has_content('center', $OUTPUT);

line 90-96

<?php echo core_renderer::MAIN_CONTENT_TOKEN ?>
+ <?php if ($hascenter) { ?> + <div class="block-region"> + <div> + <?php echo $OUTPUT->blocks_for_region('center') ?> + </div> + </div> + <?php } ?>
</div>
-------------------------------------------------------------

theme/[your_theme]/config.php
//change the following line (add 'center' to the frontpage regions)

'frontpage' => array(
'file' => 'general.php',
+ 'regions' => array('side-pre', 'center', 'side-post'),
'defaultregion' => 'side-post',
),

Show
Anuraj Anand added a comment - Center position for moodle blocks(version: moodle 2.2) On edit mode, click on the move button, then you will be able to move the block to the center position. Modifications needed: lib/blocklib.php //Define new block position. line 46 define('BLOCK_POS_RIGHT', 'side-post'); + define('BLOCK_POS_CENTER', 'center'); ------------------------------------------------------------- theme/[your_theme]/layout/general.php //add the following lines. line 7 $hassidepost = $PAGE->blocks->region_has_content('side-post', $OUTPUT); + $hascenter = $PAGE->blocks->region_has_content('center', $OUTPUT); line 90-96 <?php echo core_renderer::MAIN_CONTENT_TOKEN ?> + <?php if ($hascenter) { ?> + <div class="block-region"> + <div> + <?php echo $OUTPUT->blocks_for_region('center') ?> + </div> + </div> + <?php } ?> </div> ------------------------------------------------------------- theme/[your_theme]/config.php //change the following line (add 'center' to the frontpage regions) 'frontpage' => array( 'file' => 'general.php', + 'regions' => array('side-pre', 'center', 'side-post'), 'defaultregion' => 'side-post', ),

Dates

  • Created:
    Updated:
    Resolved: