getRoles(); if (in_array("admin", $roles)){ $t="t"; $form['type']['#default_value'] = 'materio_order_type'; $form['type']['#disabled'] = true; $form['customer']['uid']['#selection_handler'] = 'default:user_by_email'; } } function materio_commerce_form_user_form_alter(&$form, &$form_state, $form_id) { if ($form_id !== 'user_form') return; $mail = $form['account']['mail']['#default_value']; $user_storage = \Drupal::entityTypeManager()->getStorage('user'); $users = $user_storage->loadByProperties(['mail' => $mail]); $user = reset($users); // $roles = $user->getRoles(); $license_storage = \Drupal::entityTypeManager()->getStorage('commerce_license'); $licenses = $license_storage->loadByProperties(['uid' => $user->id()]); if ($licenses) { $form['license'] = [ "#type" => 'fieldset', "#title" => 'licenses' ]; foreach ($licenses as $lid => $license) { $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(); $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(); $form['license']['license_'.$lid] = [ "#type" => 'item', "#description" => implode(" | ", $infos) ]; } } }