Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-59629

Adding a block fails if layout doesn't have default region set

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.3, 3.5.3, 3.6.1
    • 3.5.4, 3.6.2
    • Blocks, Themes
    • MOODLE_33_STABLE, MOODLE_35_STABLE, MOODLE_36_STABLE
    • MOODLE_35_STABLE, MOODLE_36_STABLE
    • MDL-59629-master
    • Hide
      Setup
      1. Edit theme/boost/config.php and set the 'mydashboard' layout to

            'mydashboard' => array(
                'file' => 'columns2.php',
                'regions' => array(),
                'options' => array('nonavbar' => true, 'langmenu' => true, 'nocontextheader' => true),
            ),
        

      2. Purge caches (just in case).
      Test
      1. Log in as a user and go to your dashboard
      2. Turn editing on.
      3. Add any block.
      4. Confirm that you can successfully add the block that you have chosen.

      Note: Make sure to revert your code changes in the setup phase after the test. (e.g. git reset --hard)

      Show
      Setup Edit theme/boost/config.php and set the ' mydashboard ' layout to 'mydashboard' => array( 'file' => 'columns2.php', 'regions' => array(), 'options' => array('nonavbar' => true, 'langmenu' => true, 'nocontextheader' => true), ), Purge caches (just in case). Test Log in as a user and go to your dashboard Turn editing on. Add any block. Confirm that you can successfully add the block that you have chosen. Note: Make sure to revert your code changes in the setup phase after the test. (e.g. git reset --hard )

    Description

      If one of your layouts doesn't have regions and default regions, then adding blocks will fail with Coding error.
       
      E.g. example of theme config.

        $THEME->layouts = [
            'mydashboard' => array(
            'file' => 'columns2.php',
            'regions' => array(),
            'options' => array('langmenu' => true),
          ];

       
       
      And then error: 
       
      Coding error detected, it must be fixed by a programmer: Trying to reference an unknown block region
      Debug info: 
      Error code: codingerror
      Stack trace: * line 1047 of /lib/blocklib.php: coding_exception thrown

      • line 821 of /lib/blocklib.php: call to block_manager->check_region_is_known()
      • line 892 of /lib/blocklib.php: call to block_manager->add_block()
      • line 1464 of /lib/blocklib.php: call to block_manager->add_block_at_end_of_default_region()
      • line 1390 of /lib/blocklib.php: call to block_manager->process_url_add()
      • line 1545 of /lib/pagelib.php: call to block_manager->process_url_actions()
      • line 975 of /lib/pagelib.php: call to moodle_page->starting_output()
      • line 1087 of /lib/outputrenderers.php: call to moodle_page->set_state()
      • line 164 of /my/index.php: call to core_renderer->header()

      The issue is in add_block_at_end_of_default_region function. We try to get the last element of the not existing element of array, because $defaulregion is null.

      Attachments

        Activity

          People

            peterdias Peter Dias
            dmitriim Dmitrii Metelkin
            Adrian Greeve Adrian Greeve
            Jun Pataleta Jun Pataleta
            Anna Carissa Sadia Anna Carissa Sadia
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan, Huong Nguyen, Bas Brands, Mathew May
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              14/Jan/19

              Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 30 minutes
                30m