2021-07-15 20:55:12 +02:00
|
|
|
<?php
|
|
|
|
|
2021-10-27 18:01:44 +02:00
|
|
|
namespace Drupal\farm_quick\Plugin\QuickForm;
|
2021-07-15 20:55:12 +02:00
|
|
|
|
2021-07-16 22:11:51 +02:00
|
|
|
use Drupal\Core\Access\AccessResult;
|
2021-07-15 20:55:12 +02:00
|
|
|
use Drupal\Core\Form\FormStateInterface;
|
2021-07-20 14:32:09 +02:00
|
|
|
use Drupal\Core\Messenger\MessengerInterface;
|
|
|
|
use Drupal\Core\Messenger\MessengerTrait;
|
2021-10-25 17:36:56 +02:00
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
2021-07-15 20:55:12 +02:00
|
|
|
use Drupal\Core\Plugin\PluginBase;
|
2021-07-16 22:11:51 +02:00
|
|
|
use Drupal\Core\Session\AccountInterface;
|
2023-06-13 18:53:49 +02:00
|
|
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
2021-07-15 20:55:12 +02:00
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for quick forms.
|
|
|
|
*/
|
2021-10-25 17:36:56 +02:00
|
|
|
class QuickFormBase extends PluginBase implements QuickFormInterface, ContainerFactoryPluginInterface {
|
2021-07-15 20:55:12 +02:00
|
|
|
|
2021-07-20 14:32:09 +02:00
|
|
|
use MessengerTrait;
|
2021-07-15 20:55:12 +02:00
|
|
|
use StringTranslationTrait;
|
|
|
|
|
2023-08-04 23:09:51 +02:00
|
|
|
/**
|
|
|
|
* The quick form ID.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected string $quickId;
|
|
|
|
|
2021-07-20 14:32:09 +02:00
|
|
|
/**
|
|
|
|
* Constructs a QuickFormBase object.
|
|
|
|
*
|
|
|
|
* @param array $configuration
|
|
|
|
* A configuration array containing information about the plugin instance.
|
|
|
|
* @param string $plugin_id
|
|
|
|
* The plugin_id for the plugin instance.
|
|
|
|
* @param mixed $plugin_definition
|
|
|
|
* The plugin implementation definition.
|
|
|
|
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
|
|
|
|
* The messenger service.
|
|
|
|
*/
|
|
|
|
public function __construct(array $configuration, $plugin_id, $plugin_definition, MessengerInterface $messenger) {
|
|
|
|
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
|
|
|
$this->messenger = $messenger;
|
|
|
|
}
|
|
|
|
|
2021-07-15 20:55:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
|
|
|
return new static(
|
|
|
|
$configuration,
|
|
|
|
$plugin_id,
|
2021-07-20 14:32:09 +02:00
|
|
|
$plugin_definition,
|
|
|
|
$container->get('messenger')
|
2021-07-15 20:55:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-04 23:09:51 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
final public function setQuickId(string $id) {
|
|
|
|
return $this->quickId = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
final public function getQuickId() {
|
|
|
|
return $this->quickId ?? $this->getPluginId();
|
|
|
|
}
|
|
|
|
|
2021-07-15 20:55:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getId() {
|
2023-08-04 23:09:51 +02:00
|
|
|
return $this->getQuickId();
|
2021-07-15 20:55:12 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 12:52:45 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getFormId() {
|
2023-08-04 23:09:51 +02:00
|
|
|
return $this->getQuickId();
|
2023-03-13 12:52:45 +01:00
|
|
|
}
|
|
|
|
|
2021-07-15 20:55:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2023-08-04 16:26:48 +02:00
|
|
|
public function getLabel() {
|
2021-07-15 20:55:12 +02:00
|
|
|
return $this->pluginDefinition['label'] ?? '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getDescription() {
|
|
|
|
return $this->pluginDefinition['description'] ?? '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getHelpText() {
|
|
|
|
return $this->pluginDefinition['helpText'] ?? '';
|
|
|
|
}
|
|
|
|
|
2021-07-16 22:11:51 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getPermissions() {
|
|
|
|
return $this->pluginDefinition['permissions'] ?? [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function access(AccountInterface $account) {
|
|
|
|
$permissions = $this->getPermissions();
|
|
|
|
return AccessResult::allowedIfHasPermissions($account, $permissions);
|
|
|
|
}
|
|
|
|
|
2021-07-15 20:55:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function buildForm(array $form, FormStateInterface $form_state) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function validateForm(array &$form, FormStateInterface $form_state) {
|
|
|
|
// Validation is optional.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function submitForm(array &$form, FormStateInterface $form_state) {
|
|
|
|
// Submit is optional, but presumably this will be overridden.
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|