A question for Gareth J Barnard

A question for Gareth J Barnard

by Mary Evans -
Number of replies: 6
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Gareth,

What does this do and is it necessary? What I mean is could Essential live without it?

  /**
    * Get the HTML for blocks in the given region.
    *
    * @since 2.5.1 2.6
    * @param string $region The region to get HTML for.
    * @return string HTML.
    * Written by G J Barnard
    */

    public function essentialblocks($region, $classes = array(), $tag = 'aside') {
        $classes = (array)$classes;
        $classes[] = 'block-region';
        $attributes = array(
            'id' => 'block-region-'.preg_replace('#[^a-zA-Z0-9_\-]+#', '-', $region),
            'class' => join(' ', $classes),
            'data-blockregion' => $region,
            'data-droptarget' => '1'
        );
        return html_writer::tag($tag, $this->blocks_for_region($region), $attributes);
    }

Thanks

Mary

Average of ratings: -
In reply to Mary Evans

Re: A question for Gareth J Barnard

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Mary,

Its the same as the standard 'blocks()' call but strips out the block regions manipulation code such that you can cope with the LTR / RTL logic in the layout file instead, where perhaps it makes more sense.

So, yes, possibly, but would have to double check the flip / flop logic in the layout files.  But in reality by using it you get the block region you specified rather than another you did not.

It was written originally in Shoelace when we were trying to wrap our minds around the whole LTR / RTL thing about the same time as the 'general.php' to 'columnsX.php' thing.  I cannot remember off the top of my head what Shoelace has now in the same respect - would have to look up.  It is also related to that tracker with the LTR / RTL truth table that was argued over, simplified by others and then later realised that perhaps I was right but things have not quite changed back.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: A question for Gareth J Barnard

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Ok, Shoelace still has it: https://github.com/gjb2048/moodle-theme_shoelace/blob/master/layout/columns3.php - so makes it much easier to debug and understand what is going on without resorting to investigations in the API call stack with an array.  I think that the block regions manipulation code gets used in two places and sometimes gets flipped twice or at least there was a bug where that happened when some code was changed and that happened.  Possibly a bug you were working on Mary and you asked me to look at it.  Anyway, very complicated solution to a problem that can be solved higher up at the expense of a little more complication in the layout file.

In reply to Gareth J Barnard

Re: A question for Gareth J Barnard

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Plus!  By having the logic in the layout file you can react accordingly an set the correct CSS classes on the elements and avoid some of that empty region exists etc. CSS selectors that are in 'bootstrapbase/less/moodle/core'.less' to a lesser or greater extent.

In reply to Gareth J Barnard

Re: A question for Gareth J Barnard

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

OK...I remember the fiasco of the side-pre only layout for bootstrapbase/clean themes. What I cannot get my head round is where did the id="block-region-???" come from? Is that a JavaScript/AJAX addition?

The thing is that in Standard Moodle Themes it uses id="region-pre" or id="region-post" or if you are really wacky like me it would be  id="region-mickey" and/or id="region-mouse" smile

In reply to Mary Evans

Re: A question for Gareth J Barnard

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

To be honest I don't know where the id of 'block-region-???' comes from - just that if you remove it the JS fails sad.  I more of a "region-statler" and "region-waldorf" with a footer area of "region-crazy-harry" type developer ;)