public function FormBuilderWrapper::prepareForm in Devel 8.3
Same name and namespace in other branches
- 8 webprofiler/src/Form/FormBuilderWrapper.php \Drupal\webprofiler\Form\FormBuilderWrapper::prepareForm()
- 8.2 webprofiler/src/Form/FormBuilderWrapper.php \Drupal\webprofiler\Form\FormBuilderWrapper::prepareForm()
- 4.x webprofiler/src/Form/FormBuilderWrapper.php \Drupal\webprofiler\Form\FormBuilderWrapper::prepareForm()
Prepares a structured form array.
Adds required elements, executes any hook_form_alter functions, and optionally inserts a validation token to prevent tampering.
Parameters
string $form_id: A unique string identifying the form for validation, submission, theming, and hook_form_alter functions.
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Passed in here so that hook_form_alter() calls can use it, as well.
Overrides FormBuilder::prepareForm
File
- webprofiler/
src/ Form/ FormBuilderWrapper.php, line 28
Class
- FormBuilderWrapper
- Class FormBuilderWrapper.
Namespace
Drupal\webprofiler\FormCode
public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
parent::prepareForm($form_id, $form, $form_state);
if (!$this->buildForms) {
$this->buildForms = [];
}
$elements = [];
foreach ($form as $key => $value) {
if (strpos($key, '#') !== 0) {
$elements[$key]['#title'] = isset($value['#title']) ? $value['#title'] : NULL;
$elements[$key]['#access'] = isset($value['#access']) ? $value['#access'] : NULL;
$elements[$key]['#type'] = isset($value['#type']) ? $value['#type'] : NULL;
}
}
$buildInfo = $form_state
->getBuildInfo();
$class = get_class($buildInfo['callback_object']);
$method = new \ReflectionMethod($class, 'buildForm');
$this->buildForms[$buildInfo['form_id']] = [
'class' => [
'class' => $class,
'method' => 'buildForm',
'file' => $method
->getFilename(),
'line' => $method
->getStartLine(),
],
'form' => $elements,
];
return $form;
}