DevelExecutePHP.php in Devel PHP 8
File
src/Plugin/Block/DevelExecutePHP.php
View source
<?php
declare (strict_types=1);
namespace Drupal\devel_php\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DevelExecutePHP extends BlockBase implements ContainerFactoryPluginInterface {
protected $formBuilder;
public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilderInterface $formBuilder) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->formBuilder = $formBuilder;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : self {
return new self($configuration, $plugin_id, $plugin_definition, $container
->get('form_builder'));
}
protected function blockAccess(AccountInterface $account) {
return AccessResult::allowedIfHasPermission($account, 'execute php code');
}
public function build() {
return $this->formBuilder
->getForm('Drupal\\devel_php\\Form\\ExecutePHP', FALSE);
}
}