class QuickForm in farmOS 2.x
Same name in this branch
- 2.x modules/core/quick/src/Form/QuickForm.php \Drupal\farm_quick\Form\QuickForm
- 2.x modules/core/quick/src/Annotation/QuickForm.php \Drupal\farm_quick\Annotation\QuickForm
Form that renders quick forms.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\farm_quick\Form\QuickForm
Expanded class hierarchy of QuickForm
File
- modules/
core/ quick/ src/ Form/ QuickForm.php, line 16
Namespace
Drupal\farm_quick\FormView source
class QuickForm extends FormBase {
/**
* The quick form manager.
*
* @var \Drupal\farm_quick\QuickFormManager
*/
protected $quickFormManager;
/**
* The quick form ID.
*
* @var string
*/
protected $quickFormId;
/**
* Class constructor.
*
* @param \Drupal\farm_quick\QuickFormManager $quick_form_manager
* The quick form manager.
*/
public function __construct(QuickFormManager $quick_form_manager) {
$this->quickFormManager = $quick_form_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.quick_form'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'quick_form';
}
/**
* Get the title of the quick form.
*
* @param string $id
* The quick form ID.
*
* @return string
* Quick form title.
*/
public function getTitle(string $id) {
return $this->quickFormManager
->createInstance($id)
->getLabel();
}
/**
* Checks access for a specific quick form.
*
* @param \Drupal\Core\Session\AccountInterface $account
* Run access checks for this account.
* @param string $id
* The quick form ID.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(AccountInterface $account, string $id) {
return $this->quickFormManager
->createInstance($id)
->access($account);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $id = NULL) {
// Save the quick form ID.
$this->quickFormId = $id;
// Load the quick form.
$quick_form = $this->quickFormManager
->createInstance($id);
$form = $quick_form
->buildForm($form, $form_state);
// Add a submit button, if one wasn't provided.
if (empty($form['actions']['submit'])) {
$form['actions'] = [
'#type' => 'actions',
'#weight' => 1000,
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
}
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$this->quickFormManager
->createInstance($this->quickFormId)
->validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->quickFormManager
->createInstance($this->quickFormId)
->submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
QuickForm:: |
protected | property | The quick form ID. | |
QuickForm:: |
protected | property | The quick form manager. | |
QuickForm:: |
public | function | Checks access for a specific quick form. | |
QuickForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
QuickForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
QuickForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
QuickForm:: |
public | function | Get the title of the quick form. | |
QuickForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
QuickForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
QuickForm:: |
public | function | Class constructor. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |