Skip to content

Commit c9301a5

Browse files
authored
Merge pull request #950 from swierczek/addon-update-code-block-formatting
Add TOC and adjust code block spacing
2 parents cee2786 + a6f6856 commit c9301a5

File tree

1 file changed

+66
-54
lines changed

1 file changed

+66
-54
lines changed

docs/development/add-on-update-file.md

Lines changed: 66 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
# Add-on Update File
1111

12+
[TOC]
13+
1214
## Overview
1315

1416
The `upd.[addon_name].php` file (commonly just called the `upd` file) is critical to ExpressionEngine knowing what to do with your add-on. Here we tell ExpressionEngine what actions to register, core hooks we want to use, database tables to update, and much more. We need to tell ExpressionEngine what to do when we install an add-on, update an add-on, and uninstall and add-on. Thankfully the CLI takes care of most of this for us.
@@ -63,8 +65,8 @@ class Amazing_add_on_upd extends Installer
6365
The first thing you will notice in our `Amazing_add_on_upd` class is a list of properties that describe some specifics of our add-on to ExpressionEngine. There are two required properties to declare here:
6466

6567
```
66-
public $has_cp_backend = 'y'; // Shows the option to see addon’s settings.
67-
public $has_publish_fields = 'n'; // Whether module provides tab for entry edit page
68+
public $has_cp_backend = 'y'; // Shows the option to see addon’s settings.
69+
public $has_publish_fields = 'n'; // Whether module provides tab for entry edit page
6870
```
6971

7072
## Install Your Add-On (`install()`)
@@ -77,23 +79,25 @@ The CLI automatically generates our install method. This method will ensure that
7779

7880

7981
```
80-
public function install()
81-
{
82-
parent::install();
82+
public function install()
83+
{
84+
parent::install();
8385
84-
// create a database table
85-
// notify mission control
86-
// add publish tabs
86+
// create a database table
87+
// notify mission control
88+
// add publish tabs
8789
88-
return true;
89-
}
90+
return true;
91+
}
9092
```
9193

9294
### Adding Publish Tabs
9395
Optionally add the publish page tab fields to any saved publish layouts. This is ONLY used if the module adds a tab to the publish page and it requires the [`tabs()` function](#add-publish-tabs-with-your-add-on-tabs):
9496

95-
ee()->load->library('layout');
96-
ee()->layout->add_layout_tabs($this->tabs(), 'module_name');
97+
```
98+
ee()->load->library('layout');
99+
ee()->layout->add_layout_tabs($this->tabs(), 'module_name');
100+
```
97101

98102

99103
## Add Publish Tabs With Your Add-on (`tabs()`)
@@ -104,25 +108,27 @@ Optionally add the publish page tab fields to any saved publish layouts. This is
104108

105109
An optional function included only if your add-on adds a tab to the publish page. This function should return a multidimensional associative array: the top array key consisting of the tab name, followed by any field names, with each field having a variety of default settings. Note that when the fields are added to the publish page, they are namespaced to prevent variable collisions:
106110

107-
function tabs()
108-
{
109-
$tabs['tab_name'] = array(
110-
'field_name_one'=> array(
111-
'visible' => 'true',
112-
'collapse' => 'false',
113-
'htmlbuttons' => 'true',
114-
'width' => '100%'
115-
),
116-
'field_name_two'=> array(
117-
'visible' => 'true',
118-
'collapse' => 'false',
119-
'htmlbuttons' => 'true',
120-
'width' => '100%'
121-
),
122-
);
123-
124-
return $tabs;
125-
}
111+
```
112+
function tabs()
113+
{
114+
$tabs['tab_name'] = array(
115+
'field_name_one'=> array(
116+
'visible' => 'true',
117+
'collapse' => 'false',
118+
'htmlbuttons' => 'true',
119+
'width' => '100%'
120+
),
121+
'field_name_two'=> array(
122+
'visible' => 'true',
123+
'collapse' => 'false',
124+
'htmlbuttons' => 'true',
125+
'width' => '100%'
126+
),
127+
);
128+
129+
return $tabs;
130+
}
131+
```
126132

127133
Be sure that you also update your [`install()` function](#adding-publish-tabs) to add your specified tabs.
128134

@@ -138,22 +144,24 @@ The `update` method will run code when a user installs an update to our add-on.
138144
| \$current | `string` | The last recorded version of the module in the `exp_modules` table |
139145
| Returns | `Boolean` | `FALSE` if no update is needed, `TRUE` otherwise
140146

141-
public function update($current = '')
142-
{
143-
// Runs migrations
144-
parent::update($current);
147+
```
148+
public function update($current = '')
149+
{
150+
// Runs migrations
151+
parent::update($current);
145152
146-
// only run the update if the user is currently running a version less than 2.0
147-
if (version_compare($current, '2.0', '<'))
148-
{
149-
// Do your update code here
150-
// update database
151-
// notify mission control of the update
152-
}
153+
// only run the update if the user is currently running a version less than 2.0
154+
if (version_compare($current, '2.0', '<'))
155+
{
156+
// Do your update code here
157+
// update database
158+
// notify mission control of the update
159+
}
153160
154161
155-
return true;
156-
}
162+
return true;
163+
}
164+
```
157165

158166
## Uninstall Your Add-On (`uninstall()`)
159167
The CLI automatically generates our uninstall method. This method will ensure that all extensions and actions declared above will be properly uninstalled. Similarly to installation, if you just need to ensure your actions and extensions are uninstalled, you can leave this method as is. However, you added custom functionality in the `install()` method, then you need to also ensure you clean up after yourself here.
@@ -162,19 +170,23 @@ The CLI automatically generates our uninstall method. This method will ensure th
162170
| --------- | --------- | ------------------------------------------------------------ |
163171
| Returns | `Boolean` | `TRUE` if everything uninstalled properly, `FALSE` otherwise |
164172

165-
public function uninstall()
166-
{
167-
parent::uninstall();
173+
```
174+
public function uninstall()
175+
{
176+
parent::uninstall();
168177
169-
// remove my database tables
170-
// remove any publish tabs
171-
// turn off the lights
178+
// remove my database tables
179+
// remove any publish tabs
180+
// turn off the lights
172181
173-
return true;
174-
}
182+
return true;
183+
}
184+
```
175185

176186
### Removing Tabs
177187
Optionally delete any publish page tab fields saved in publish layouts. This is ONLY used if the module adds a tab to the publish page and it requires the `tabs()` function:
178188

179-
ee()->load->library('layout');
180-
ee()->layout->delete_layout_tabs($this->tabs(), 'module_name');
189+
```
190+
ee()->load->library('layout');
191+
ee()->layout->delete_layout_tabs($this->tabs(), 'module_name');
192+
```

0 commit comments

Comments
 (0)