This project is not covered by Drupal’s security advisory policy.

The FormUI is a developer API meant to help build Drupal forms with Drupal's Form API. In short, it's an object-oriented wrapper around the Form API that is boiled down to an actual form array.

This is an alpha "release" and this API can change at any time!

Usage

function example_form($form, &$form_state) {
    module_load_include('module', 'formui');
    $formui = new FormUI();

    $options = array('example1' => 'Example 1', 'example2' => 'Example 2');

    $formui
      ->add(
        'some_field',
        $formui->textfield()
          ->setOption('title', 'Some Field')
      )
      ->add('another_field', $formui->select($options))
      ->add('submit', $formui->submit('Submit'));

    return $formui->generate();
}

For FormUIItem instances, you can use setOption() or use a method for the option you want to set. For example, to set the title, you can also just run: $formui->textfield()->title('Thing').

Documentation

Documentation is provided in the README file.

Drupal 8

The Drupal 8 version keeps almost all the same setup, but also includes a FormBase specific for dealing with building forms with the FormUI:

use Drupal\formui\FormUiBase;

class MyForm extends FormUiBase {
  public function buildFormUi(FormStateInterface $form_state, array $extra = array()) {
    $this->form->add($this->textfield()->label('Name'));
  }
}

Project information

Downloads