|
@@ -48,50 +48,64 @@ function materio_commerce_form_role_delegation_role_assign_form_alter(&$form, &$
|
|
$license_storage = \Drupal::entityTypeManager()->getStorage('commerce_license');
|
|
$license_storage = \Drupal::entityTypeManager()->getStorage('commerce_license');
|
|
$licenses = $license_storage->loadByProperties(['uid' => $account->id()]);
|
|
$licenses = $license_storage->loadByProperties(['uid' => $account->id()]);
|
|
|
|
|
|
-
|
|
|
|
if ($licenses) {
|
|
if ($licenses) {
|
|
- $description = t("This role is granted by a license. It cannot be removed manually.");
|
|
|
|
|
|
+ $licenses_by_role = [];
|
|
foreach ($licenses as $lid => $license) {
|
|
foreach ($licenses as $lid => $license) {
|
|
$licensed_role_id = $license->license_role->target_id;
|
|
$licensed_role_id = $license->license_role->target_id;
|
|
- $form["account"]["role_change"][$licensed_role_id]['#disabled'] = TRUE;
|
|
|
|
- $form["account"]["role_change"][$licensed_role_id]['#default_value'] = TRUE;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- $product_variation = $license->getPurchasedEntity();
|
|
|
|
- $product = null;
|
|
|
|
- if ($product_variation){
|
|
|
|
- $product = $product_variation->getProduct();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $granted = $license->getGrantedTime();
|
|
|
|
- $expires = $license->getExpiresTime();
|
|
|
|
|
|
+ $licenses_by_role[$licensed_role_id]['licenses'][] = $license;
|
|
$license_state = $license->getState()->getValue()['value'];
|
|
$license_state = $license->getState()->getValue()['value'];
|
|
- $license_edit_url = $license->toUrl();
|
|
|
|
- $license_link = Link::fromTextAndUrl(t('edit license'), $license_edit_url);
|
|
|
|
-
|
|
|
|
- $order = $license->getOriginatingOrder();
|
|
|
|
- if ($order) {
|
|
|
|
- $order_url = $order->toUrl();
|
|
|
|
- $order_state = $order->get('state')->first()->getValue()['value'];
|
|
|
|
- $order_number = $order->get('order_number')->first()->getValue()['value'];
|
|
|
|
- $order_link = Link::fromTextAndUrl(t("order @num (@state)", array(
|
|
|
|
- '@num' => $order_number,
|
|
|
|
- '@state' => $order_state
|
|
|
|
- )), $order_url);
|
|
|
|
|
|
+ if($license_state === 'active') {
|
|
|
|
+ $licenses_by_role[$licensed_role_id]['license_active'] = true;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ foreach ($licenses_by_role as $rid => $role_licenses) {
|
|
|
|
+ $license_active = isset($role_licenses['license_active']) ? true : false;
|
|
|
|
+ $description = "";
|
|
|
|
+ if($license_active) {
|
|
|
|
+ $form["account"]["role_change"][$rid]['#disabled'] = TRUE;
|
|
|
|
+ $form["account"]["role_change"][$rid]['#default_value'] = TRUE;
|
|
|
|
+
|
|
|
|
+ $description = t("This role is granted by a license. It cannot be removed manually.<br/>");
|
|
|
|
+ }
|
|
|
|
+ foreach ($role_licenses['licenses'] as $license) {
|
|
|
|
+ $license_state = $license->getState()->getValue()['value'];
|
|
|
|
+
|
|
|
|
+ $product_variation = $license->getPurchasedEntity();
|
|
|
|
+ $product = null;
|
|
|
|
+ if ($product_variation){
|
|
|
|
+ $product = $product_variation->getProduct();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $granted = $license->getGrantedTime();
|
|
|
|
+ $expires = $license->getExpiresTime();
|
|
|
|
+
|
|
|
|
+ $license_edit_url = $license->toUrl();
|
|
|
|
+ $license_link = Link::fromTextAndUrl(t('edit license'), $license_edit_url);
|
|
|
|
+
|
|
|
|
+ $order = $license->getOriginatingOrder();
|
|
|
|
+ if ($order) {
|
|
|
|
+ $order_url = $order->toUrl();
|
|
|
|
+ $order_state = $order->get('state')->first()->getValue()['value'];
|
|
|
|
+ $order_number = $order->get('order_number')->first()->getValue()['value'];
|
|
|
|
+ $order_link = Link::fromTextAndUrl(t("order @num (@state)", array(
|
|
|
|
+ '@num' => $order_number,
|
|
|
|
+ '@state' => $order_state
|
|
|
|
+ )), $order_url);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $description .= t("-- @product: @variation | license state: @license_state | granted: @granted | expires: @expires | @license_link | @order_link<br/>", array(
|
|
|
|
+ '@product' => $product ? $product->getTitle() : t('no product'),
|
|
|
|
+ '@variation' => $product_variation ? $product_variation->getTitle() : t('no variation'),
|
|
|
|
+ '@license_state' => $license_state,
|
|
|
|
+ '@granted' => date('d-m-Y', $granted),
|
|
|
|
+ '@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
|
|
|
|
+ '@license_link' => $license_link->toString(),
|
|
|
|
+ '@order_link' => $order ? $order_link->toString() : t('no order')
|
|
|
|
+ ));
|
|
|
|
|
|
- $description .= t("<br/>-- @product: @variation | license state: @license_state | granted: @granted | expires: @expires | @license_link | @order_link", array(
|
|
|
|
- '@product' => $product ? $product->getTitle() : t('no product'),
|
|
|
|
- '@variation' => $product_variation ? $product_variation->getTitle() : t('no variation'),
|
|
|
|
- '@license_state' => $license_state,
|
|
|
|
- '@granted' => date('d-m-Y', $granted),
|
|
|
|
- '@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
|
|
|
|
- '@license_link' => $license_link->toString(),
|
|
|
|
- '@order_link' => $order ? $order_link->toString() : t('no order')
|
|
|
|
- ));
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ $form["account"]["role_change"][$rid]['#description'] = $description;
|
|
}
|
|
}
|
|
- $form["account"]["role_change"][$licensed_role_id]['#description'] = $description;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -125,48 +139,63 @@ function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
|
|
$licenses = $license_storage->loadByProperties(['uid' => $entity->id()]);
|
|
$licenses = $license_storage->loadByProperties(['uid' => $entity->id()]);
|
|
|
|
|
|
if ($licenses) {
|
|
if ($licenses) {
|
|
- $description = t("This role is granted by a license. It cannot be removed manually.");
|
|
|
|
|
|
+ $licenses_by_role = [];
|
|
foreach ($licenses as $lid => $license) {
|
|
foreach ($licenses as $lid => $license) {
|
|
$licensed_role_id = $license->license_role->target_id;
|
|
$licensed_role_id = $license->license_role->target_id;
|
|
- $form["role_change"]["widget"][$licensed_role_id]['#disabled'] = TRUE;
|
|
|
|
- $form["role_change"]["widget"][$licensed_role_id]['#default_value'] = TRUE;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- $product_variation = $license->getPurchasedEntity();
|
|
|
|
- $product = null;
|
|
|
|
- if ($product_variation){
|
|
|
|
- $product = $product_variation->getProduct();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $granted = $license->getGrantedTime();
|
|
|
|
- $expires = $license->getExpiresTime();
|
|
|
|
|
|
+ $licenses_by_role[$licensed_role_id]['licenses'][] = $license;
|
|
$license_state = $license->getState()->getValue()['value'];
|
|
$license_state = $license->getState()->getValue()['value'];
|
|
- $license_edit_url = $license->toUrl();
|
|
|
|
- $license_link = Link::fromTextAndUrl(t('edit license'), $license_edit_url);
|
|
|
|
-
|
|
|
|
- $order = $license->getOriginatingOrder();
|
|
|
|
- if ($order) {
|
|
|
|
- $order_url = $order->toUrl();
|
|
|
|
- $order_state = $order->get('state')->first()->getValue()['value'];
|
|
|
|
- $order_number = $order->get('order_number')->first()->getValue()['value'];
|
|
|
|
- $order_link = Link::fromTextAndUrl(t("order @num (@state)", array(
|
|
|
|
- '@num' => $order_number,
|
|
|
|
- '@state' => $order_state
|
|
|
|
- )), $order_url);
|
|
|
|
|
|
+ if($license_state === 'active') {
|
|
|
|
+ $licenses_by_role[$licensed_role_id]['license_active'] = true;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ foreach ($licenses_by_role as $rid => $role_licenses) {
|
|
|
|
+ $license_active = isset($role_licenses['license_active']) ? true : false;
|
|
|
|
+ $description = "";
|
|
|
|
+ if($license_active) {
|
|
|
|
+ $form["role_change"]["widget"][$rid]['#disabled'] = TRUE;
|
|
|
|
+ $form["role_change"]["widget"][$rid]['#default_value'] = TRUE;
|
|
|
|
+
|
|
|
|
+ $description = t("This role is granted by a license. It cannot be removed manually.<br/>");
|
|
|
|
+ }
|
|
|
|
+ foreach ($role_licenses['licenses'] as $license) {
|
|
|
|
+ $license_state = $license->getState()->getValue()['value'];
|
|
|
|
+
|
|
|
|
+ $product_variation = $license->getPurchasedEntity();
|
|
|
|
+ $product = null;
|
|
|
|
+ if ($product_variation){
|
|
|
|
+ $product = $product_variation->getProduct();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $granted = $license->getGrantedTime();
|
|
|
|
+ $expires = $license->getExpiresTime();
|
|
|
|
+
|
|
|
|
+ $license_edit_url = $license->toUrl();
|
|
|
|
+ $license_link = Link::fromTextAndUrl(t('edit license'), $license_edit_url);
|
|
|
|
+
|
|
|
|
+ $order = $license->getOriginatingOrder();
|
|
|
|
+ if ($order) {
|
|
|
|
+ $order_url = $order->toUrl();
|
|
|
|
+ $order_state = $order->get('state')->first()->getValue()['value'];
|
|
|
|
+ $order_number = $order->get('order_number')->first()->getValue()['value'];
|
|
|
|
+ $order_link = Link::fromTextAndUrl(t("order @num (@state)", array(
|
|
|
|
+ '@num' => $order_number,
|
|
|
|
+ '@state' => $order_state
|
|
|
|
+ )), $order_url);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $description .= t("-- @product: @variation | license state: @license_state | granted: @granted | expires: @expires | @license_link | @order_link<br/>", array(
|
|
|
|
+ '@product' => $product ? $product->getTitle() : t('no product'),
|
|
|
|
+ '@variation' => $product_variation ? $product_variation->getTitle() : t('no variation'),
|
|
|
|
+ '@license_state' => $license_state,
|
|
|
|
+ '@granted' => date('d-m-Y', $granted),
|
|
|
|
+ '@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
|
|
|
|
+ '@license_link' => $license_link->toString(),
|
|
|
|
+ '@order_link' => $order ? $order_link->toString() : t('no order')
|
|
|
|
+ ));
|
|
|
|
|
|
- $description .= t("<br/>-- @product: @variation | license state: @license_state | granted: @granted | expires: @expires | @license_link | @order_link", array(
|
|
|
|
- '@product' => $product ? $product->getTitle() : t('no product'),
|
|
|
|
- '@variation' => $product_variation ? $product_variation->getTitle() : t('no variation'),
|
|
|
|
- '@license_state' => $license_state,
|
|
|
|
- '@granted' => date('d-m-Y', $granted),
|
|
|
|
- '@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
|
|
|
|
- '@license_link' => $license_link->toString(),
|
|
|
|
- '@order_link' => $order ? $order_link->toString() : t('no order')
|
|
|
|
- ));
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ $form["role_change"]["widget"][$rid]['#description'] = $description;
|
|
}
|
|
}
|
|
- $form["role_change"]["widget"][$licensed_role_id]['#description'] = $description;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|