Experimental project

This is a sandbox project, which contains experimental code for developer use only.

This module allows you to use objects as forms. By using the ctools plugin system this module maps the form_id to the object. This enables you to contain all the form functions (get form, validate and submit) inside a single object.

For example, this will add the 'my_custom_form' as an form_id:

/**
 * Implements hook_cforms_form().
 */
function hook_cforms_form() {
  $plugins['my_custom_form'] = array(
    'name' => 'My Custom Form',
    'form' => array(
      'class' => 'MyCustomForm',
      'file' => 'MyCustomForm.inc',
      'path' => drupal_get_path('module', 'custom') . '/plugins/widgets',
    ),
  );
  return $plugins;
}

The object would be:

/**
 * Class WidgetAdminForm.
 */
class MyCustomWidget extends CFormsBase {

  /**
   * Get the renderable array of the form.
   *
   * @param array $form
   * @param array $form_state
   *
   * @return array
   */
  public function getForm(array $form, array &$form_state) {
    return $form;
  }

  /**
   * Submit handler function for the form.
   *
   * @param array $form
   * @param array $form_state
   */
  public function submitForm(array $form, array &$form_state) {}

}

There is still some stuff TODO:

  • Update the code with local changes
  • Supply API file
  • Add more tests!
  • Update README file

Project information