3 namespace Drupal\devel\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Defines a form that allows privileged users to execute arbitrary PHP code.
11 class ExecutePHP extends FormBase {
16 public function getFormId() {
17 return 'devel_execute_form';
23 public function buildForm(array $form, FormStateInterface $form_state) {
25 '#title' => $this->t('Execute PHP Code'),
26 '#description' => $this->t('Execute some PHP code'),
28 $form['execute']['code'] = array(
29 '#type' => 'textarea',
30 '#title' => t('PHP code to execute'),
31 '#description' => t('Enter some code. Do not use <code><?php ?></code> tags.'),
32 '#default_value' => (isset($_SESSION['devel_execute_code']) ? $_SESSION['devel_execute_code'] : ''),
35 $form['execute']['op'] = array('#type' => 'submit', '#value' => t('Execute'));
36 $form['#redirect'] = FALSE;
37 if (isset($_SESSION['devel_execute_code'])) {
38 unset($_SESSION['devel_execute_code']);
47 public function submitForm(array &$form, FormStateInterface $form_state) {
49 $code = $form_state->getValue('code');
51 $_SESSION['devel_execute_code'] = $code;