class EntityLegalDocumentAcceptanceForm in Entity Legal 4.0.x
Same name and namespace in other branches
- 8.2 src/Form/EntityLegalDocumentAcceptanceForm.php \Drupal\entity_legal\Form\EntityLegalDocumentAcceptanceForm
- 3.0.x src/Form/EntityLegalDocumentAcceptanceForm.php \Drupal\entity_legal\Form\EntityLegalDocumentAcceptanceForm
Provides a confirmation form for deleting a custom block entity.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\entity_legal\Form\EntityLegalDocumentAcceptanceForm
Expanded class hierarchy of EntityLegalDocumentAcceptanceForm
1 file declares its use of EntityLegalDocumentAcceptanceForm
- EntityLegalDocument.php in src/
Entity/ EntityLegalDocument.php
File
- src/
Form/ EntityLegalDocumentAcceptanceForm.php, line 14
Namespace
Drupal\entity_legal\FormView source
class EntityLegalDocumentAcceptanceForm extends FormBase {
/**
* The Entity Legal Document used by this form.
*
* @var \Drupal\entity_legal\EntityLegalDocumentInterface
*/
protected $document;
/**
* The private temp store.
*
* @var \Drupal\Core\TempStore\PrivateTempStore
*/
protected $tempStore;
/**
* Builds a new form instance.
*
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $private_temp_store_factory
* The private temp store factory service.
*/
public function __construct(PrivateTempStoreFactory $private_temp_store_factory) {
$this->tempStore = $private_temp_store_factory
->get('entity_legal');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('tempstore.private'));
}
/**
* Sets the legal document.
*
* @param \Drupal\entity_legal\EntityLegalDocumentInterface $document
* The legal document.
*/
public function setDocument(EntityLegalDocumentInterface $document) {
$this->document = $document;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'entity_legal_document_acceptance_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$has_agreed = $this->document
->userHasAgreed();
$form['agree'] = [
'#title' => $this->document
->getAcceptanceLabel(),
'#type' => 'checkbox',
'#required' => TRUE,
'#default_value' => $has_agreed,
'#disabled' => $has_agreed,
];
$form['submit'] = [
'#value' => t('Submit'),
'#type' => 'submit',
'#access' => !$has_agreed,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$published_version = $this->document
->getPublishedVersion();
\Drupal::entityTypeManager()
->getStorage(ENTITY_LEGAL_DOCUMENT_ACCEPTANCE_ENTITY_NAME)
->create([
'document_version_name' => $published_version
->id(),
])
->save();
// Restore potential postponed messages and show them on the correct page.
// @see \Drupal\entity_legal\Plugin\EntityLegal\Redirect::execute()
if ($grouped_messages = $this->tempStore
->get('postponed_messages')) {
foreach ($grouped_messages as $type => $messages) {
foreach ($messages as $message) {
$this
->messenger()
->addMessage($message, $type);
}
}
$this->tempStore
->delete('postponed_messages');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityLegalDocumentAcceptanceForm:: |
protected | property | The Entity Legal Document used by this form. | |
EntityLegalDocumentAcceptanceForm:: |
protected | property | The private temp store. | |
EntityLegalDocumentAcceptanceForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
EntityLegalDocumentAcceptanceForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
EntityLegalDocumentAcceptanceForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
EntityLegalDocumentAcceptanceForm:: |
public | function | Sets the legal document. | |
EntityLegalDocumentAcceptanceForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
EntityLegalDocumentAcceptanceForm:: |
public | function | Builds a new form instance. | |
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. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
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. | |
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. |