Version 1
[yaffs-website] / web / modules / contrib / devel / src / Form / ExecutePHP.php
1 <?php
2
3 namespace Drupal\devel\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Defines a form that allows privileged users to execute arbitrary PHP code.
10  */
11 class ExecutePHP extends FormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return 'devel_execute_form';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   public function buildForm(array $form, FormStateInterface $form_state) {
24     $form = array(
25       '#title' => $this->t('Execute PHP Code'),
26       '#description' => $this->t('Execute some PHP code'),
27     );
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>&lt;?php ?&gt;</code> tags.'),
32       '#default_value' => (isset($_SESSION['devel_execute_code']) ? $_SESSION['devel_execute_code'] : ''),
33       '#rows' => 20,
34     );
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']);
39     }
40
41     return $form;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function submitForm(array &$form, FormStateInterface $form_state) {
48     ob_start();
49     $code = $form_state->getValue('code');
50     print eval($code);
51     $_SESSION['devel_execute_code'] = $code;
52     dpm(ob_get_clean());
53   }
54
55 }