fixed linvesed roles display in user edit form
This commit is contained in:
parent
aff162514b
commit
287a57a5d3
|
@ -48,14 +48,20 @@ 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.");
|
||||||
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]['#disabled'] = TRUE;
|
||||||
$form["account"]["role_change"][$licensed_role_id]['#default_value'] = TRUE;
|
$form["account"]["role_change"][$licensed_role_id]['#default_value'] = TRUE;
|
||||||
|
|
||||||
|
|
||||||
$product_variation = $license->getPurchasedEntity();
|
$product_variation = $license->getPurchasedEntity();
|
||||||
|
$product = null;
|
||||||
|
if ($product_variation){
|
||||||
$product = $product_variation->getProduct();
|
$product = $product_variation->getProduct();
|
||||||
|
}
|
||||||
|
|
||||||
$granted = $license->getGrantedTime();
|
$granted = $license->getGrantedTime();
|
||||||
$expires = $license->getExpiresTime();
|
$expires = $license->getExpiresTime();
|
||||||
|
@ -64,6 +70,7 @@ function materio_commerce_form_role_delegation_role_assign_form_alter(&$form, &$
|
||||||
$license_link = Link::fromTextAndUrl(t('edit license'), $license_edit_url);
|
$license_link = Link::fromTextAndUrl(t('edit license'), $license_edit_url);
|
||||||
|
|
||||||
$order = $license->getOriginatingOrder();
|
$order = $license->getOriginatingOrder();
|
||||||
|
if ($order) {
|
||||||
$order_url = $order->toUrl();
|
$order_url = $order->toUrl();
|
||||||
$order_state = $order->get('state')->first()->getValue()['value'];
|
$order_state = $order->get('state')->first()->getValue()['value'];
|
||||||
$order_number = $order->get('order_number')->first()->getValue()['value'];
|
$order_number = $order->get('order_number')->first()->getValue()['value'];
|
||||||
|
@ -71,20 +78,21 @@ function materio_commerce_form_role_delegation_role_assign_form_alter(&$form, &$
|
||||||
'@num' => $order_number,
|
'@num' => $order_number,
|
||||||
'@state' => $order_state
|
'@state' => $order_state
|
||||||
)), $order_url);
|
)), $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(
|
$description .= t("<br/>-- @product: @variation | granted: @granted | expires: @expires | @license_link | @order_link", array(
|
||||||
'@product' => $product->getTitle(),
|
'@product' => $product ? $product->getTitle() : t('no product'),
|
||||||
'@variation' => $product_variation->getTitle(),
|
'@variation' => $product_variation ? $product_variation->getTitle() : t('no variation'),
|
||||||
'@granted' => date('d-m-Y', $granted),
|
'@granted' => date('d-m-Y', $granted),
|
||||||
'@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
|
'@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
|
||||||
'@license_link' => $license_link->toString(),
|
'@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) {
|
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()]);
|
$licenses = $license_storage->loadByProperties(['uid' => $entity->id()]);
|
||||||
|
|
||||||
if ($licenses) {
|
if ($licenses) {
|
||||||
// $form['license'] = [
|
$description = t("This role is granted by a license. It cannot be removed manually.");
|
||||||
// "#type" => 'fieldset',
|
|
||||||
// "#title" => 'licenses'
|
|
||||||
// ];
|
|
||||||
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]['#disabled'] = TRUE;
|
||||||
|
@ -127,7 +132,10 @@ function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
|
||||||
|
|
||||||
|
|
||||||
$product_variation = $license->getPurchasedEntity();
|
$product_variation = $license->getPurchasedEntity();
|
||||||
|
$product = null;
|
||||||
|
if ($product_variation){
|
||||||
$product = $product_variation->getProduct();
|
$product = $product_variation->getProduct();
|
||||||
|
}
|
||||||
|
|
||||||
$granted = $license->getGrantedTime();
|
$granted = $license->getGrantedTime();
|
||||||
$expires = $license->getExpiresTime();
|
$expires = $license->getExpiresTime();
|
||||||
|
@ -136,6 +144,7 @@ function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
|
||||||
$license_link = Link::fromTextAndUrl(t('edit license'), $license_edit_url);
|
$license_link = Link::fromTextAndUrl(t('edit license'), $license_edit_url);
|
||||||
|
|
||||||
$order = $license->getOriginatingOrder();
|
$order = $license->getOriginatingOrder();
|
||||||
|
if ($order) {
|
||||||
$order_url = $order->toUrl();
|
$order_url = $order->toUrl();
|
||||||
$order_state = $order->get('state')->first()->getValue()['value'];
|
$order_state = $order->get('state')->first()->getValue()['value'];
|
||||||
$order_number = $order->get('order_number')->first()->getValue()['value'];
|
$order_number = $order->get('order_number')->first()->getValue()['value'];
|
||||||
|
@ -143,17 +152,19 @@ function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
|
||||||
'@num' => $order_number,
|
'@num' => $order_number,
|
||||||
'@state' => $order_state
|
'@state' => $order_state
|
||||||
)), $order_url);
|
)), $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(
|
$description .= t("<br/>-- @product: @variation | granted: @granted | expires: @expires | @license_link | @order_link", array(
|
||||||
'@product' => $product->getTitle(),
|
'@product' => $product ? $product->getTitle() : t('no product'),
|
||||||
'@variation' => $product_variation->getTitle(),
|
'@variation' => $product_variation ? $product_variation->getTitle() : t('no variation'),
|
||||||
'@granted' => date('d-m-Y', $granted),
|
'@granted' => date('d-m-Y', $granted),
|
||||||
'@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
|
'@expires' => $expires === "0" ? 'never' : date('d-m-Y', $expires),
|
||||||
'@license_link' => $license_link->toString(),
|
'@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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue