public function Role::alterEntityOwnerForm in Commerce License 8.2
Alter a form for an entity owned by the license owner.
This is for use by license type plugins that change something on an entity owned by the license owner when they grant the license.
This allows the license type plugin to disable elements of the form if they are being granted by the license, to prevent them being removed while the license is active. For example, the role plugin locks the role that it grants a user on that user's edit form.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
string $form_id: The form ID.
\Drupal\commerce_license\Entity\LicenseInterface $license: The license being considered.
\Drupal\Core\Entity\EntityInterface $form_entity: The entity being edited in the form. It is active, and either owned by the license owner, or is the actual license owner user entity.
Overrides GrantedEntityLockingInterface::alterEntityOwnerForm
See also
File
- src/
Plugin/ Commerce/ LicenseType/ Role.php, line 100
Class
- Role
- Provides a license type which grants one or more roles.
Namespace
Drupal\commerce_license\Plugin\Commerce\LicenseTypeCode
public function alterEntityOwnerForm(array &$form, FormStateInterface $form_state, $form_id, LicenseInterface $license, EntityInterface $form_entity) {
if ($form_entity
->getEntityTypeId() != 'user') {
// Only act on a user form.
return;
}
$licensed_role_id = $license->license_role->target_id;
$form['account']['roles'][$licensed_role_id]['#disabled'] = TRUE;
$form['account']['roles'][$licensed_role_id]['#default_value'] = TRUE;
$form['account']['roles'][$licensed_role_id]['#description'] = t("This role is granted by a license. It cannot be removed manually.");
}