social_auth_buttons-1.0.0-beta1/social_auth_buttons.module
social_auth_buttons.module
<?php
use Drupal\Component\Utility\NestedArray;
function _social_auth_form(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
$form['social_auth_buttons'] = [
'#type' => 'social_auth_buttons',
'#title' => t('Social Auth Buttons'),
];
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function social_auth_buttons_form_user_login_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
/* Your code here */
_social_auth_form($form['actions'], $form_state);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function social_auth_buttons_form_commerce_checkout_flow_multistep_default_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
/* Your code here */
if (isset($form['login']['returning_customer'])) {
_social_auth_form($form['login']['returning_customer'], $form_state);
}
}
/**
* Implements hook_theme().
*/
function social_auth_buttons_theme($existing, $type, $theme, $path) {
return [
'social_auth_buttons' => [
'render element' => 'element',
],
'social_auth_buttons_link' => [
'render element' => 'element',
],
];
}
/**
* Prepares variables for file form widget templates.
*
* Default template: social-auth-buttons.html.twig.
*
* @param array $variables
* An associative array containing:
* - element: A render element representing the social auth buttons.
*/
function template_preprocess_social_auth_buttons(&$variables) {
$element = $variables['element'];
$variables['attributes'] = [];
if (isset($element['#id'])) {
$variables['attributes']['id'] = $element['#id'];
}
if (!empty($element['#attributes']['class'])) {
$variables['attributes']['class'] = (array) $element['#attributes']['class'];
}
}
/**
* Prepares variables for file form widget templates.
*
* Default template: social-auth-buttons-link.html.twig.
*
* @param array $variables
* An associative array containing:
* - link: Link object.
*/
function template_preprocess_social_auth_buttons_link(&$variables) {
$element = $variables['element'];
$variables['attributes'] = [];
if (isset($element['#id'])) {
$variables['attributes']['id'] = $element['#id'];
}
if (!empty($element['#attributes']['class'])) {
$variables['attributes']['class'] = (array) $element['#attributes']['class'];
}
if (isset($element['#link'])) {
$variables['link'] = $element['#link'];
$url = $variables['link']->getUrl();
$variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $url->getOptions());
$variables['network'] = $element['#network'];
$variables['name'] = str_replace('social_auth_', '', $element['#name']);
}
}
