added 'add license' action in role_delgation and user edit forms

This commit is contained in:
Bachir Soussi Chiadmi 2022-11-17 22:36:03 +01:00
parent 20a8dc404e
commit ad3ef95a7b
2 changed files with 14 additions and 7 deletions

View File

@ -0,0 +1,6 @@
materio_commerce.commerce_license.add_page:
route_name: entity.commerce_license.add_page
title: 'Add license'
appears_on:
- entity.user.edit_form
- role_delegation.edit_form

View File

@ -1,9 +1,10 @@
<?php
// use Drupal\Core\Form\FormBuilder;
// use Drupal\Core\Url;
use \Drupal\Core\Link;
use Drupal\Core\Entity\EntityInterface;
// use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityFormInterface;
use Drupal\Core\Form\FormStateInterface;
// use Drupal\Core\Form\FormStateInterface;
use Drupal\user\EntityOwnerInterface;
@ -29,15 +30,12 @@ function materio_commerce_form_commerce_order_add_form_alter(&$form, &$form_stat
function materio_commerce_form_role_delegation_role_assign_form_alter(&$form, &$form_state, $form_id) {
/** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
$form_object = $form_state->getFormObject();
// /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
// $form_object = $form_state->getFormObject();
// if (!($form_object instanceof EntityFormInterface)) {
// // We're only interested in forms for an entity.
// return;
// }
/** @var \Drupal\user\UserInterface $account */
$account = $form_state->getBuildInfo()['args'][0];
// $entity = $form_object->getEntity();
// $entity_type_id = $entity->getEntityTypeId();
// if (!($entity instanceof EntityOwnerInterface) && $entity_type_id != 'user') {
@ -45,6 +43,9 @@ function materio_commerce_form_role_delegation_role_assign_form_alter(&$form, &$
// return;
// }
/** @var \Drupal\user\UserInterface $account */
$account = $form_state->getBuildInfo()['args'][0];
$license_storage = \Drupal::entityTypeManager()->getStorage('commerce_license');
$licenses = $license_storage->loadByProperties(['uid' => $account->id()]);