Skip to content

About

Module Pages for Bonfire 2, an admin panel for CodeIgniter 4 projects

Resources

Stars

4 stars

Watchers

2 watching

Forks

Repository files navigation

Admin module "Pages" for Bonfire 2

About

This repo holds the code for an admin module "Pages" for Bonfire 2, an admin panel for CodeIgniter 4 projects.

The Pages module is a complete example of a Bonfire 2 admin module. It provides Title, Content (with an excerpt for the admin list), URL Slug and Category fields, meta information, and integrates with the parts of the admin that the current Bonfire 2 offers: the sidebar, dashboard widgets, global search, list filters, row and bulk actions, the Recycler, and the permission system.

Features

  • CRUD for pages: create, list, search, filter, edit and delete.
  • Row and bulk actions in the list. Checking pages opens the floating selection bar with Publish, Unpublish, Move to trash and Delete permanently; each page's row menu offers the same actions.
  • Soft deletes with the Recycler. Deleted pages can be restored, and purging a page also removes its meta information.
  • Permissions declared by the module itself (pages.list, pages.create, pages.edit, pages.delete), granted to superadmin and admin by php spark bonfire:permissions.
  • The "published" state is stored in Bonfire's meta information and shown as a status chip in the list.
  • Integration with Bonfire's global search, including meta fields (author name, email and Facebook page).
  • Filters by category and creation date, and a search box that works over htmx.
  • HugeRTE editor with htmx-powered field validation.
  • English and Lithuanian translations.

Requirements

  • PHP 8.2 or newer.
  • CodeIgniter 4.7 or newer.
  • Bonfire 2 (develop).

Installation

As a Composer package

composer require dgvirtual/bonfire2-pages-module

The module registers itself with Bonfire from its Config/Registrar: Bonfire finds Module.php, and the permissions are declared for php spark bonfire:permissions. There is nothing to add to app/Config/Bonfire.php.

From a copy in app/Modules

  1. Copy the directory Pages to the app/Modules directory of your project.

  2. Uncomment (or add) the module location in app/Config/Bonfire.php:

    public $appModules = [
        'App\Modules' => APPPATH . 'Modules',
    ];
  3. Register the module's namespace in app/Config/Autoload.php, so CodeIgniter reads its Config/Registrar.php:

    public $psr4 = [
        APP_NAMESPACE          => APPPATH,
        'App\Modules\Pages'    => APPPATH . 'Modules/Pages',
    ];

Both ways

  1. Run the module's migration:

    php spark migrate -n App\Modules\Pages --all
  2. Grant the module's permissions to the default groups:

    php spark bonfire:permissions

    Later changes in Settings → Groups are kept; the command does not give a permission back to a group that an administrator has taken it away from.

  3. Copy Pages/Config/Pages.php to app/Config and change the top of the copied file below the PHP tag to:

    namespace Config;
    
    use App\Modules\Pages\Config\Pages as BasePages;
    
    class Pages extends BasePages
    {
        // class content as is

    The config holds the meta fields shown on the page form and the meta fields included in the admin search.

  4. Optionally, fill the database with sample pages:

    php spark db:seed App\Modules\Pages\Database\Seeds\InsertSamplePages

The Recycler entry for pages is registered by the module itself. You do not need to edit app/Config/Recycler.php.

Using the module

Open Pages in the admin sidebar. The list can be searched and filtered. Check one or more pages to open the floating bar at the bottom of the list; the same actions are in each row's menu:

Action What it does
Publish Marks the page as published through the published meta field.
Unpublish Takes the page down without deleting it.
Move to trash Soft deletes the page; restore it from Tools › Recycler.
Delete permanently Purges the page and its meta information. Cannot be undone.

Purging asks the admin to type the number of selected pages, since there is no undo.

Theme changes

The module uses the current Admin theme components (<x-page-head>, <x-admin-box>, <x-empty-state>, <x-status>, <x-row-actions>, <x-selection-bar>, <x-bulk-actions>, <x-save-bar>). If your install published an older copy of the Admin theme, update the theme files, or the list will not show the floating action bar.

Tests

The module ships a feature test that boots Bonfire on CodeIgniter's test application, runs every migration and checks the list, the forms, and every action:

composer install
vendor/bin/phpunit

Updating from an earlier version

Read the changelog. Recent versions changed the route names (pages-new, pages-create, pages-edit, pages-save), removed the module's own delete endpoints in favour of Bonfire's actions, and moved the Recycler and permission setup into the module. Merge any changes in Pages/Config/Pages.php with your app/Config/Pages.php.

License

MIT. See LICENSE.

About

Module Pages for Bonfire 2, an admin panel for CodeIgniter 4 projects

Resources

Stars

4 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages