Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To add to the first answer,</p> <p>one thing that I constantly had problems with is not calling the <code>add_layout_tabs</code> method anywhere in the update file of your module (i.e .the file that starts with <code>upd.</code>)</p> <p>So suppose your update file is called: <code>upd.addon_name.php</code>. Then in the <code>install</code> looks like this (note: the following functions are all part of the <code>Addon_name_upd</code> class inside your update file: </p> <pre><code>function install () { // ... create databases or any necessary code for your module $this-&gt;EE-&gt;load-&gt;library('layout'); $this-&gt;EE-&gt;layout-&gt;add_layout_tabs($this-&gt;tabs(), 'addon_name'); return TRUE; } </code></pre> <p>Notice the call to <code>$this-&gt;tabs()</code> method: That method looks something like this:</p> <pre><code>function tabs() { $tabs['addon_name'] = array( 'field_1_inside_publish_form' =&gt; array( 'visible' =&gt; 'true', 'collapse'=&gt; 'false', 'htmlbuttons' =&gt; 'true', 'width' =&gt; '100%' ) ); return $tabs; } </code></pre> <p>Where <code>field_1_inside_publish_form</code> is a field that would be defined in your corresponding tab file for the module (i.e. <code>tab.addon_name.php</code> ).</p> <p>The install method will in effect save a new tab to the existing publish layout that includes your module's tab configuration.</p> <p>However, you must add a method to remove your configuration in the uninstall method of the update file by calling the <code>delete_layout_tabs</code> method like so:</p> <pre><code>function uninstall() { // necessary code to drop your database tables or whatever $this-&gt;EE-&gt;load-&gt;library('layout'); $this-&gt;EE-&gt;layout-&gt;delete_layout_tabs($this-&gt;tabs(), 'addon_name'); return TRUE; } </code></pre> <p>One more thing, if you develop like I do: make a little change here, test your change, go back and code some more, then you'll find that if new fields added to the tab file <code>tab.addon_name.php</code> after your module is enabled don't appear in your new tab on the publish page. The reason is because the method <code>add_layout_tabs</code> that you call in the install method of your update file needs to be ran. </p> <p>However, this method only gets executed when you enable your module. So that means you have to disable your module, which is a drag if your module adds database tables. Luckily you can make the update method of your update file load your new tab configuration (in addition to adding or dropping any new database tables as part of your module's updates.)</p> <p>The idea is that you delete your previous configuration and you add the configuration, which, calls your tabs method which has the names of the the new fields for your module's tab section.</p> <p>So, suppose your tabs method has a new field called 'field_2_inside_publish_form' like so:</p> <pre><code>function tabs() { $tabs['addon_name'] = array( 'field_1_inside_publish_form' =&gt; array( 'visible' =&gt; 'true', 'collapse'=&gt; 'false', 'htmlbuttons' =&gt; 'true', 'width' =&gt; '100%' ), 'field_2_inside_publish_form' =&gt; array( 'visible' =&gt; 'true', 'collapse'=&gt; 'false', 'htmlbuttons' =&gt; 'true', 'width' =&gt; '100%' ) ); } </code></pre> <p>then your update method can update the layout like so (assume that you've updated your <code>$this-&gt;version</code> property in the udpate file from '1.0' to '1.5'.</p> <pre><code>function update($current='') { // don't do anything if the version hasn't changed if($current == $this-&gt;version) { return FALSE; } // the version property has a version higher than current version in db // this means the module is being updated. if($current &lt; $this-&gt;version) { // update the tab layout // delete old layout $this-&gt;EE-&gt;load-&gt;library('layout'); $this-&gt;EE-&gt;layout-&gt;delete_layout_tabs($this-&gt;tabs(), 'addon_name'); // add new tab layout which calls tabs method with updated code $this-&gt;EE-&gt;load-&gt;library('layout'); $this-&gt;EE-&gt;layout-&gt;add_layout_tabs($this-&gt;tabs(), 'addon_name'); } return TRUE; } </code></pre> <p>Remember that the update method of the update file of your module gets run <strong>everytime you are in your module's control panel page</strong> defined in in your modules control panel page file (i.e. <code>mcp.addon_name.php</code> ). Your module's main control panel page would probably correspond to the index method of the <code>Addon_name_mcp</code> class of your control panel page file.</p> <p>It would correspond to a link uri like this: <code>admin.php?S=0&amp;D=cp&amp;C=addons_modules&amp;M=show_module_cp&amp;module=addon_name&amp;method=index</code> </p> <p>Hope that helps. It's kind of long winded but I wrote it more for my own benefit than for anyone else (cause I wasted like 3 hours trying to get my module to work.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload