Autogenerated Wordpress Admin Tables, for Eloquent Models.
Make it easy, to create a WordPress Admin Table CRUD.
Overview: Makes a WordPress Admin Table, with the data from the Eloquent Model.
Create: Allows to create a new instance of the Eloquent Model, from an ACF group.
Read: Make a view page, where the data from the instance is displayed.
Update: Allows to update an instance of the Eloquent Model, from an ACF group.
Delete: Allows to delete an instance of the Eloquent Model.
IMPORTANT:
You will need ACF (Advanced Custom Fields) to get the Create and Update parts to work.
To get started install the package as described below in Installation.
To use the tool have a look at Usage
Install with composer
composer require morningtrain/wp-database-model-admin-ui
Initialize \Morningtrain\WP\DatabaseModelAdminUi\ModelUI
with the folder, where all the Eloquent Models is located.
\Morningtrain\WP\DatabaseModelAdminUi\ModelUI::setup(__DIR__ . "/app/Models");
When an Admin Table need to be show, for an Eloquent Model, this need to be register in.
To do this, on each Model class, there will be called a static method called setupAdminUi
.
To start of, use \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::modelPage()
method and give it a slug and an Eloquent Model class.
The wrapper method has the following parameters:
string $slug
string $model
When this is done, we need to register it. This is done by:
\Morningtrain\WP\DatabaseModelAdminUi\ModelUI::modelPage(string, string)
->register();
This is all there is to get started with an Admin Table overview.
This will show an Admin Table overview, with all it's columns.
The ModelPage can be customized, with different things. To se a list of all the settings, see ModelPage.
Sets the value to the page title, for the Admin Table.
Default: Admin Table
->withPageTitle(string)
Sets the value to the menu title, for the Admin Table.
Default: Admin Table
->withMenuTitle(string)
Sets the value, that the user needs, for viewing the Admin Table.
Default: manage_options
->withCapability(string)
Sets the value for the Admin Table admin menu icon.
Default: empty value
->withIconUrl(string)
Sets the value for the Admin Table admin menu position.
Default: null
->withPosition(int)
Sets the value for the Admin Table search button text.
Default: __('Search')
->withSearchButtonText(string)
Sets the value as columns, for the Admin Table.
Default: all columns on the Model
This one takes an array of the Column
classes.
The Column
can be customized, with different things. To se a list of all the settings, see Column.
->withColumns(array)
Sets the value as row actions, for the Admin Table.
Default: []
If method ->withViewPage()
is in use, it will add a default View action to each row.
If method ->withAcfEditPage()
is in use, it will add a default Edit action to each row.
If method ->makeRemovable()
is in use, it will add a default Delete action to each row.
This one takes an array of the RowAction
classes.
The RowAction
can be customized, with different things. To se a list of all the settings, see RowAction.
->withRowActions(array)
Return the callback|string
modified \Illuminate\Database\Eloquent\Builder
.
Default: null
Parameters in callback:
\Illuminate\Database\Eloquent\Builder $query
->withModifyQueryCallback(\Illuminate\Database\Eloquent\Builder)
Set up the Admin Table views.
Default: []
This one takes an array of the AdminTableViews
classes.
The AdminTableViews
can be customized, with different things. To se a list of all the settings, see AdminTableViews.
->withAdminTableViews(array)
You can also add views by using the ->addAdminTableViewsCallback()
method instead. This should be used when having dynamic views to avoid using resources when not necessary.
Return the an array array of AdminTableViews
instances.
Default: null
Parameters in callback:
ModelPage $modelPage
The AdminTableViews
can be customized, with different things. To se a list of all the settings, see AdminTableViews.
->addAdminTableViewsCallback(callback)
Set up the Admin Table extra tablenavns.
This one is split up into two methods, to have one for the top and one for the bottom.
Default: []
Both methods takes an array of the AdminTableExtraTablenav
classes.
The AdminTableExtraTablenav
can be customized, with different things. To se a list of all the settings, see AdminTableExtraTablenav.
->withAdminTableTopExtraTablenavs(array)
->withAdminTableBottomExtraTablenavs(array)
Set up a view page, for the Admin Table.
Default: null
This one takes an instance of the ViewPage
class.
The ViewPage
can be customized, with different things. To se a list of all the settings, see ViewPage.
->withViewPage()
Set up an ACF create page, for the Admin Table.
Default: null
This one takes an instance of the AcfCreatePage
class.
The AcfCreatePage
can be customized, with different things. To se a list of all the settings, see AcfCreatePage.
->withAcfCreatePage()
Set up an ACF edit page, for the Admin Table.
Default: null
This one takes an instance of the AcfEditPage
class.
The AcfEditPage
can be customized, with different things. To se a list of all the settings, see AcfEditPage.
->withAcfEditPage()
Render meta boxes.
Default: null
This one takes an array, of instances, of the MetaBox
class.
The MetaBox
can be customized, with different things. To se a list of all the settings, see MetaBox.
->withMetaBoxes(array)
Sets the value as excluded columns, for the Admin Table.
Default: []
Each item in the array, is the slug on the column.
->withoutColumns(array)
Sets the value as parent slug, for the Model Page.
Default: null
->makeSubMenu(string)
Add a removable option.
Default: false
->makeRemovable()
To get an instance of a Column
, use the wrapper method: \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::column()
.
The wrapper method has the following parameters:
string $slug
Sets the value to the column title.
Default: slug, with first letter uppercase
->withTitle(string)
Render the callback|string
in each row, for the specific column.
Default: output the value
Parameters in callback:
$instance
ModelPage $modelPage
->withRender(callback|string)
Makes the column searchable. It can take a callback|string
, where it's possible to make own search, on a custom column, that isn't on the Eloquent model table.
Default: false
Parameters in callback:
\Illuminate\Database\Eloquent\Builder $dataQuery
string $searchString
->makeSearchable(callback|string|null)
Makes the column sortable. It can take a callback|string
, where it's possible to make own order, on a custom column, that isn't on the Eloquent model table.
Default: false
Parameters in callback:
\Illuminate\Database\Eloquent\Builder $dataQuery
string $order
->makeSortable(callback|string|null)
To get an instance of a RowAction
, use the wrapper method: \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::rowAction()
.
The wrapper method has the following parameters:
string $slug
callable|string $renderCallback
: Callback has the following parameters:array $item
ModelPage $modelPage
To get an instance of a AdminTableView
, use the wrapper method: \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::adminTableView()
.
The wrapper method has the following parameters:
string $urlKey
null|string $urlValue
Sets the value to the view title.
Default: urlKey, with first letter uppercase
->withTitle(string)
Sets the value to the view count.
Default: null
->withCount(string)
Sets the callback value to the view count.
Default: null
Parameters in callback:
AdminTableView $view
->withCountCallback(callback|string)
To get an instance of a AdminTableExtraTablenav
, use the wrapper method: \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::adminTableExtraTablenav()
.
The wrapper method has the following parameters:
callback|string $renderCallback
To get an instance of a ViewPage
, use the wrapper method: \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::viewPage()
.
Render the callback|string
, on the view page.
Default: shows a table, with all data in a <table>
Parameters in callback:
array $data
$currentModelPage
->withRender(callback|string)
Sets the value to the capability.
Default: ModelPage::capability
->withCapability(string)
Hide the default view.
Default: true
->hideDefaultView()
To get an instance of a AcfCreatePage
, use the wrapper method: \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::acfCreatePage()
.
To make this work, it's needed to create an ACF group, that has the fields, like the Eloquent Model, that can be created.
Under the ACF group locations, there is a new rule called Eloquent Model, that should be chosen to show the ACF group on the create page.
Calls the callback|string
, when a Model is updated, through ACF.
Default: null
Parameters in callback|string:
$instance
$model
array $values
->withSaveCallback(callback|string)
Sets the value to the capability.
Default: ModelPage::capability
->withCapability(string)
To get an instance of a AcfEditPage
, use the wrapper method: \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::acfEditPage()
.
To make this work, it's needed to create an ACF group, that has the fields, like the Eloquent Model, that can be edited.
Under the ACF group locations, there is a new rule called Eloquent Model, that should be chosen to show the ACF group on the edit page.
Calls the AcfLoadField
callback|string
, when a field, on the Model, is loaded.
Default: []
This one takes an array of the AcfLoadField
classes.
The AcfLoadField
can be customized, with different things. To se a list of all the settings, see AcfLoadField.
->withLoadFieldCallbacks([])
Calls the callback|string
, when a Model is updated, through ACF.
Default: null
Parameters in callback|string:
int|null $modelId
$model
array $values
->withSaveCallback(callback|string)
Sets the value to the capability.
Default: ModelPage::capability
->withCapability(string)
To get an instance of a AcfLoadField
, use the wrapper method: \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::acfLoadField()
.
The wrapper method has the following parameters:
string $slug
callable|string $renderCallback
: Callback has the following parameters:mixed $return
string $slug
int $modelId
$model
To get an instance of a MetaBox, use the wrapper method: \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::metaBox()
.
The wrapper method has the following parameters:
string $slug
callable|string $renderCallback
: Callback has the following parameters:int|null $modelId
$model
Sets the value to the meta box title.
Default: slug, with first letter uppercase
->withTitle(string)
Sets the priority to high.
Default: default
->withHighPriority()
Sets the priority to core.
Default: default
->withCorePriority()
Sets the priority to low.
Default: default
->withLowPriority()
Sets the context to side.
Default: normal
->onSideContext()
Sets the meta box to be rendered on Acf Edit Page.
Default: Admin Table
->onAcfEditPage()
Thank you for your interest in contributing to the project.
If you found a bug, we encourage you to make a pull request.
To add a bug report, create a new issue. Please remember to add a telling title, detailed description and how to reproduce the problem.
We do not provide support for this package.
- Fork the Project
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
- Commit your Changes (git commit -m 'Add some AmazingFeature')
- Push to the Branch (git push origin feature/AmazingFeature)
- Open a Pull Request
The MIT License (MIT). Please see License File for more information.