Download the PHP package e0ipso/schema-forms without Composer

On this page you can find all versions of the php package e0ipso/schema-forms. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package schema-forms

Schema Forms

Schema Forms builds forms for PHP frameworks from a JSON Schema that describes the data. You give it the schema and, optionally, a UI schema with per-property display hints. It returns a form definition for the framework.

Drupal is the only supported framework. The generator returns a Drupal Form API render array.

Installation

A Drupal project that uses this library usually requires it already. To require it yourself:

The package requires PHP 8.3 or later. CI runs on PHP 8.3 and 8.4. The Drupal generator uses Drupal core classes, and Drupal core is only a dev dependency here, so run the generator inside a Drupal site.

Usage

Take this JSON Schema for a registration form:

And this UI schema:

Pass both to the generator. Decode the schema to objects and the UI schema to arrays:

$form is this render array. The root container also carries #json_schema (the decoded schema) and #element_validate, left out here:

The input schema must be a valid draft-04 JSON Schema whose root type is object. Anything else makes transform() throw a TypeError.

Context keys

The Context accepts three keys, all optional:

How schema types become elements

JSON Schema Form API element
string textfield
string with "format": "email" email
integer number with #step 1
number number
boolean checkbox
any type with enum radios, options from the enum
array whose items has an enum checkboxes, options from the enum
any other array an open details element with one control per item, an "Append an item" button and a remove button per item. Both buttons use AJAX.
object with properties an open details element with one control per sub-property
a property with const the constant as #markup, with no input

A type with no element in this list, such as null, renders as a disabled item that says the property cannot be edited. It does not disappear from the form.

When type is a list such as ["string", "null"], the generator uses the first entry. Put null last: ["null", "string"] renders as the "cannot be edited" item.

The element title comes from ui:title, then the schema title, then the property name with _ and - turned into spaces and each word capitalized. Enum option labels come from ui:enum mappings, or the enum value formatted the same way.

UI schema data

The same data shape can be collected with different form controls. The UI schema picks them. Its keys are property names. For an object property, nest the sub-property hints under the property's key. An array property passes its hints on to every item.

Supported controls:

Other keys are ignored.

Validating submissions

The root container has an #element_validate callback. When Drupal validates the form, it:

  1. Removes the add and remove button values that array properties leave in the submission.
  2. Casts the submitted strings to the schema types. Numeric strings become int or float, "0" and "1" become booleans on a boolean property, and an empty string becomes NULL on a nullable property that cannot hold it.
  3. Validates the result against the schema with justinrainbow/json-schema. Each error is set on the element it belongs to. Errors that match no element are joined into one error on the container.

Limitations

Development

composer test runs GrumPHP. It runs PHPUnit, PHP_CodeSniffer with the Drupal and DrupalPractice standards, PHP lint, phpmnd, composer normalize, and YAML and JSON lint.

GrumPHP also installs git hooks that check commit messages and branch names. Commits follow Conventional Commits (fix(drupal): ..., with a subject of 50 characters or fewer). Branches are named <type>/<kebab-case>, for example fix/enum-options. semantic-release tags a release from the commit messages on every push to master.


All versions of schema-forms with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
ext-json Version *
e0ipso/shaper Version ^1.2
justinrainbow/json-schema Version ^5.2 || ^6.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package e0ipso/schema-forms contains the following files

Loading the files please wait ...