OOP Forms
Component ID
2671876
Component name
OOP Forms
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Downloads
285
Component created
Component changed
Component body
This module is for developers only. It does not provide any features for normal users.
OOP Forms module provides set of wrappers for building drupal forms in object oriented way.
It takes the burden of writing FAPI arrays manually off the developers
and let them build those ugly arrays with set of method calls.
The old way:
$form['text_field'] = array(
'#type' => 'textfield',
'#title' => t('Old text field'),
'#default_value' => 'This is exhausting',
'#description' => t('Manually created text field using FAPI array.'),
);
The new OOP way:
// Get OOP Forms service for easier use
/** @var Drupaloop_formsFormBuilder $builder */
$builder = Drupal::service('oop_forms.builder');
$form['text_field'] = $builder
->createTextField()
->setTitle(t('OOP text field'))
->setDefaultValue('This is fun!')
->setDescription(t('Text field generated with OOP forms service'))
->build()
;
This module is work in progress.
To add support for more FAPI elements, look for missing elements in DrupalCoreRenderElement namespace
(its files are located at core/lib/Drupal/Core/Render/Element).
