Download the PHP package steirico/kirby-plugin-custom-add-fields without Composer
On this page you can find all versions of the php package steirico/kirby-plugin-custom-add-fields. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download steirico/kirby-plugin-custom-add-fields
More information about steirico/kirby-plugin-custom-add-fields
Files in steirico/kirby-plugin-custom-add-fields
Package kirby-plugin-custom-add-fields
Short Description Custom fields for Kirby's add dialog. This plugin allows to define the fields shown on the page add dialog in a page's blueprint.
License MIT
Informations about the package kirby-plugin-custom-add-fields
Kirby custom Add Fields Plugin
Custom fields for Kirby's add dialog. This plugin allows to define the fields shown on Kirby's page add dialog in the corresponding page's blueprint.
Installation
Use one of the alternatives below.
Download
Download and copy this repository to /site/plugins/kirby-plugin-custom-add-fields
.
Git submodule
Composer
Compatibility
Kirby | Plugin |
---|---|
pre 3.6 | 1.5.0 |
3.6 and newer | 2.0.0 and newer |
Usage
Defining custom Add Fields
This plugin adds the extra property addFields
to page blueprints.
To define custom add fields do as you would do for defining regular fields
but put the definition in the property addFields
.
/blueprints/pages/remote.yml
:
Reusing and Extending
The plugin supports the extends
keyword for reusing and extending fields:
/blueprints/pages/event.yml
:
See the kirby docs for more information on reusing and extending field.
In such a manner, kirby's default add fields (title
and slug
) can be reused and extended:
/blueprints/pages/book.yml
:
Using custom Add Fields
Values of custom add fields that correspond to fields of the page blueprint are
taken into account for the new page straightforwardly. In the example above the value of title
in the add page dialog will be set as page's title
.
slug
Handling
In order to have kirby adding pages correctly the property slug
has to be set.
There are three ways to define a page's slug
:
- Add a custom add field named
slug
in order to define theslug
manually. - If a field named
slug
is missing the plugin will set theslug
based on the current timestamp. - Set/overwrite the
slug
in a pages hook script (see below).
Using custom Add Fields in Hook Scripts
The values of the custom add fields can be used on the server side for modifying the page to be added.
To do so one can register a page.create:after
hook and modify the page
object.
The plugin also registers a generic hook which automatically detects and calls the
page model's static
method named hookPageCreate($page)
. Define a page model and the method as follow:
/site/models/remote.php
:
If exceptions are thrown in page.create:after
hooks or in hookPageCreate($page)
,
a corresponding error is sent back to the panel, but the newly created page remains.
In such cases it is advisable to catch exceptions and delete the newly created page:
Configure Redirects
Kirby's add dialog redirects to the newly created page. Since there is a related kirby issue if slugs are changed in hooks, this behavior can not be reproduced reliably. Therefore, the plugin's default behavior is to remain on the actual panel page after a page has been added.
If desired, redirect to the newly created page is possible on a per blueprint basis by setting the property redirect
to true
:
/blueprints/pages/parent.yml
:
If redirection to an existing page after creation is required, redirect
can be set to that page id.
/blueprints/pages/parent.yml
:
Force a specific Template
The template to be used for the new page can be forced by a field of the current page. By default,
if a field called forcedTemplate
exists on the current page its value is taken into account
as template for the new page.
The field can be changed by kirby options:
/site/config/config.php
:
Skip Add Dialog
The plugin allows to skip the add dialog (see forum).
/blueprints/pages/parent.yml
:
Beside setting the property skip: true
one has to define the template for the new page.
This can be achieved either by setting the property forcedTemplate
or by the means
described in Force a specific Template.
Show / hide Template Select
As of Kirby 3.5.0 the add dialog's template select is hidden if only one option is available (except in debug mode). By default, the plugin imitates this behavior in respect of the Kirby version.
Independently of the Kirby version in use, the plugins allows control/force a certain behavior by the
kirby option forceTemplateSelectionField
:
/site/config/config.php
:
Setting the option to true
will always make the add dialog show the template select.
Setting it to false
will hide the template select if only one template is available.
Know issues
There are some known issues related to this plugin:
- Some fields Fields such as the pages field perform additional requests to the backend. Although the pages field works as of v1.1.1, such fields may not work with this plugin. Feel free to file an issue if you encounter a broken field.
- When installed, the kirby3-security-headers adds CSP headers to the panel, breaking this plugin. As a workaround, you may disable it like this:
License
MIT