diff --git a/config/sync/user.role.admin.yml b/config/sync/user.role.admin.yml
index 62b5d5c7..5aae0cc5 100644
--- a/config/sync/user.role.admin.yml
+++ b/config/sync/user.role.admin.yml
@@ -75,7 +75,6 @@ permissions:
- 'access user profiles'
- 'add commerce_log commerce_order admin comment'
- 'add flag lists'
- - 'administer commerce_license'
- 'administer commerce_order'
- 'administer commerce_payment'
- 'administer commerce_subscription'
diff --git a/config/sync/views.view.admin_users.yml b/config/sync/views.view.admin_users.yml
index 77fb490d..b2f7e9fb 100644
--- a/config/sync/views.view.admin_users.yml
+++ b/config/sync/views.view.admin_users.yml
@@ -45,6 +45,7 @@ dependencies:
- user
- user_email_verification
- views_bulk_operations
+ - views_conditional
- views_data_export
id: admin_users
label: 'Admin Users'
@@ -2775,7 +2776,74 @@ display:
entity_field: access
plugin_id: field
label: 'Last access'
- exclude: false
+ exclude: true
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: true
+ empty_zero: true
+ hide_alter_empty: true
+ click_sort_column: value
+ type: commerce_license_expiration
+ settings:
+ date_format: html_date
+ custom_date_format: d-m-Y
+ timezone: ''
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ access_1:
+ id: access_1
+ table: users_field_data
+ field: access
+ relationship: none
+ group_type: group
+ admin_label: ''
+ entity_type: user
+ entity_field: access
+ plugin_id: field
+ label: 'Dernier accès année'
+ exclude: true
alter:
alter_text: false
text: ''
@@ -2818,7 +2886,7 @@ display:
click_sort_column: value
type: timestamp
settings:
- date_format: html_date
+ date_format: html_year
custom_date_format: ''
timezone: ''
group_column: value
@@ -2831,6 +2899,63 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
+ views_conditional_field:
+ id: views_conditional_field
+ table: views_conditional
+ field: views_conditional_field
+ relationship: none
+ group_type: group
+ admin_label: ''
+ plugin_id: views_conditional_field
+ label: 'Last access '
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: false
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ if: access_1
+ condition: eq
+ equalto: '1970'
+ then: never
+ then_translate: 1
+ or: '{{ access }}'
+ or_translate: 1
+ strip_tags: 0
role_expire_expiry_data:
id: role_expire_expiry_data
table: users
@@ -2895,7 +3020,7 @@ display:
entity_type: commerce_license
entity_field: product_variation
plugin_id: field
- label: 'Licensed product variation'
+ label: License
exclude: false
alter:
alter_text: false
@@ -3592,20 +3717,22 @@ display:
views_bulk_operations_bulk_form: views_bulk_operations_bulk_form
name: name
mail: mail
- operations: operations
+ operations: mail
roles_target_id: roles_target_id
field_member_type: field_member_type
field_company: field_company
field_showroom: field_showroom
- access: access
created: created
- field_memo: field_memo
- verified: verified
- status: status
record_id: record_id
+ access: access
+ access_1: access_1
+ views_conditional_field: views_conditional_field
role_expire_expiry_data: role_expire_expiry_data
product_variation: product_variation
expires: product_variation
+ verified: verified
+ status: status
+ field_memo: field_memo
default: '-1'
info:
views_bulk_operations_bulk_form:
@@ -3651,9 +3778,23 @@ display:
default_sort_order: asc
align: ''
separator: ''
- empty_column: false
+ empty_column: true
responsive: ''
field_showroom:
+ sortable: false
+ default_sort_order: asc
+ align: ''
+ separator: ''
+ empty_column: true
+ responsive: ''
+ created:
+ sortable: true
+ default_sort_order: asc
+ align: ''
+ separator: ''
+ empty_column: false
+ responsive: ''
+ record_id:
sortable: false
default_sort_order: asc
align: ''
@@ -3667,14 +3808,33 @@ display:
separator: ''
empty_column: false
responsive: ''
- created:
- sortable: true
+ access_1:
+ sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
- field_memo:
+ views_conditional_field:
+ align: ''
+ separator: ''
+ empty_column: false
+ responsive: ''
+ role_expire_expiry_data:
+ sortable: false
+ default_sort_order: asc
+ align: ''
+ separator: ''
+ empty_column: true
+ responsive: ''
+ product_variation:
+ sortable: false
+ default_sort_order: asc
+ align: ''
+ separator: '
'
+ empty_column: true
+ responsive: ''
+ expires:
sortable: false
default_sort_order: asc
align: ''
@@ -3686,7 +3846,7 @@ display:
default_sort_order: asc
align: ''
separator: ''
- empty_column: false
+ empty_column: true
responsive: ''
status:
sortable: false
@@ -3695,33 +3855,12 @@ display:
separator: ''
empty_column: false
responsive: ''
- record_id:
+ field_memo:
sortable: false
default_sort_order: asc
align: ''
separator: ''
- empty_column: false
- responsive: ''
- role_expire_expiry_data:
- sortable: false
- default_sort_order: asc
- align: ''
- separator: ''
- empty_column: false
- responsive: ''
- product_variation:
- sortable: false
- default_sort_order: asc
- align: ''
- separator: '
'
- empty_column: false
- responsive: ''
- expires:
- sortable: false
- default_sort_order: asc
- align: ''
- separator: ''
- empty_column: false
+ empty_column: true
responsive: ''
override: true
sticky: true
diff --git a/web/modules/custom/materio_commerce/materio_commerce.module b/web/modules/custom/materio_commerce/materio_commerce.module
index ed27faf6..2c1a8936 100644
--- a/web/modules/custom/materio_commerce/materio_commerce.module
+++ b/web/modules/custom/materio_commerce/materio_commerce.module
@@ -1,11 +1,15 @@
getRoles();
if (in_array("admin", $roles)){
- $t="t";
$form['type']['#default_value'] = 'materio_order_type';
$form['type']['#disabled'] = true;
@@ -24,51 +27,132 @@ function materio_commerce_form_commerce_order_add_form_alter(&$form, &$form_stat
}
}
-function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
- if ($form_id !== 'user_form') return;
+function materio_commerce_form_role_delegation_role_assign_form_alter(&$form, &$form_state, $form_id) {
- $mail = $form['account']['mail']['#default_value'];
- $user_storage = \Drupal::entityTypeManager()->getStorage('user');
- $users = $user_storage->loadByProperties(['mail' => $mail]);
- $user = reset($users);
- // $roles = $user->getRoles();
+
+ /** @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') {
+ // // We only act on entities that have an owner, and user entities.
+ // return;
+ // }
$license_storage = \Drupal::entityTypeManager()->getStorage('commerce_license');
- $licenses = $license_storage->loadByProperties(['uid' => $user->id()]);
+ $licenses = $license_storage->loadByProperties(['uid' => $account->id()]);
if ($licenses) {
- $form['license'] = [
- "#type" => 'fieldset',
- "#title" => 'licenses'
- ];
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();
- $infos = [];
- $infos[] = $product->getTitle();
- $infos[] = $product_variation->getTitle();
-
$granted = $license->getGrantedTime();
- $infos[] = "granted: " . date('d-m-Y', $granted);
$expires = $license->getExpiresTime();
- $infos[] = "expires: " . ($expires === "0" ? 'never' : date('d-m-Y', $expires));
$license_edit_url = $license->toUrl();
- $license_link = Link::fromTextAndUrl('edit license', $license_edit_url);
- $infos[] = $license_link->toString();
+ $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("order " . $order_number . " (" . $order_state . ")", $order_url);
- $infos[] = $order_link->toString();
+ $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.
@product: @variation | granted: @granted | expires: @expires | @license_link | @order_link", array(
+ '@product' => $product->getTitle(),
+ '@variation' => $product_variation->getTitle(),
+ '@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()
+ ));
+
+ }
+ }
+
+
+}
+
+function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) {
+ if ($form_id !== 'user_form') return;
+
+ // WE USE FORM OBJECT TO GET THE ENTITY instead of followings
+ // $mail = $form['account']['mail']['#default_value'];
+ // $user_storage = \Drupal::entityTypeManager()->getStorage('user');
+ // $users = $user_storage->loadByProperties(['mail' => $mail]);
+ // $user = reset($users);
+ // $roles = $user->getRoles();
+
+
+ /** @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;
+ }
+
+ $entity = $form_object->getEntity();
+ $entity_type_id = $entity->getEntityTypeId();
+ if (!($entity instanceof EntityOwnerInterface) && $entity_type_id != 'user') {
+ // We only act on entities that have an owner, and user entities.
+ return;
+ }
+
+ $license_storage = \Drupal::entityTypeManager()->getStorage('commerce_license');
+ $licenses = $license_storage->loadByProperties(['uid' => $entity->id()]);
+
+ if ($licenses) {
+ // $form['license'] = [
+ // "#type" => 'fieldset',
+ // "#title" => 'licenses'
+ // ];
+ foreach ($licenses as $lid => $license) {
+ $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 = $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();
+ $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.
@product: @variation | granted: @granted | expires: @expires | @license_link | @order_link", array(
+ '@product' => $product->getTitle(),
+ '@variation' => $product_variation->getTitle(),
+ '@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()
+ ));
- $form['license']['license_'.$lid] = [
- "#type" => 'item',
- "#description" => implode(" | ", $infos)
- ];
}
}