public function ExecutePHP::buildForm in Devel 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ ExecutePHP.php, line 23
Class
- ExecutePHP
- Defines a form that allows privileged users to execute arbitrary PHP code.
Namespace
Drupal\devel\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form = array(
'#title' => $this
->t('Execute PHP Code'),
'#description' => $this
->t('Execute some PHP code'),
);
$form['execute']['code'] = array(
'#type' => 'textarea',
'#title' => t('PHP code to execute'),
'#description' => t('Enter some code. Do not use <code><?php ?></code> tags.'),
'#default_value' => isset($_SESSION['devel_execute_code']) ? $_SESSION['devel_execute_code'] : '',
'#rows' => 20,
);
$form['execute']['actions'] = [
'#type' => 'actions',
];
$form['execute']['actions']['op'] = [
'#type' => 'submit',
'#value' => t('Execute'),
];
$form['#redirect'] = FALSE;
if (isset($_SESSION['devel_execute_code'])) {
unset($_SESSION['devel_execute_code']);
}
return $form;
}