Skip to Content search facebook instagram pinterest twitter youtube

Action methods

These methods are the "doing methods" of the admin controller - adding records, editing records, deleting records, etc. Each of these methods correspond to an admin route.

Intro

When a user selects a controller from the navigation (e.g. from a tile in the modules tab of the admin), the links to these modules are in the form admin/intro/<slug> which calls the _intro method of the controller.

This method can either return HTML of an intro method, or can redirect somewhere else.

The default behaviour is to redirect to the main list.

Main list

The main method here is _getContents which itself calls _getContentsQuery and _getContentsView which do the interesting parts.

The method _getContentsView takes mode argument, with the default view mode of 'list'. Additional view modes can be defined using a protected property. The actual rendering of list views is via the _getContentsViewList method which itself uses the Itemlist class for the rendering.

Typically only the _getContentsQuery method would be customised with the others left as-is.

Available refinement options are managed via the refine_bar protected parameter and rendered by _getSearchForm which would typically be left as-is.

Refinement options which have a leading _ (underscore) are not treated as fields directly, but instead as custom clauses. These get passed to the _getRefineClause method which should return SQL for a where clause.

Add form

The add form is shown when adding records.

  • _getAddForm - prepare the add form html, only form contents, does not include the <form> tag or save box, almost always the default is used
  • _addPreRender - allows for tweaks to the default add form code (i.e. injecting additional view data)
  • _isAddSaved - can be used to disable the display of the save box
  • _getAddSubActions - additional links to show in the save box
  • _getCustomAddSaveHTML - can be used if a custom save box is needed

Add save

This is the action which is POSTed to when the add form is saved.

The method which is called is _addSave and the default version of this can be used as-is if using JsonForm.

An additional method _preSave is called when using JsonForm. This method is called for both adds and edits; for adds the record id will be zero. The default version of this sets the date_added and date_modified fields.

Edit form

The edit form is shown when editing records

  • _getEditForm - prepare the add form html, only form contents, does not include the <form> tag or save box, almost always the default is used
  • _editPreRender - allows for tweaks to the default edit form code (i.e. injecting additional view data)
  • _isEditSaved - can be used to disable the display of the save box
  • _getEditLiveUrl - return the url for the front-end view of this item, causes the view live site button to point directly to this item
  • _getEditSubActions - additional links to show in the save box
  • _getCustomEditSaveHTML - can be used if a custom save box is needed

Edit save

This is the action which is POSTed to when the edit form is saved.

The method which is called is _editSave and the default version of this can be used as-is if using JsonForm.

An additional method _preSave is called when using JsonForm. This method is called for both adds and edits. The default version of this sets the date_modified fields.

Duplication

The duplication form is typically just the edit form, although the form action is different. The save implemented by creating a new blank record first, and then calling _duplicateSave which by default actually just calls _editSave.

This implemention allows for low-effort implemention of duplication features.

  • _getDuplicateForm - get the duplicate form, typically the same as getting the edit form
  • _getDuplicateSubActions - sidebar actions on duplicate form
  • _getCustomDuplicateSaveHTML - overrides the sidebar for duplicates
  • _duplicatePreRender - the default version of this calls _editPreRender
  • _duplicateSave - the default version calls _editSave

Deletes

Records can be deleted in the admin. If action logging is turned on (it normally is) then the logging contains all the old record data, and the deletes can also be undone.

  • _getDeleteForm - return the delete form, shows a message of what is being deleted
  • _isDeleteSaved - can disable the save button, preventing deletes
  • _getDeleteSubActions - additional actions for the deletion save box
  • _deletePreSave - called prior to deletion for additional validation, throws an exception on error
  • _deleteSave - actual deletion, default value calls Controller::deleteRecord which cascades deletes with logging
  • _deletePostSave - called after deletion

Export

The export form is provided by _getExport and the export itself is done by _exportData. Typically these methods are both left as-is.

Another useful method is _getExportQuery which is the main query which returns the data which is exported.

Import

The import form is _getImport and the data is imported with _importData, although like the export tool these methods are often left as-is, and instead various other methods are used to tweak the import behaviour:

  • _importColGuess - assists the csv-to-field mapping code
  • _importExtraOptions - html of additional fields to show on the import form
  • _importPre - called before the import
  • _importPreRecord - called before each record of import
  • _importPostRecord - called after each record
  • _importPost - called after the whole import is complete