Right now, if we were to install the package, the block type would not come with it, and users of your add-on would be confused and disappointed. We can tell the package to install the block type during the package's installation, though.
Open the package controller
(/packages/cookbook_gallery/controller.php
) in your code editor.
Add a new method to the controller
class called install
, as follows:
public function install() { $pkg = parent::install(); // install the block type BlockType::installBlockTypeFromPackage('cookbook_gallery', $pkg); }
What's going on here? Well, the Package
class has a function called install
, which, you guessed it, installs the package to the concrete5 database. Since our package controller extends the Package
class, the install
function is automatically available to us.
The first step is to call the Package
class's install
function and get the object that it returns. This will allow us to install the block type and have it assigned to our package.
It's important to pass the $pkg
object to the block type installer, because if users uninstall or reinstall your add-on, the block type will come and go with it.
Save the controller file. It's time to install our add-on!
Visit /dashboard/extend/install/
on your concrete5 site (you'll have to log in if your haven't already). You will see your add-on awaiting installation.
The gallery add-on awaiting installation is as shown in the following screenshot:
Click on the Install button. concrete5 will add your package and its block controller to the site. If it succeeds, you will see a message at the top of the screen.
After successful installation of the add-on, we see the following screenshot:
Visit your concrete5 homepage and hover over the Edit button to add a sub-page underneath the home page.
Let's use the Full layout for this gallery page.
Give the page a title and path. How about Image Gallery
?
Add the page to the site. Now that we have a nice place to put our block, let's actually make our block do something!