morningtrain/wp-database-model-admin-ui

Autogenerated Wordpress Admin Tables, for Eloquent Models

v0.5.2 2023-11-09 11:29 UTC

This package is auto-updated.

Last update: 2024-12-09 13:45:40 UTC


README

Autogenerated Wordpress Admin Tables, for Eloquent Models.

Table of Contents

Introduction

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.

Getting Started

To get started install the package as described below in Installation.

To use the tool have a look at Usage

Installation

Install with composer

composer require morningtrain/wp-database-model-admin-ui

Dependencies

Usage

Initializing package

Initialize \Morningtrain\WP\DatabaseModelAdminUi\ModelUI with the folder, where all the Eloquent Models is located.

\Morningtrain\WP\DatabaseModelAdminUi\ModelUI::setup(__DIR__ . "/app/Models");

Use for an Eloquent Model

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.

Classes

ModelPage

Page Title

Sets the value to the page title, for the Admin Table.
Default: Admin Table

->withPageTitle(string)
Menu Title

Sets the value to the menu title, for the Admin Table.
Default: Admin Table

->withMenuTitle(string)
Capability

Sets the value, that the user needs, for viewing the Admin Table.
Default: manage_options

->withCapability(string)
Icon Url

Sets the value for the Admin Table admin menu icon.
Default: empty value

->withIconUrl(string)
Position

Sets the value for the Admin Table admin menu position.
Default: null

->withPosition(int)
Search button text

Sets the value for the Admin Table search button text.
Default: __('Search')

->withSearchButtonText(string)
Columns

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)
Row Actions

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)
Modify Query Callback

Return the callback|string modified \Illuminate\Database\Eloquent\Builder.
Default: null Parameters in callback:

  • \Illuminate\Database\Eloquent\Builder $query
->withModifyQueryCallback(\Illuminate\Database\Eloquent\Builder)
Admin Table Views

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)
Admin Table Extra Tablenavns

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)
View Page

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()
ACF Create Page

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()
ACF Edit Page

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()
Meta Boxes

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)
Without Columns

Sets the value as excluded columns, for the Admin Table.
Default: []

Each item in the array, is the slug on the column.

->withoutColumns(array)
Parent Slug

Sets the value as parent slug, for the Model Page.
Default: null

->makeSubMenu(string)
Removable

Add a removable option.
Default: false

->makeRemovable()

Column

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
Title

Sets the value to the column title.
Default: slug, with first letter uppercase

->withTitle(string)
Render

Render the callback|string in each row, for the specific column.
Default: output the value
Parameters in callback:

  • $instance
  • ModelPage $modelPage
->withRender(callback|string)
Searchable

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)
Sortable

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)

RowAction

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

AdminTableView

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
Title

Sets the value to the view title.
Default: urlKey, with first letter uppercase

->withTitle(string)
Count

Sets the value to the view count.
Default: null

->withCount(string)
Count Callback

Sets the callback value to the view count.
Default: null Parameters in callback:

  • AdminTableView $view
->withCountCallback(callback|string)

AdminTableExtraTablenav

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

ViewPage

To get an instance of a ViewPage, use the wrapper method: \Morningtrain\WP\DatabaseModelAdminUi\ModelUI::viewPage().

Render

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)
Capability

Sets the value to the capability.
Default: ModelPage::capability

->withCapability(string)
Hide default view

Hide the default view.
Default: true

->hideDefaultView()

AcfCreatePage

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.

Save Callback

Calls the callback|string, when a Model is updated, through ACF.
Default: null
Parameters in callback|string:

  • $instance
  • $model
  • array $values
->withSaveCallback(callback|string)
Capability

Sets the value to the capability.
Default: ModelPage::capability

->withCapability(string)

AcfEditPage

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.

Load Field Callbacks

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([])
Save Callback

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)
Capability

Sets the value to the capability.
Default: ModelPage::capability

->withCapability(string)

AcfLoadField

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

MetaBox

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
Title

Sets the value to the meta box title.
Default: slug, with first letter uppercase

->withTitle(string)
High Priority

Sets the priority to high. Default: default

->withHighPriority()
Core Priority

Sets the priority to core. Default: default

->withCorePriority()
Low Priority

Sets the priority to low. Default: default

->withLowPriority()
Side Context

Sets the context to side. Default: normal

->onSideContext()
On ACF Edit Page

Sets the meta box to be rendered on Acf Edit Page.
Default: Admin Table

->onAcfEditPage()

Contributing

Thank you for your interest in contributing to the project.

Bug Report

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.

Support Questions

We do not provide support for this package.

Pull Requests

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Credits

License

The MIT License (MIT). Please see License File for more information.

Developed by

Morningtrain logo