https://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&feed=atom&action=historyDeveloper Area/Development Tutorials/Basic blocktype plugin - Revision history2024-03-29T13:34:37ZRevision history for this page on the wikiMediaWiki 1.35.10https://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&diff=7260&oldid=prevAaronw: /* If your block stores data in external tables... */2015-12-16T04:06:59Z<p><span dir="auto"><span class="autocomment">If your block stores data in external tables...</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 04:06, 16 December 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l260" >Line 260:</td>
<td colspan="2" class="diff-lineno">Line 260:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If your block stores data in external tables and this data needs to be copied to the new blocktype, then your options are limited. Unfortunately BlockInstance->copy() doesn't have a hook method that is invoked after the new block instance gets committed to the database and assigned an ID. (See forum discussion: https://mahara.org/interaction/forum/topic.php?id=7448#post30077 ). If you'd like to implement a post-blockinstance-commit hook method (it should probably go at the end of Blockinstance->copy() right after it calls $newblockinstance->commit() ), then please upstream it! ;)</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If your block stores data in external tables and this data needs to be copied to the new blocktype, then your options are limited. Unfortunately BlockInstance->copy() doesn't have a hook method that is invoked after the new block instance gets committed to the database and assigned an ID. (See forum discussion: https://mahara.org/interaction/forum/topic.php?id=7448#post30077 ). If you'd like to implement a post-blockinstance-commit hook method (it should probably go at the end of Blockinstance->copy() right after it calls $newblockinstance->commit() ), then please upstream it! ;)</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>If you don't want to do that, then your best option is to use an [[Developer_Area/Events_API|event handler]]. BlockInstance->commit() fires a "blockinstancecommit" event each time a block instance is created or updated, and it passes the BlockInstance object as its parameter. So, in your rewrite_blockinstance_extra_config() method you could add the extra data to the BlockInstance object that is passed in, and then in your event handler, look for that extra data and use it to create the necessary records in the database. Bear in mind this event handler is called <del class="diffchange diffchange-inline">for </del>any block <del class="diffchange diffchange-inline">update </del>or <del class="diffchange diffchange-inline">instert, not just for copies</del>. So <del class="diffchange diffchange-inline">it should </del>check <del class="diffchange diffchange-inline">to see </del>whether the <del class="diffchange diffchange-inline">data you added in rewrite_blockinstance_extra_config() </del>is <del class="diffchange diffchange-inline">present</del>, and <del class="diffchange diffchange-inline">if not, </del>it <del class="diffchange diffchange-inline">should exit without doing anything</del>.</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>If you don't want to do that, then your best option is to use an [[Developer_Area/Events_API|event handler]]. BlockInstance->commit() fires a "blockinstancecommit" event each time a block instance is created or updated, and it passes the BlockInstance object as its parameter. So, in your rewrite_blockinstance_extra_config() method you could add the extra data to the BlockInstance object that is passed in, and then in your event handler, look for that extra data and use it to create the necessary records in the database. Bear in mind this event handler is called <ins class="diffchange diffchange-inline">every time '''</ins>any<ins class="diffchange diffchange-inline">''' </ins>block <ins class="diffchange diffchange-inline">is updated </ins>or <ins class="diffchange diffchange-inline">inserted</ins>. So <ins class="diffchange diffchange-inline">before doing anything else, your event handler will need to </ins>check whether the <ins class="diffchange diffchange-inline">BlockInstance </ins>is <ins class="diffchange diffchange-inline">of the right blocktype</ins>, and <ins class="diffchange diffchange-inline">whether </ins>it <ins class="diffchange diffchange-inline">is a newly-copied block</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function export_blockinstance_config()===</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function export_blockinstance_config()===</div></td></tr>
</table>Aaronwhttps://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&diff=7259&oldid=prevAaronw: /* (optional) function rewrite_blockinstance_extra_config() */2015-12-16T04:05:50Z<p><span dir="auto"><span class="autocomment">(optional) function rewrite_blockinstance_extra_config()</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 04:05, 16 December 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l256" >Line 256:</td>
<td colspan="2" class="diff-lineno">Line 256:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This method is called '''before''' the new block is saved into the database, so you will not know the new block's ID yet, and consequently this method should not insert records directly into the database. It is mostly useful for altering the contents of the configdata.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This method is called '''before''' the new block is saved into the database, so you will not know the new block's ID yet, and consequently this method should not insert records directly into the database. It is mostly useful for altering the contents of the configdata.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>If your block stores data in external tables<del class="diffchange diffchange-inline">, </del>and this data needs to be copied to the new blocktype, then your options are limited. Unfortunately BlockInstance->copy() doesn't have a hook method that is invoked after the new block instance gets committed to the database and assigned an ID. (See forum discussion: https://mahara.org/interaction/forum/topic.php?id=7448#post30077 ). If you'd like to implement a post-blockinstance-commit hook method (it should probably go at the end of Blockinstance->copy() right after it calls $newblockinstance->commit() ), then please upstream it! ;)</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">==== If your block stores data in external tables... ====</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>If your block stores data in external tables and this data needs to be copied to the new blocktype, then your options are limited. Unfortunately BlockInstance->copy() doesn't have a hook method that is invoked after the new block instance gets committed to the database and assigned an ID. (See forum discussion: https://mahara.org/interaction/forum/topic.php?id=7448#post30077 ). If you'd like to implement a post-blockinstance-commit hook method (it should probably go at the end of Blockinstance->copy() right after it calls $newblockinstance->commit() ), then please upstream it! ;)</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you don't want to do that, then your best option is to use an [[Developer_Area/Events_API|event handler]]. BlockInstance->commit() fires a "blockinstancecommit" event each time a block instance is created or updated, and it passes the BlockInstance object as its parameter. So, in your rewrite_blockinstance_extra_config() method you could add the extra data to the BlockInstance object that is passed in, and then in your event handler, look for that extra data and use it to create the necessary records in the database. Bear in mind this event handler is called for any block update or instert, not just for copies. So it should check to see whether the data you added in rewrite_blockinstance_extra_config() is present, and if not, it should exit without doing anything.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you don't want to do that, then your best option is to use an [[Developer_Area/Events_API|event handler]]. BlockInstance->commit() fires a "blockinstancecommit" event each time a block instance is created or updated, and it passes the BlockInstance object as its parameter. So, in your rewrite_blockinstance_extra_config() method you could add the extra data to the BlockInstance object that is passed in, and then in your event handler, look for that extra data and use it to create the necessary records in the database. Bear in mind this event handler is called for any block update or instert, not just for copies. So it should check to see whether the data you added in rewrite_blockinstance_extra_config() is present, and if not, it should exit without doing anything.</div></td></tr>
</table>Aaronwhttps://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&diff=7258&oldid=prevAaronw: /* (optional) function rewrite_blockinstance_extra_config() */2015-12-16T04:05:13Z<p><span dir="auto"><span class="autocomment">(optional) function rewrite_blockinstance_extra_config()</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 04:05, 16 December 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l252" >Line 252:</td>
<td colspan="2" class="diff-lineno">Line 252:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function rewrite_blockinstance_extra_config()===</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function rewrite_blockinstance_extra_config()===</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>This function is called at the end of doing a "shallow" or "full" copy of a block. If your <del class="diffchange diffchange-inline">blocktype stores data in custom tables, </del>or <del class="diffchange diffchange-inline">has data that </del>needs to <del class="diffchange diffchange-inline">be </del>rewritten in <del class="diffchange diffchange-inline">a way that </del>the <del class="diffchange diffchange-inline">other </del>copy <del class="diffchange diffchange-inline">methods don't properly handle</del>, then you <del class="diffchange diffchange-inline">can </del>implement this function to <del class="diffchange diffchange-inline">copy </del>that <del class="diffchange diffchange-inline">information across. Specifically, this function receives a copy of the new block's object, by reference</del>.</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>This function is called at the end of doing a "shallow" or "full" copy of a block. If your <ins class="diffchange diffchange-inline">block is copied by "shallow" </ins>or <ins class="diffchange diffchange-inline">"full" and </ins>needs to <ins class="diffchange diffchange-inline">have its data </ins>rewritten in <ins class="diffchange diffchange-inline">ways beyond what </ins>the <ins class="diffchange diffchange-inline">standard BlockInstance-></ins>copy<ins class="diffchange diffchange-inline">() method does in those cases</ins>, then you <ins class="diffchange diffchange-inline">may </ins>implement this function to <ins class="diffchange diffchange-inline">help with </ins>that.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>This method is called '''before''' the new block is saved into the database, so you will not know the new block's ID yet, and consequently this method should not insert records directly into the database. <del class="diffchange diffchange-inline">Instead, you can use one or both </del>of <del class="diffchange diffchange-inline">these methods:</del></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>This method is called '''before''' the new block is saved into the database, so you will not know the new block's ID yet, and consequently this method should not insert records directly into the database. <ins class="diffchange diffchange-inline">It is mostly useful for altering the contents </ins>of <ins class="diffchange diffchange-inline">the configdata.</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">1. Transform the </del>block<del class="diffchange diffchange-inline">'s configdata </del>and <del class="diffchange diffchange-inline">return it</del>. (<del class="diffchange diffchange-inline">You should return </del>the new block<del class="diffchange diffchange-inline">'s configdata unchanged if </del>you'<del class="diffchange diffchange-inline">re not going </del>to <del class="diffchange diffchange-inline">transform </del>it)</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">If your </ins>block <ins class="diffchange diffchange-inline">stores data in external tables, </ins>and <ins class="diffchange diffchange-inline">this data needs to be copied to the new blocktype, then your options are limited</ins>. <ins class="diffchange diffchange-inline">Unfortunately BlockInstance->copy</ins>(<ins class="diffchange diffchange-inline">) doesn't have a hook method that is invoked after </ins>the new block <ins class="diffchange diffchange-inline">instance gets committed to the database and assigned an ID. (See forum discussion: https://mahara.org/interaction/forum/topic.php?id=7448#post30077 ). If </ins>you'<ins class="diffchange diffchange-inline">d like </ins>to <ins class="diffchange diffchange-inline">implement a post-blockinstance-commit hook method (it should probably go at the end of Blockinstance->copy() right after it calls $newblockinstance->commit() ), then please upstream </ins>it<ins class="diffchange diffchange-inline">! ;</ins>)</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">2</del>. <del class="diffchange diffchange-inline">Update </del>the <del class="diffchange diffchange-inline">new block's <code></del>BlockInstance<del class="diffchange diffchange-inline"></code> </del>object (<del class="diffchange diffchange-inline">which </del>is passed <del class="diffchange diffchange-inline">by reference) </del>in <del class="diffchange diffchange-inline">such a way </del>that <del class="diffchange diffchange-inline">your plugin will recognize the added </del>data and <del class="diffchange diffchange-inline">save </del>it to the <del class="diffchange diffchange-inline">proper tables when its commit</del>() <del class="diffchange diffchange-inline">method </del>is <del class="diffchange diffchange-inline">called</del></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">If you don't want to do that, then your best option is to use an [[Developer_Area/Events_API|event handler]]</ins>. <ins class="diffchange diffchange-inline">BlockInstance->commit() fires a "blockinstancecommit" event each time a block instance is created or updated, and it passes </ins>the BlockInstance object <ins class="diffchange diffchange-inline">as its parameter. So, in your rewrite_blockinstance_extra_config</ins>(<ins class="diffchange diffchange-inline">) method you could add the extra data to the BlockInstance object that </ins>is passed in<ins class="diffchange diffchange-inline">, and then in your event handler, look for </ins>that <ins class="diffchange diffchange-inline">extra </ins>data and <ins class="diffchange diffchange-inline">use it to create the necessary records in the database. Bear in mind this event handler is called for any block update or instert, not just for copies. So </ins>it <ins class="diffchange diffchange-inline">should check </ins>to <ins class="diffchange diffchange-inline">see whether </ins>the <ins class="diffchange diffchange-inline">data you added in rewrite_blockinstance_extra_config</ins>() is <ins class="diffchange diffchange-inline">present, and if not, it should exit without doing anything.</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function export_blockinstance_config()===</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function export_blockinstance_config()===</div></td></tr>
</table>Aaronwhttps://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&diff=7257&oldid=prevSlanthier: /* function default_copy_type() */ /* correction of the name of the view_artefact table */2015-12-15T18:41:25Z<p><span dir="auto"><span class="autocomment">function default_copy_type(): </span> <span dir="auto"><span class="autocomment">correction of the name of the view_artefact table</span></span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:41, 15 December 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l244" >Line 244:</td>
<td colspan="2" class="diff-lineno">Line 244:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*<code>nocopy</code>: This block is not included when a page is copied</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*<code>nocopy</code>: This block is not included when a page is copied</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>If these settings don't work as expected, see the implementation of <code>BlockInstance->copy()</code> in <code>htdocs/blocktype/lib.php</code> for details on how it all happens. For instance the "full" copy is based on the artefacts linked to the block via the <code><del class="diffchange diffchange-inline">view_artefacts</del></code> table, which should be auto-populated if your block stores artefacts in a variable called <code>artefactid</code> or <code>artefactids</code> in its config, but may not be populated if you are doing something more complex.</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>If these settings don't work as expected, see the implementation of <code>BlockInstance->copy()</code> in <code>htdocs/blocktype/lib.php</code> for details on how it all happens. For instance the "full" copy is based on the artefacts linked to the block via the <code><ins class="diffchange diffchange-inline">view_artefact</ins></code> table, which should be auto-populated if your block stores artefacts in a variable called <code>artefactid</code> or <code>artefactids</code> in its config, but may not be populated if you are doing something more complex.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function rewrite_blockinstance_config()===</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function rewrite_blockinstance_config()===</div></td></tr>
</table>Slanthierhttps://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&diff=7242&oldid=prevAaronw: /* (optional) function export_blockinstance_config() */2015-12-07T00:07:56Z<p><span dir="auto"><span class="autocomment">(optional) function export_blockinstance_config()</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 00:07, 7 December 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l264" >Line 264:</td>
<td colspan="2" class="diff-lineno">Line 264:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This function is called when exporting a blockinstance to a restorable format (currently; only Leap). Passed a block instance, it should export an array containing enough data to recreate a copy of the block. For most blocks the default implementation will probably be sufficient, but if your blocktype uses custom tables or unusual data structures you may need to customize this. If you customize this, you should probably also customize <code>import_create_blockinstance()</code></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This function is called when exporting a blockinstance to a restorable format (currently; only Leap). Passed a block instance, it should export an array containing enough data to recreate a copy of the block. For most blocks the default implementation will probably be sufficient, but if your blocktype uses custom tables or unusual data structures you may need to customize this. If you customize this, you should probably also customize <code>import_create_blockinstance()</code></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">It </del>is <del class="diffchange diffchange-inline">normally only </del>called <del class="diffchange diffchange-inline">by </del><code><del class="diffchange diffchange-inline">export_blockinstance_config_leap</del></code><del class="diffchange diffchange-inline">, which json</del>-encodes the <del class="diffchange diffchange-inline">returned data, for storage in a Leap2a file</del>.</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">See the <code>PluginImportLeap->rewrite_blockinstance_config()</code> method in <code>htdocs/import/leap/lib.php</code> for details on when this method is called, what data it is passed, and what return format it expects.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">===(optional) function export_blockinstance_config_leap()===</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">This function </ins>is called <ins class="diffchange diffchange-inline">when exporting a blockinstance specifically to leap2a. The default implementation simply calls the same blocktype's </ins><code><ins class="diffchange diffchange-inline">export_blockinstance_config()</ins></code> <ins class="diffchange diffchange-inline">method and then JSON</ins>-encodes the <ins class="diffchange diffchange-inline">results</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">See the </del><code><del class="diffchange diffchange-inline">PluginImportLeap->rewrite_blockinstance_config</del>()</code> <del class="diffchange diffchange-inline">method in <code>htdocs/import/leap/lib.php</code> for details on when </del>this method <del class="diffchange diffchange-inline">is called</del>, <del class="diffchange diffchange-inline">what data it is passed, and what return format it expects</del>.</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">Usually it is better to customize </ins><code><ins class="diffchange diffchange-inline">export_blockinstance_config</ins>()</code> <ins class="diffchange diffchange-inline">instead of </ins>this method, <ins class="diffchange diffchange-inline">so that your code will be forwards-compatible with any additional restorable export formats Mahara may support in the future</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function import_create_blockinstance()===</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function import_create_blockinstance()===</div></td></tr>
</table>Aaronwhttps://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&diff=7241&oldid=prevAaronw: /* (optional) function import_rewrite_blockinstance_relationships_leap() */2015-12-07T00:04:25Z<p><span dir="auto"><span class="autocomment">(optional) function import_rewrite_blockinstance_relationships_leap()</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 00:04, 7 December 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l286" >Line 286:</td>
<td colspan="2" class="diff-lineno">Line 286:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function import_rewrite_blockinstance_relationships_leap()===</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function import_rewrite_blockinstance_relationships_leap()===</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>This function is called when importing a blockinstance from the Leap2a format. Unlike <code><del class="diffchange diffchange-inline">import_create_blockinstance</del></code>, it is called at the '''end''' of the import process (after views<del class="diffchange diffchange-inline">, </del>collections<del class="diffchange diffchange-inline">, and artefacts </del>have been imported), so you can use it to rewrite any references to these items stored in your blocks' configurations.</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>This function is called when importing a blockinstance from the Leap2a format. Unlike <code><ins class="diffchange diffchange-inline">import_rewrite_blockinstance_extra_config_leap</ins></code>, it is called at the '''end''' of the import process (after views <ins class="diffchange diffchange-inline">and </ins>collections have been imported), so you can use it to rewrite any references to these items stored in your blocks' configurations.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">In most cases this will not be necessary because the Leap import's default behavior will successfully rewrite all </del>references<del class="diffchange diffchange-inline">. But if you are using custom tables </del>or <del class="diffchange diffchange-inline">unusual data structures</del>, you <del class="diffchange diffchange-inline">may </del>need to implement this.</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">Because artefact </ins>references <ins class="diffchange diffchange-inline">get rewritten automatically (</ins>or <ins class="diffchange diffchange-inline">in <code>import_rewrite_blockinstance_extra_config_leap</code>)</ins>, you <ins class="diffchange diffchange-inline">should only </ins>need to implement this <ins class="diffchange diffchange-inline">method if your blocktype contains references to views and collections (like the core "Navigation" blocktype)</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>See the function <code>PluginImportLeap->rewrite_blockinstance_relationships()</code> in <code>htdocs/import/leap/lib.php</code> for details on when this method is called, what data it is passed, and what return format it expects.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>See the function <code>PluginImportLeap->rewrite_blockinstance_relationships()</code> in <code>htdocs/import/leap/lib.php</code> for details on when this method is called, what data it is passed, and what return format it expects.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[category:Developer Area]][[Category:Tutorials]][[Category:Blocktype Plugins]]</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[category:Developer Area]][[Category:Tutorials]][[Category:Blocktype Plugins]]</div></td></tr>
</table>Aaronwhttps://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&diff=7240&oldid=prevAaronw: /* (optional) function import_create_blockinstance_leap() */2015-12-07T00:02:14Z<p><span dir="auto"><span class="autocomment">(optional) function import_create_blockinstance_leap()</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 00:02, 7 December 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l277" >Line 277:</td>
<td colspan="2" class="diff-lineno">Line 277:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Similar to <code>import_create_blockinstance()</code>, except it is called only during a Leap2a import. (Since Leap is currently mahara's ''only'' import format, it is essentially the same at present. You should probably create an import_create_blockinstance() method instead, to give your block better forward-compatibility in case other import formats are created in the future.)</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Similar to <code>import_create_blockinstance()</code>, except it is called only during a Leap2a import. (Since Leap is currently mahara's ''only'' import format, it is essentially the same at present. You should probably create an import_create_blockinstance() method instead, to give your block better forward-compatibility in case other import formats are created in the future.)</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">===(optional) function import_rewrite_blockinstance_extra_config_leap()===</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">Similar to the standard <code>rewrite_blockinstance_extra_config</code> method, this method is called during the Leap2a import process, to allow you to rewrite the blockinstance in the database. It is called immediately before calling <code>import_create_blockinstance_leap()</code>, and can be used to rewrite the artefact references in the configdata before the blocktype gets created.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">See the method <code>PluginImportLeap->rewrite_blockinstance_config()</code> in <code>htdocs/import/leap/lib.php</code> for more details.</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function import_rewrite_blockinstance_relationships_leap()===</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function import_rewrite_blockinstance_relationships_leap()===</div></td></tr>
</table>Aaronwhttps://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&diff=7239&oldid=prevAaronw at 23:52, 6 December 20152015-12-06T23:52:38Z<p></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 23:52, 6 December 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l260" >Line 260:</td>
<td colspan="2" class="diff-lineno">Line 260:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>2. Update the new block's <code>BlockInstance</code> object (which is passed by reference) in such a way that your plugin will recognize the added data and save it to the proper tables when its commit() method is called</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>2. Update the new block's <code>BlockInstance</code> object (which is passed by reference) in such a way that your plugin will recognize the added data and save it to the proper tables when its commit() method is called</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function <del class="diffchange diffchange-inline">rewrite_blockinstance_extra_config_leap</del>()===</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function <ins class="diffchange diffchange-inline">export_blockinstance_config</ins>()===</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>This function is called when exporting a blockinstance to <del class="diffchange diffchange-inline">the Leap2a </del>format. <del class="diffchange diffchange-inline">Part </del>of the <del class="diffchange diffchange-inline">export process involves identifying </del>the <del class="diffchange diffchange-inline">block's references to artefacts</del>, <del class="diffchange diffchange-inline">views, and collections, and rewriting those </del>to <del class="diffchange diffchange-inline">refer to the IDs those items have been given within the Leap2a file</del>. If <del class="diffchange diffchange-inline">your block contains data stored in ways that are not covered </del>by the <del class="diffchange diffchange-inline">existing ID rewriting process</del>, <del class="diffchange diffchange-inline">you can implement this hook method to handle the extra situations</del>.</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>This function is called when exporting a blockinstance to <ins class="diffchange diffchange-inline">a restorable </ins>format <ins class="diffchange diffchange-inline">(currently; only Leap)</ins>. <ins class="diffchange diffchange-inline">Passed a block instance, it should export an array containing enough data to recreate a copy </ins>of the <ins class="diffchange diffchange-inline">block. For most blocks </ins>the <ins class="diffchange diffchange-inline">default implementation will probably be sufficient</ins>, <ins class="diffchange diffchange-inline">but if your blocktype uses custom tables or unusual data structures you may need </ins>to <ins class="diffchange diffchange-inline">customize this</ins>. If <ins class="diffchange diffchange-inline">you customize this, you should probably also customize <code>import_create_blockinstance()</code></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">It is normally only called </ins>by <ins class="diffchange diffchange-inline"><code>export_blockinstance_config_leap</code>, which json-encodes </ins>the <ins class="diffchange diffchange-inline">returned data</ins>, <ins class="diffchange diffchange-inline">for storage in a Leap2a file</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>See the <code>PluginImportLeap->rewrite_blockinstance_config()</code> method in <code>htdocs/import/leap/lib.php</code> for details on when this method is called, what data it is passed, and what return format it expects.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>See the <code>PluginImportLeap->rewrite_blockinstance_config()</code> method in <code>htdocs/import/leap/lib.php</code> for details on when this method is called, what data it is passed, and what return format it expects.</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">===(optional) function import_create_blockinstance()===</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">This method is called during import to create a copy of an imported block. It should receive an array like the one generated by <code>export_blockinstance_config()</code> and turn it into a new <code>BlockInstance</code>.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">See the method <code>View::import_from_config</code> in <code>htdocs/lib/view.php</code> for context on when this method is called, what data it receives, and what return value is expected.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">===(optional) function import_create_blockinstance_leap()===</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">Similar to <code>import_create_blockinstance()</code>, except it is called only during a Leap2a import. (Since Leap is currently mahara's ''only'' import format, it is essentially the same at present. You should probably create an import_create_blockinstance() method instead, to give your block better forward-compatibility in case other import formats are created in the future.)</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function import_rewrite_blockinstance_relationships_leap()===</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>===(optional) function import_rewrite_blockinstance_relationships_leap()===</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>This function is called when importing a blockinstance from the Leap2a format. <del class="diffchange diffchange-inline">It </del>is called at the end of the import process (after views, collections, and artefacts have been imported), so you can use it to rewrite any references to these items stored in your <del class="diffchange diffchange-inline">block</del>'<del class="diffchange diffchange-inline">s configuration</del>. <del class="diffchange diffchange-inline">(If they're </del>not <del class="diffchange diffchange-inline">rewritten successfully </del>be the default <del class="diffchange diffchange-inline">Leap2a import </del>behavior.<del class="diffchange diffchange-inline">)</del></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>This function is called when importing a blockinstance from the Leap2a format. <ins class="diffchange diffchange-inline">Unlike <code>import_create_blockinstance</code>, it </ins>is called at the <ins class="diffchange diffchange-inline">'''</ins>end<ins class="diffchange diffchange-inline">''' </ins>of the import process (after views, collections, and artefacts have been imported), so you can use it to rewrite any references to these items stored in your <ins class="diffchange diffchange-inline">blocks</ins>' <ins class="diffchange diffchange-inline">configurations</ins>.</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">In most cases this will </ins>not be <ins class="diffchange diffchange-inline">necessary because </ins>the <ins class="diffchange diffchange-inline">Leap import's </ins>default behavior <ins class="diffchange diffchange-inline">will successfully rewrite all references. But if you are using custom tables or unusual data structures, you may need to implement this</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>See the function <code>PluginImportLeap->rewrite_blockinstance_relationships()</code> in <code>htdocs/import/leap/lib.php</code> for details on when this method is called, what data it is passed, and what return format it expects.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>See the function <code>PluginImportLeap->rewrite_blockinstance_relationships()</code> in <code>htdocs/import/leap/lib.php</code> for details on when this method is called, what data it is passed, and what return format it expects.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[category:Developer Area]][[Category:Tutorials]][[Category:Blocktype Plugins]]</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[category:Developer Area]][[Category:Tutorials]][[Category:Blocktype Plugins]]</div></td></tr>
</table>Aaronwhttps://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&diff=7238&oldid=prevAaronw: /* function import_rewrite_blockinstance_relationships_leap() */2015-12-06T23:30:51Z<p><span dir="auto"><span class="autocomment">function import_rewrite_blockinstance_relationships_leap()</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 23:30, 6 December 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l266" >Line 266:</td>
<td colspan="2" class="diff-lineno">Line 266:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>See the <code>PluginImportLeap->rewrite_blockinstance_config()</code> method in <code>htdocs/import/leap/lib.php</code> for details on when this method is called, what data it is passed, and what return format it expects.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>See the <code>PluginImportLeap->rewrite_blockinstance_config()</code> method in <code>htdocs/import/leap/lib.php</code> for details on when this method is called, what data it is passed, and what return format it expects.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>===function import_rewrite_blockinstance_relationships_leap()===</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>===<ins class="diffchange diffchange-inline">(optional) </ins>function import_rewrite_blockinstance_relationships_leap()===</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This function is called when importing a blockinstance from the Leap2a format. It is called at the end of the import process (after views, collections, and artefacts have been imported), so you can use it to rewrite any references to these items stored in your block's configuration. (If they're not rewritten successfully be the default Leap2a import behavior.)</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This function is called when importing a blockinstance from the Leap2a format. It is called at the end of the import process (after views, collections, and artefacts have been imported), so you can use it to rewrite any references to these items stored in your block's configuration. (If they're not rewritten successfully be the default Leap2a import behavior.)</div></td></tr>
<!-- diff cache key maharawikidb-mediawiki-:diff::1.12:old-7237:rev-7238 -->
</table>Aaronwhttps://wiki.mahara.org/index.php?title=Developer_Area/Development_Tutorials/Basic_blocktype_plugin&diff=7237&oldid=prevAaronw: /* function rewrite_blockinstance_extra_config_leap() */2015-12-06T23:30:43Z<p><span dir="auto"><span class="autocomment">function rewrite_blockinstance_extra_config_leap()</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 23:30, 6 December 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l260" >Line 260:</td>
<td colspan="2" class="diff-lineno">Line 260:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>2. Update the new block's <code>BlockInstance</code> object (which is passed by reference) in such a way that your plugin will recognize the added data and save it to the proper tables when its commit() method is called</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>2. Update the new block's <code>BlockInstance</code> object (which is passed by reference) in such a way that your plugin will recognize the added data and save it to the proper tables when its commit() method is called</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>===function rewrite_blockinstance_extra_config_leap()===</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>===<ins class="diffchange diffchange-inline">(optional) </ins>function rewrite_blockinstance_extra_config_leap()===</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This function is called when exporting a blockinstance to the Leap2a format. Part of the export process involves identifying the block's references to artefacts, views, and collections, and rewriting those to refer to the IDs those items have been given within the Leap2a file. If your block contains data stored in ways that are not covered by the existing ID rewriting process, you can implement this hook method to handle the extra situations.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This function is called when exporting a blockinstance to the Leap2a format. Part of the export process involves identifying the block's references to artefacts, views, and collections, and rewriting those to refer to the IDs those items have been given within the Leap2a file. If your block contains data stored in ways that are not covered by the existing ID rewriting process, you can implement this hook method to handle the extra situations.</div></td></tr>
</table>Aaronw