Locations View

Let's start filling out the menus created within the administration panel. Run the following opus crud CLI command:

apex opus crud Disaster/Models/Location --dbtable disaster_locations --view admin/disaster/locations --magic

This will create multiple files located at:

Filename Description
/src/Disaster/Controllers/LocationController.php Controller that contains all necessary CRUD functions to create, retrive, update and delete locations within the database.
/src/Disaster/Opus/DataTables/Locations.php Class that handles the data table whichdisplays all existing locations previously saved.
/src/Disaster/Opus/Forms/Location.php Handles the HTML form that is displayed when creating / editing a location.
/views/html/admin/disaster/location.html Template that displays both, table of all existing locationst to manage and a form To create a new location.
/views/html/admin/disaster/locations_manage.html View to manage details on a location.
/views/php/admin/disaster/locations.php Calls the LocationController as needed when the form is posted to create, update and delete locations.
/views/php/admin/disaster/locations_manage.php Parses the template and displays the location information to update.

Automated code generation can only go so far, so some manual tweaking to the generated files is required. Modify the code as described in the below sections.

/src/Disaster/Opus/Forms/Location.php

Open the file at /src/Disaster/Opus/Forms/Location.php, and on line 40 you will see it defines the 'country' form field. Change this line to:

[data-line=40]
'country' => $builder->select()->required()->dataSource('stdlist.country'),

And on line 42 where it defines the 'notes' field, simply change "textbox()" to "textarea(). The line should be:

[data-line=42]
'notes' => $builder->textarea()->required()->value(''),

Full details can be found on the HTML Forms page of the documentation including the Form Builder and FormField sections of the documentation.

/src/Disaster/Opus/DataTables/Locations.php

Open the /src/Disaster/Opus/DataTables/Locations.php file, and at the top within the use declarations add the line:

[data-line=5]
use Apex\App\Base\Lists\CountryList;

Starting on line 17 where the $columns is defined, remove the 'country' and 'notes' items. The $columns array should be:

[data-line=17]
public array $columns = [
    'city' => 'City',
    'created_at' => 'Created At',
    'manage' => 'Manage'
];

Within the formatRow() method around line 110 add the line:

$row['city'] .= ', ' . CountryList::$opt[$row['country']]['name'];

Conclusion

Now visit the Disaster Relief->Locations menu of the administration panel, and you will see a fully functioning menu allowing you to complete all CRUD operations for locations. Let's go over what we did throughout this page.

  • Executed the opus crud CLI command which automatically generated all necessary files for the Disaster Relief->Locations menu of the administration panel.
  • Updated the HTML form class and modified the form fields as necessary.
  • Updated the Data Table class and modified columns and formatting of rows as necessary.