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

Copy instance data when copying block instances

    XMLWordPrintable

Details

    • MOODLE_26_STABLE, MOODLE_27_STABLE, MOODLE_28_STABLE
    • MOODLE_29_STABLE
    • MDL-49306-master
    • Hide

      Because no blocks implement the interface we are adding, we will need to hack an existing block. We will use the HTML block.

      Success case

      1. (hack) Add the following function to the HTML block (blocks/html/block_html.php):

            function instance_copy($fromid) {
                return true;
            }
        

      2. Login as admin. Go to "Home / ▶ Site administration / ▶ Appearance / ▶ Default Dashboard page" and click "Blocks editing on"
      3. Add a HTML block to page. Add some content to the block.
      4. Click "Blocks editing off" and click "Dashboard" to take you to the Dashboard page.
      5. Click "Customise this page" then "Reset page to default" and observe that a) there are no errors on the page, and b) the HTML block that you added displays fine (i.e. the content is there).
      6. Before continuing to the next test, click "Reset page to default".

      Fail case

      1. (hack) Change the function you added in the first success case test in blocks/html/block_html.php to be:

            function instance_copy($fromid) {
                return false;
            }
        

      2. Assuming you are still logged in as admin from the previous test, go to the Dashboard page and click "Customise this page" and "Reset page to default".
      3. Observe that there should now be a developer debug error indicating the block instance id's that were attempted to be copied and that block-specific data was unable to be copied.
      Show
      Because no blocks implement the interface we are adding, we will need to hack an existing block. We will use the HTML block. Success case (hack) Add the following function to the HTML block (blocks/html/block_html.php): function instance_copy($fromid) { return true; } Login as admin. Go to "Home / ▶ Site administration / ▶ Appearance / ▶ Default Dashboard page" and click "Blocks editing on" Add a HTML block to page. Add some content to the block. Click "Blocks editing off" and click "Dashboard" to take you to the Dashboard page. Click "Customise this page" then "Reset page to default" and observe that a) there are no errors on the page, and b) the HTML block that you added displays fine (i.e. the content is there). Before continuing to the next test, click "Reset page to default". Fail case (hack) Change the function you added in the first success case test in blocks/html/block_html.php to be: function instance_copy($fromid) { return false; } Assuming you are still logged in as admin from the previous test, go to the Dashboard page and click "Customise this page" and "Reset page to default". Observe that there should now be a developer debug error indicating the block instance id's that were attempted to be copied and that block-specific data was unable to be copied.

    Description

      We have defined some blocks which have specific data that needs to copied to the new instances when a block is copied. Currently there is no mechanism for this to happen. The provided patch allows block to implement a method which is called when a block is copied. This function is an analogue of the functions which are called when a block is created or deleted.

      Attachments

        Activity

          People

            nathanl Nathan Lewis
            nathanl Nathan Lewis
            Dave Cooper Dave Cooper
            Dan Poltawski Dan Poltawski
            John Okely John Okely
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              11/May/15