social_auth_vipps-8.x-2.1/social_auth_vipps.module
social_auth_vipps.module
<?php
/**
* @file
* Hook implementations for Social Auth Vipps module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\social_auth_vipps\Form\VippsAuthSettingsForm;
/**
* Implements hook_help().
*/
function social_auth_vipps_help($route_name, RouteMatchInterface $route_match) {
$output = '';
switch ($route_name) {
case 'social_auth_vipps.settings_form':
$output = '<h3>' . t('Configuration instructions') . '</h3>';
$output .= '<p>';
$output .= t('Configuration instructions and other useful documentation can be found at the <a href="@doc-url">Social Auth documentation</a>.',
['@doc-url' => 'https://www.drupal.org/docs/8/modules/social-api/social-api-2x/social-auth-2x/installing-social-auth-2x']);
$output .= '</p>';
break;
}
return $output;
}
/**
* Implements hook_form_alter().
*/
function social_auth_vipps_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id === 'user_login_form') {
social_auth_vipps_show_vipps_login_button($form, $form_state);
}
}
/**
* Show login button.
*
* @param array $form
* Login form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Login form state.
*/
function social_auth_vipps_show_vipps_login_button(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Config\ConfigFactoryInterface $configFactory */
$configFactory = Drupal::service('config.factory');
$config = $configFactory->get(VippsAuthSettingsForm::SETTINGS);
if (boolval($config->get('show_in_login_form'))) {
$config = \Drupal::configFactory()->getEditable('social_auth.settings');
$btnImg = '/' . $config->get('log_in_with_vipps_btn');
$form['login_with_vipps_button'] = [
'#type' => 'item',
'#markup' => sprintf("<div class='vipps-button-group'><a href='%s' class='%s' id = '%s'><img src='%s' alt='" . t('vipps login') . "'></a></div>",
Url::fromRoute('social_auth_vipps.redirect_to_vipps')->toString(),
'login-with-vipps-link',
'login-with-vipps-link',
$btnImg
),
'#weight' => -1,
];
$form['#attached']['library'][] = 'social_auth_vipps/social_auth_vipps';
}
}
/**
* Implements hook_config_schema_info_alter().
*/
function social_auth_vipps_config_schema_info_alter(&$definitions) {
$definitions["social_auth.settings"]["mapping"]['log_in_with_vipps_btn'] = [
'type' => 'string',
'label' => 'Log in with Vipps button',
'description' => 'Path to the Log in with Vipps button.',
];
}
