Moodle
  1. Moodle
  2. MDL-31777

Switch block's columns when course is set to RTL Mode (Hebrew, Arabic or Farsi languages)

    Details

    • Rank:
      38388

      Description

      Block columns should switch sides in RTL Mode (Hebrew, Arabic, Farsi... languages)

        Issue Links

          Activity

          Hide
          Nadav Kavalerchik added a comment - - edited

          @Mary,
          Please have a look

          Also, It seems, I should apply a similar patch to all themes since they have similar layout/general.php file with some differences in each theme.

          What do you think? Is there a more elegant way to do this?

          Show
          Nadav Kavalerchik added a comment - - edited @Mary, Please have a look Also, It seems, I should apply a similar patch to all themes since they have similar layout/general.php file with some differences in each theme. What do you think? Is there a more elegant way to do this?
          Hide
          Mary Evans added a comment -

          I've just assigned this to you.

          The body class looks OK but not sure about the changes in the main layout for region-pre and region-post. Why not do something like...

          IF has side pre AND is rtl
          THEN OUTPUT side post

          Because all you want to do is swap sides isn't it?

          Show
          Mary Evans added a comment - I've just assigned this to you. The body class looks OK but not sure about the changes in the main layout for region-pre and region-post. Why not do something like... IF has side pre AND is rtl THEN OUTPUT side post Because all you want to do is swap sides isn't it?
          Hide
          Nadav Kavalerchik added a comment -

          I got funny errors when i tried

          IF has side pre AND is rtl 
          THEN OUTPUT side post
          

          $OUTPUT->blocks_for_region('side-pre'); did not display anything when I was in RTL and "has side post".
          Maybe I was not considering something.
          I'd love if you or someone else can suggest a better code

          How about the other themes, Am i right?

          Show
          Nadav Kavalerchik added a comment - I got funny errors when i tried IF has side pre AND is rtl THEN OUTPUT side post $OUTPUT->blocks_for_region('side-pre'); did not display anything when I was in RTL and "has side post". Maybe I was not considering something. I'd love if you or someone else can suggest a better code How about the other themes, Am i right?
          Hide
          Mary Evans added a comment -

          Each theme would need to be changed separately, as they all use their own particular layout file, which will be a big job to do. However, it might be easier to do this in moodle/lib/outputrenderers.php then this could be done in Moodle core and each theme would output the relevent code as required. Which would...if this can be done, make for a better solution.

          So what we need is to create a function that recognises that the site is dir-rtl so output for side-pre = $OUTPUT->blocks_for_region('side-post');
          and
          output for side-post = $OUTPUT->blocks_for_region('side-pre');

          But I don't know enough about Moodle to know if this can be done, or if it is in the correct place to do this.

          Does this sound feasible?

          Show
          Mary Evans added a comment - Each theme would need to be changed separately, as they all use their own particular layout file, which will be a big job to do. However, it might be easier to do this in moodle/lib/outputrenderers.php then this could be done in Moodle core and each theme would output the relevent code as required. Which would...if this can be done, make for a better solution. So what we need is to create a function that recognises that the site is dir-rtl so output for side-pre = $OUTPUT->blocks_for_region('side-post'); and output for side-post = $OUTPUT->blocks_for_region('side-pre'); But I don't know enough about Moodle to know if this can be done, or if it is in the correct place to do this. Does this sound feasible?
          Hide
          Mary Evans added a comment - - edited

          Thinking about this some more...perhaps something simpler may work...

          in moodle/blocklib.php we can re-define the BLOCKS

          from this

          /**#@+
           * Default names for the block regions in the standard theme.
           */
          define('BLOCK_POS_LEFT',  'side-pre');
          define('BLOCK_POS_RIGHT', 'side-post');
          /**#@-*/
          

          to this

          /**#@+
           * Default names for the block regions in the standard theme.
           */
          if $PAGE->right_to_left(){
              define('BLOCK_POS_LEFT',  'side-post');
              define('BLOCK_POS_RIGHT', 'side-pre');
          }else{
              define('BLOCK_POS_LEFT',  'side-pre');
              define('BLOCK_POS_RIGHT', 'side-post');
          }
          /**#@-*/
          

          If only it was that simple!!!

          Show
          Mary Evans added a comment - - edited Thinking about this some more...perhaps something simpler may work... in moodle/blocklib.php we can re-define the BLOCKS from this /**#@+ * Default names for the block regions in the standard theme. */ define('BLOCK_POS_LEFT', 'side-pre'); define('BLOCK_POS_RIGHT', 'side-post'); /**#@-*/ to this /**#@+ * Default names for the block regions in the standard theme. */ if $PAGE->right_to_left(){ define('BLOCK_POS_LEFT', 'side-post'); define('BLOCK_POS_RIGHT', 'side-pre'); } else { define('BLOCK_POS_LEFT', 'side-pre'); define('BLOCK_POS_RIGHT', 'side-post'); } /**#@-*/ If only it was that simple!!!
          Hide
          Nadav Kavalerchik added a comment -

          Thank you for the ideas.
          I will look into them

          Show
          Nadav Kavalerchik added a comment - Thank you for the ideas. I will look into them
          Hide
          Mary Evans added a comment -

          I have just tried this...

          /**#@+
           * Default names for the block regions in the standard theme.
           */
          if (right_to_left()) {
              define('BLOCK_POS_LEFT',  'side-post');
              define('BLOCK_POS_RIGHT', 'side-pre');
          }else{
              define('BLOCK_POS_LEFT',  'side-pre');
              define('BLOCK_POS_RIGHT', 'side-post');
          }
          /**#@-*/
          

          But it did not appear to do anything...so we need to find what happens to the blocks after this section...ummm

          Show
          Mary Evans added a comment - I have just tried this... /**#@+ * Default names for the block regions in the standard theme. */ if (right_to_left()) { define('BLOCK_POS_LEFT', 'side-post'); define('BLOCK_POS_RIGHT', 'side-pre'); } else { define('BLOCK_POS_LEFT', 'side-pre'); define('BLOCK_POS_RIGHT', 'side-post'); } /**#@-*/ But it did not appear to do anything...so we need to find what happens to the blocks after this section...ummm
          Hide
          Mary Evans added a comment -

          Hi Nadav,
          I think I have cracked it! This works just as you want it to.

                          <?php if ($hassidepre) { ?>
                          <div id="region-pre" class="block-region">
                             <div class="region-content">
                                <?php
                                if (right_to_left()) {
                                    echo $OUTPUT->blocks_for_region('side-post');
                                } else {
                                    echo $OUTPUT->blocks_for_region('side-pre');
                             } ?>
          
                             </div>
                          </div>
                          <?php } ?>
          
                          <?php if ($hassidepost) { ?>
                          <div id="region-post" class="block-region">
                             <div class="region-content">
                                <?php
                                if (right_to_left()) {
                                    echo $OUTPUT->blocks_for_region('side-pre');
                                } else {
                                    echo $OUTPUT->blocks_for_region('side-post');
                             } ?>
                             </div>
                          </div>
                          <?php } ?>
          

          Nothing else is needed...no need to fix bodyclasses as the container stays and is styled as it is regardless of content, since the only thing that is moving is the content $OUTPUT so this is simplcity itself, and one wonders why this has not been done before.

          Anyway I have developed a new theme called 'rtlbase' which I have just added this fix to. I'll email you a copy to test.
          Cheers
          Mary

          Show
          Mary Evans added a comment - Hi Nadav, I think I have cracked it! This works just as you want it to. <?php if ($hassidepre) { ?> <div id= "region-pre" class= "block-region" > <div class= "region-content" > <?php if (right_to_left()) { echo $OUTPUT->blocks_for_region('side-post'); } else { echo $OUTPUT->blocks_for_region('side-pre'); } ?> </div> </div> <?php } ?> <?php if ($hassidepost) { ?> <div id= "region-post" class= "block-region" > <div class= "region-content" > <?php if (right_to_left()) { echo $OUTPUT->blocks_for_region('side-pre'); } else { echo $OUTPUT->blocks_for_region('side-post'); } ?> </div> </div> <?php } ?> Nothing else is needed...no need to fix bodyclasses as the container stays and is styled as it is regardless of content, since the only thing that is moving is the content $OUTPUT so this is simplcity itself, and one wonders why this has not been done before. Anyway I have developed a new theme called 'rtlbase' which I have just added this fix to. I'll email you a copy to test. Cheers Mary
          Hide
          Nadav Kavalerchik added a comment -

          Beautiful

          Have you tested it with pages that has only side-pre or only side-post?
          I remember i had issues with those situation while i was getting to the final code to work smoothly.

          btw, see if you can change the rtlbase to basertl, so it will be listed just after the base theme on the file system.
          might be nicer?

          Still, i guess i will have to go through the themes and patch them too.

          Show
          Nadav Kavalerchik added a comment - Beautiful Have you tested it with pages that has only side-pre or only side-post? I remember i had issues with those situation while i was getting to the final code to work smoothly. btw, see if you can change the rtlbase to basertl, so it will be listed just after the base theme on the file system. might be nicer? Still, i guess i will have to go through the themes and patch them too.
          Hide
          Mary Evans added a comment -

          I'll do some more testing.

          Yes to name change...that makes sense

          Show
          Mary Evans added a comment - I'll do some more testing. Yes to name change...that makes sense
          Hide
          Michael de Raadt added a comment -

          Thanks for working on this, Nadav and Mary.

          Show
          Michael de Raadt added a comment - Thanks for working on this, Nadav and Mary.

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: