Namespace
Drupal\devel\Form
File
-
src/Form/SwitchUserPageForm.php
View source
<?php
namespace Drupal\devel\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\devel\SwitchUserListHelper;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SwitchUserPageForm extends FormBase {
protected FormBuilderInterface $formBuilder;
protected SwitchUserListHelper $switchUserListHelper;
public static function create(ContainerInterface $container) : static {
$instance = parent::create($container);
$instance->switchUserListHelper = $container->get('devel.switch_user_list_helper');
$instance->formBuilder = $container->get('form_builder');
return $instance;
}
public function getFormId() : string {
return 'devel_switchuser_page_form';
}
public function buildForm(array $form, FormStateInterface $form_state) : array {
if ($accounts = $this->switchUserListHelper
->getUsers()) {
$form['devel_links'] = $this->switchUserListHelper
->buildUserList($accounts);
$form['devel_form'] = $this->formBuilder
->getForm(SwitchUserForm::class);
}
else {
$this->messenger
->addStatus('There are no user accounts present!');
}
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) : void {
}
public function submitForm(array &$form, FormStateInterface $form_state) : void {
}
}
Classes