twiked user page tabs

This commit is contained in:
Bachir Soussi Chiadmi 2021-03-11 23:14:16 +01:00
parent ce1beb7278
commit 9bae6d15ff
1 changed files with 49 additions and 0 deletions

View File

@ -149,3 +149,52 @@ function materio_user_entity_type_build(array &$entity_types) {
// https://drupal.stackexchange.com/a/230547 // https://drupal.stackexchange.com/a/230547
$entity_types['user']->setFormClass('modal', 'Drupal\user\RegisterForm'); $entity_types['user']->setFormClass('modal', 'Drupal\user\RegisterForm');
} }
/*
* hook_menu_local_tasks_alter
*/
function materio_user_menu_local_tasks_alter(&$data, $route_name){
$t="t";
// remove some tabs on user pages
// if (in_array($route_name, ['entity.user.canonical', 'entity.user.edit_form']) ) {
if (preg_match('/^entity\.user\./', $route_name)
|| in_array($route_name, [
'simplenews.newsletter_subscriptions_user',
'commerce_order.address_book.overview',
'entity.commerce_payment_method.collection',
'view.commerce_user_orders.order_page',
'view.commerce_user_subscriptions.page_1'
])) {
unset($data['tabs'][0]['profile.user_page:member']);
$data['tabs'][0]['entity.user.edit_form']['#weight'] = -20;
$data['tabs'][0]['simplenews.newsletter_subscriptions_user']['#weight'] = -9;
}
// foreach ($data['tabs'] as $key => $tab) {
// if ($key == 'profile.user_page:member') {
// unset($data['tabs'][$key]);
// }
// if ($key == 'entity.user.edit_form') {
// $data['tabs'][$key]['#weight'] = -200;
// }
//
// }
}
/*
* hook_local_tasks_alter
*/
// function materio_user_local_tasks_alter(&$local_tasks){
// $t="t";
// }
function materio_user_form_alter(array &$form, FormStateInterface $forme_state, $form_id){
if ($form_id == 'simplenews_subscriber_account_form') {
$user = \Drupal::currentUser();
$roles = $user->getRoles();
$t="t";
if (in_array('adherent', $roles)) {
unset($form['subscriptions']['widget']['#options']['companies']);
unset($form['subscriptions']['widget']['#options']['test']);
}
}
}