QuickForm.php in farmOS 2.x
File
modules/core/quick/src/Form/QuickForm.php
View source
<?php
namespace Drupal\farm_quick\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\farm_quick\QuickFormManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class QuickForm extends FormBase {
protected $quickFormManager;
protected $quickFormId;
public function __construct(QuickFormManager $quick_form_manager) {
$this->quickFormManager = $quick_form_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.quick_form'));
}
public function getFormId() {
return 'quick_form';
}
public function getTitle(string $id) {
return $this->quickFormManager
->createInstance($id)
->getLabel();
}
public function access(AccountInterface $account, string $id) {
return $this->quickFormManager
->createInstance($id)
->access($account);
}
public function buildForm(array $form, FormStateInterface $form_state, $id = NULL) {
$this->quickFormId = $id;
$quick_form = $this->quickFormManager
->createInstance($id);
$form = $quick_form
->buildForm($form, $form_state);
if (empty($form['actions']['submit'])) {
$form['actions'] = [
'#type' => 'actions',
'#weight' => 1000,
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
}
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
$this->quickFormManager
->createInstance($this->quickFormId)
->validateForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->quickFormManager
->createInstance($this->quickFormId)
->submitForm($form, $form_state);
}
}