|
@@ -48,14 +48,20 @@ function materio_commerce_form_role_delegation_role_assign_form_alter(&$form, &$
|
|
|
$license_storage = \Drupal::entityTypeManager()->getStorage('commerce_license');
|
|
|
$licenses = $license_storage->loadByProperties(['uid' => $account->id()]);
|
|
|
|
|
|
+
|
|
|
if ($licenses) {
|
|
|
+ $description = t("This role is granted by a license. It cannot be removed manually.");
|
|
|
foreach ($licenses as $lid => $license) {
|
|
|
$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 = $product_variation->getProduct();
|
|
|
+ $product = null;
|
|
|
+ if ($product_variation){
|
|
|
+ $product = $product_variation->getProduct();
|
|
|
+ }
|
|
|
|
|
|
$granted = $license->getGrantedTime();
|
|
|
$expires = $license->getExpiresTime();
|
|
@@ -64,27 +70,29 @@ function materio_commerce_form_role_delegation_role_assign_form_alter(&$form, &$
|
|
|
$license_link = Link::fromTextAndUrl(t('edit license'), $license_edit_url);
|
|
|
|
|
|
$order = $license->getOriginatingOrder();
|
|
|
- $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);
|
|
|
-
|
|
|
- $form["account"]["role_change"][$licensed_role_id]['#description'] = t("This role is granted by a license. It cannot be removed manually.<br/> @product: @variation | granted: @granted | expires: @expires | @license_link | @order_link", array(
|
|
|
- '@product' => $product->getTitle(),
|
|
|
- '@variation' => $product_variation->getTitle(),
|
|
|
+ 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("<br/>-- @product: @variation | 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'),
|
|
|
'@granted' => date('d-m-Y', $granted),
|
|
|
'@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
|
|
|
'@license_link' => $license_link->toString(),
|
|
|
- '@order_link' => $order_link->toString()
|
|
|
+ '@order_link' => $order ? $order_link->toString() : t('no order')
|
|
|
));
|
|
|
|
|
|
}
|
|
|
+ $form["account"]["role_change"][$licensed_role_id]['#description'] = $description;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
|
|
@@ -116,10 +124,7 @@ function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
|
|
|
$licenses = $license_storage->loadByProperties(['uid' => $entity->id()]);
|
|
|
|
|
|
if ($licenses) {
|
|
|
- // $form['license'] = [
|
|
|
- // "#type" => 'fieldset',
|
|
|
- // "#title" => 'licenses'
|
|
|
- // ];
|
|
|
+ $description = t("This role is granted by a license. It cannot be removed manually.");
|
|
|
foreach ($licenses as $lid => $license) {
|
|
|
$licensed_role_id = $license->license_role->target_id;
|
|
|
$form["role_change"]["widget"][$licensed_role_id]['#disabled'] = TRUE;
|
|
@@ -127,7 +132,10 @@ function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
|
|
|
|
|
$product_variation = $license->getPurchasedEntity();
|
|
|
- $product = $product_variation->getProduct();
|
|
|
+ $product = null;
|
|
|
+ if ($product_variation){
|
|
|
+ $product = $product_variation->getProduct();
|
|
|
+ }
|
|
|
|
|
|
$granted = $license->getGrantedTime();
|
|
|
$expires = $license->getExpiresTime();
|
|
@@ -136,24 +144,27 @@ function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
|
|
|
$license_link = Link::fromTextAndUrl(t('edit license'), $license_edit_url);
|
|
|
|
|
|
$order = $license->getOriginatingOrder();
|
|
|
- $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);
|
|
|
-
|
|
|
- $form["role_change"]["widget"][$licensed_role_id]['#description'] = t("This role is granted by a license. It cannot be removed manually.<br/> @product: @variation | granted: @granted | expires: @expires | @license_link | @order_link", array(
|
|
|
- '@product' => $product->getTitle(),
|
|
|
- '@variation' => $product_variation->getTitle(),
|
|
|
+ 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("<br/>-- @product: @variation | 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'),
|
|
|
'@granted' => date('d-m-Y', $granted),
|
|
|
'@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
|
|
|
'@license_link' => $license_link->toString(),
|
|
|
- '@order_link' => $order_link->toString()
|
|
|
+ '@order_link' => $order ? $order_link->toString() : t('no order')
|
|
|
));
|
|
|
|
|
|
}
|
|
|
+ $form["role_change"]["widget"][$licensed_role_id]['#description'] = $description;
|
|
|
}
|
|
|
|
|
|
|