You are here

public function ExecutePHP::buildForm in Devel PHP 8

Plugin annotation

@SuppressWarnings(PHPMD . BooleanArgumentFlag);

Overrides FormInterface::buildForm

File

src/Form/ExecutePHP.php, line 52

Class

ExecutePHP
Defines a form that allows privileged users to execute arbitrary PHP code.

Namespace

Drupal\devel_php\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, bool $details_open = TRUE) : array {
  $form['#redirect'] = FALSE;
  $code = $this->session
    ->get('devel_execute_code', '');
  $form['execute'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('PHP code to execute'),
    '#open' => !empty($code) || $details_open,
  ];
  $form['execute']['code'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('PHP code to execute'),
    '#title_display' => 'invisible',
    '#description' => $this
      ->t('Enter some code. Do not use <code>&lt;?php ?&gt;</code> tags.'),
    '#default_value' => $code,
    '#rows' => 20,
    '#attributes' => [
      'style' => 'font-family: monospace; font-size: 1.25em;',
    ],
  ];
  $form['execute']['op'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Execute'),
  ];
  if ($this->session
    ->has('devel_execute_code')) {
    $this->session
      ->remove('devel_execute_code');
  }
  return $form;
}