Gateway is a WordPress plugin that provides fields and forms that work with your Eloquent models and Gateway Collections. We utilize a Collection (extended from the \Gateway\Collection class) to auto-generate a set of REST API routes. Now we need human-editing forms for our content type. This is where the fields definition comes into play.
Gateway Fields Example
Below is an example of a Collection Fields example for a newsletter subscribe form:
<?php
namespace ARCWP\Newsletter\Collections;
class Subscriber extends \Gateway\Collection {
protected $key = 'subscriber';
protected $fields = [
'email' => [
'type' => 'email',
'label' => 'Email Address',
'required' => true,
'placeholder' => 'Enter your email address',
],
];
}Notice in the example that we declare use of \Gateway\Collection. The collection is an Eloquent model, but supercharged to provide WordPress fields support. It further enables both inference of fields, or data integrity checks on fields to ensure what we define in a schema makes sense according to the underlying model.
Gateway Form Shortcode
To render yourGateway forms in Gutenberg or theme templates you can use the shortcode blueprint_form. The schema argument is required and this tells Blueprint which registered schema to utilize in building and processing the form.
[blueprint_form collection="subscriber"]Blueprint Form Render Class
In PHP you can render Gateway forms using the Gateway Form Render class:
<?php
use Gateway\Forms\Render;
use My\Plugin\Namespace\Collections\DocCollection;
// Render a create form based on the collection.
Render::form( DocCollection::class );