function ExecutePHP::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\Form

Code

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>&lt;?php ?&gt;</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;
}