locomotivemtl/charcoal-contrib-formio

Charcoal service provider to add a form builder property input using form.io.

0.1.2.2 2022-05-11 21:06 UTC

README

License Latest Stable Version Code Quality Coverage Status Build Status

A Charcoal Charcoal service provider to add a form builder property input using form.io.

Table of Contents

Installation

The preferred (and only supported) method is with Composer:

$ composer require locomotivemtl/charcoal-contrib-formio

Dependencies

Required

Configuration

Add the formio module to the modules list in the site's config file.

"modules": {
    "charcoal/formio/formio": {}
}

Usage

Three property type are provided by this package :

  • formio/form (Form builder input)
  • formio/schema (Form schema)
  • formio/submission (To save a form submission)
"my_property": {
    "type": "formio/form",
    "l10n": false,
    "label": "My form property"
},
"my_property": {
    "type": "formio/schema",
    "l10n": false,
    "label": "My schema property"
},
"my_property_submission": {
      "type": "formio/submission",
      "l10n": false,
      "label": "My submission property"
}

Note that formio properties do not support l10n for now.

To update a form when saving the object you must call the method createOrUpdateRelation() on the property. This example saves or updates the form builder schema for a property called test. This code should be found in the object's controller.

/**
 * {@inheritdoc}
 *
 * @see StorableTrait::preSave()
 * @return boolean
 */
protected function preSave()
{
    $this->test = $this->p('test')->createOrUpdateRelation($this->test, null);

    return parent::preSave();
}

/**
 * {@inheritdoc}
 *
 * @see StorableTrait::preUpdate
 * @param array $properties Optional properties to update.
 * @return boolean
 */
protected function preUpdate(array $properties = null)
{
    $clone = clone $this; // Avoid calling `load()` on current object.
    $this->test = $this->p('test')->createOrUpdateRelation($this->test, $clone->load()->test);

    return parent::preUpdate($properties);
}

Development

To install the development environment:

$ composer install

To run the scripts (phplint, phpcs, and phpunit):

$ composer test

Resources

API Documentation

Development Dependencies

  • [php-coveralls/php-coveralls][phpcov]
  • [phpunit/phpunit][phpunit]
  • [squizlabs/php_codesniffer][phpcs]

Coding Style

The charcoal-contrib-formio module follows the Charcoal coding-style:

Coding style validation / enforcement can be performed with composer phpcs. An auto-fixer is also available with composer phpcbf.

Credits

License

Charcoal is licensed under the MIT license. See LICENSE for details.