class ProfileForm in Entity Legal 4.0.x
Same name and namespace in other branches
- 8.2 src/Plugin/EntityLegal/ProfileForm.php \Drupal\entity_legal\Plugin\EntityLegal\ProfileForm
- 3.0.x src/Plugin/EntityLegal/ProfileForm.php \Drupal\entity_legal\Plugin\EntityLegal\ProfileForm
Method class for displaying a checkbox on the user register form.
Plugin annotation
@EntityLegal(
id = "form_link",
label = @Translation("Checkbox on signup form"),
type = "new_users",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\entity_legal\EntityLegalPluginBase implements EntityLegalPluginInterface
- class \Drupal\entity_legal\Plugin\EntityLegal\ProfileForm
- class \Drupal\entity_legal\EntityLegalPluginBase implements EntityLegalPluginInterface
Expanded class hierarchy of ProfileForm
File
- src/
Plugin/ EntityLegal/ ProfileForm.php, line 17
Namespace
Drupal\entity_legal\Plugin\EntityLegalView source
class ProfileForm extends EntityLegalPluginBase {
/**
* {@inheritdoc}
*/
public function execute(array &$context = []) {
if (!empty($this->documents)) {
$context['form']['actions']['submit']['#submit'][] = [
get_class($this),
'submitForm',
];
/** @var \Drupal\entity_legal\EntityLegalDocumentInterface $document */
foreach ($this->documents as $document) {
$context['form']['#cache']['tags'][] = "entity_legal_document:{$document->id()}";
$context['form']["legal_{$document->id()}"] = [
'#type' => 'checkbox',
'#title' => $document
->getAcceptanceLabel(),
'#default_value' => $document
->userHasAgreed(),
'#required' => TRUE,
];
$context['form']['#entity_legal'] = $this;
}
}
}
/**
* Submit handler for user register form.
*/
public static function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\entity_legal\EntityLegalDocumentInterface $document */
foreach ($form['#entity_legal']->documents as $document) {
if (!empty($form_state
->getValue([
'legal_' . $document
->id(),
]))) {
$published_version = $document
->getPublishedVersion();
$acceptance = \Drupal::entityTypeManager()
->getStorage(ENTITY_LEGAL_DOCUMENT_ACCEPTANCE_ENTITY_NAME)
->create([
'uid' => $form_state
->getValue('uid'),
'document_version_name' => $published_version
->id(),
]);
$acceptance
->save();
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityLegalPluginBase:: |
protected | property | The legal documents that implement this plugin. | |
EntityLegalPluginBase:: |
public | function | Get all Entity Legal Documents for this plugin. | |
EntityLegalPluginBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
ProfileForm:: |
public | function |
Execute callback for Entity Legal method plugin. Overrides EntityLegalPluginInterface:: |
1 |
ProfileForm:: |
public static | function | Submit handler for user register form. |