2019-05-31 23:05:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Contains materio_user.module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use \Drupal\Core\Form\FormStateInterface;
|
|
|
|
use \Drupal\Core\Block\BlockPluginInterface;
|
2021-01-12 10:17:49 +01:00
|
|
|
use \Drupal\Core\Url;
|
|
|
|
use \Drupal\Core\Link;
|
2019-05-31 23:05:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* implements hook_form_FORM_ID_alter()
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function materio_user_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
|
2021-01-27 22:49:52 +01:00
|
|
|
|
2019-05-31 23:05:37 +02:00
|
|
|
$form['name']['#attributes'] += array(
|
|
|
|
"v-model" => "mail",
|
2021-01-27 22:49:52 +01:00
|
|
|
// "@keyup.enter" => "login"
|
2019-05-31 23:05:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$form['pass']['#attributes'] = array(
|
|
|
|
"v-model" => "password",
|
2021-01-27 22:49:52 +01:00
|
|
|
// "@keyup.enter" => "login"
|
2019-05-31 23:05:37 +02:00
|
|
|
);
|
|
|
|
|
2021-01-12 10:17:49 +01:00
|
|
|
$url = Url::fromRoute('user.pass');
|
|
|
|
$form['pass']['#description'] = Link::fromTextAndUrl('Forgot your password?', $url)->toString();
|
|
|
|
// "<a href="{{ path('user.pass') }}">{{ 'Forgot your password?'|t }}</a>";
|
|
|
|
|
2019-05-31 23:05:37 +02:00
|
|
|
$form['actions']['submit']['#attributes'] = array(
|
|
|
|
"@click.prevent" => "login"
|
|
|
|
);
|
|
|
|
|
2021-01-27 22:49:52 +01:00
|
|
|
$form['message'] = array(
|
2021-01-28 12:26:27 +01:00
|
|
|
'#weight' => -10,
|
2021-01-27 22:49:52 +01:00
|
|
|
'#markup' => '
|
|
|
|
<span class="login-message" v-if="loginMessage">
|
|
|
|
{{ loginMessage }}
|
|
|
|
</span>
|
|
|
|
'
|
|
|
|
);
|
|
|
|
|
2019-05-31 23:05:37 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 15:54:03 +02:00
|
|
|
function materio_user_form_user_modal_form_alter(&$form, FormStateInterface $form_state, $form_id) {
|
|
|
|
$form['account']['mail']['#attributes'] = array(
|
|
|
|
"v-model" => "mail",
|
|
|
|
"@keyup.enter" => "register",
|
|
|
|
"placeholder" => $form['account']['mail']['#title'],
|
|
|
|
"title" => $form['account']['mail']['#description']
|
|
|
|
);
|
|
|
|
|
|
|
|
// https://drupal.stackexchange.com/a/217112
|
|
|
|
// Get default process function array:
|
|
|
|
$element_info = element_info('password_confirm');
|
|
|
|
$process = $element_info['#process'];
|
|
|
|
// Add our process function to the array:
|
|
|
|
$process[] = '_materio_user_process_password_confirm';
|
|
|
|
$form['account']['pass']['#process'] = $process;
|
|
|
|
|
|
|
|
$form['actions']['submit']['#attributes'] = array(
|
|
|
|
"@click.prevent" => "register",
|
2021-01-11 21:16:42 +01:00
|
|
|
"@keyup.enter" => "register",
|
|
|
|
"ref" => "register"
|
|
|
|
// ":class" => "can_register"
|
2019-10-07 15:54:03 +02:00
|
|
|
);
|
|
|
|
|
2021-01-28 12:26:27 +01:00
|
|
|
$form['account']['message'] = array(
|
|
|
|
'#weight' => -10,
|
|
|
|
'#markup' => '
|
|
|
|
<span class="register-message" v-if="registerMessage">
|
|
|
|
{{ registerMessage }}
|
|
|
|
</span>
|
|
|
|
'
|
|
|
|
);
|
2019-10-07 15:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function _materio_user_process_password_confirm($element){
|
|
|
|
// ksm($element);
|
2021-01-12 10:17:49 +01:00
|
|
|
$element['pass1']['#description'] = t('Password must contains Lowercase and Uppercase Letters, numbers, and punctuation.');
|
2019-10-07 15:54:03 +02:00
|
|
|
$element['pass1']['#attributes'] += array(
|
|
|
|
"v-model" => "pass1",
|
2021-01-11 21:16:42 +01:00
|
|
|
"placeholder" => $element['pass1']['#title'],
|
|
|
|
":class" => "psswd_class"
|
2019-10-07 15:54:03 +02:00
|
|
|
);
|
|
|
|
$element['pass2']['#attributes'] += array(
|
|
|
|
"v-model" => "pass2",
|
|
|
|
"placeholder" => $element['pass2']['#title']
|
|
|
|
|
|
|
|
);
|
|
|
|
return $element;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns HTML for a form element.
|
|
|
|
* Prepares variables for form element templates.
|
|
|
|
*
|
|
|
|
* Default template: form-element.html.twig.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties of the element.
|
|
|
|
* Properties used: #title, #title_display, #description, #id, #required,
|
|
|
|
* #children, #type, #name, #label_for.
|
|
|
|
*/
|
|
|
|
// function materio_user_preprocess_form_element(&$vars) {
|
|
|
|
// $element = $vars['element'];
|
|
|
|
// if($element['#type'] == 'password' && $element['#array_parents'][0] == 'account'){
|
|
|
|
// ksm($vars);
|
|
|
|
// // $vars['attributes']['placeholder'] = $element['#title'];
|
|
|
|
// $vars['element']['#attributes']['placeholder'] = $element['#title'];
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-31 23:05:37 +02:00
|
|
|
/**
|
|
|
|
* implements hook_block_view_BASE_BLOCK_ID_alter()
|
|
|
|
*
|
|
|
|
* https://www.drupal.org/project/drupal/issues/2626224
|
|
|
|
*/
|
|
|
|
function materio_user_block_view_user_login_block_alter(array &$build, BlockPluginInterface $block) {
|
|
|
|
$build['#pre_render'][] = '_materio_user_user_login_block_pre_render';
|
|
|
|
}
|
|
|
|
|
|
|
|
function _materio_user_user_login_block_pre_render(array $build){
|
|
|
|
$user_links = &$build['content']['user_links'];
|
|
|
|
$items = &$user_links['#items'];
|
2021-01-28 13:19:57 +01:00
|
|
|
|
|
|
|
unset($items['create_account']);
|
|
|
|
// $items['create_account']['#url']->mergeOptions(array(
|
|
|
|
// "attributes" => array(
|
|
|
|
// "@click.prevent" => "create_account"
|
|
|
|
// )
|
|
|
|
// ));
|
|
|
|
|
|
|
|
// Do not handle passward reset with vue
|
|
|
|
// $items['request_password']['#url']->mergeOptions(array(
|
|
|
|
// 'attributes' => array(
|
|
|
|
// "@click.prevent" => "request_password"
|
|
|
|
// )
|
|
|
|
// ));
|
2019-05-31 23:05:37 +02:00
|
|
|
return $build;
|
|
|
|
}
|
2019-10-07 15:54:03 +02:00
|
|
|
|
|
|
|
function materio_user_entity_type_build(array &$entity_types) {
|
|
|
|
// https://drupal.stackexchange.com/a/230547
|
|
|
|
$entity_types['user']->setFormClass('modal', 'Drupal\user\RegisterForm');
|
|
|
|
}
|
2021-03-11 23:14:16 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|