You are here

public function ExecutePHP::submitForm in Devel PHP 8

Plugin annotation

@SuppressWarnings(PHPMD . EvalExpression);

Overrides FormInterface::submitForm

File

src/Form/ExecutePHP.php, line 90

Class

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

Namespace

Drupal\devel_php\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) : void {
  $code = $form_state
    ->getValue('code');
  try {
    ob_start();

    // phpcs:ignore
    print eval($code);

    // phpcs:enable
    $this->develDumper
      ->message(ob_get_clean());
  } catch (\Throwable $error) {
    $this
      ->messenger()
      ->addError($error
      ->getMessage());
  }
  $this->session
    ->set('devel_execute_code', $code);
}