open_connect-8.x-1.x-dev/open_connect.module
open_connect.module
<?php
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_ENTITY_TYPE_delete().
*
* @param Drupal\Core\Entity\EntityInterface $entity
*/
function open_connect_user_delete(EntityInterface $entity) {
// Deletes all open connect entities of the given user entity.
/** @var \Drupal\open_connect\OpenConnectStorageInterface $storage */
$storage = \Drupal::service('entity_type.manager')->getStorage('open_connect');
$entities = $storage->loadMultipleByUser($entity);
$storage->delete($entities);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* // @todo: needed?
*/
function open_connect_form_user_form_alter(&$form, &$form_state) {
if (isset($form['account'])) {
$account_form = &$form['account'];
}
else {
$account_form = &$form;
}
$account = \Drupal::currentUser();
if (!$account->hasPermission('open_connect set own password')) {
$account_form['current_pass']['#access'] = FALSE;
$account_form['current_pass_required_values']['#value'] = [];
$account_form['pass']['#access'] = FALSE;
$account_form['pass']['#required'] = FALSE;
}
}
/**
* Implements hook_form_FORM_ID_alter().
*
* // @todo: needed?
*/
function open_connect_form_user_profile_form_alter(&$form, &$form_state) {
if (isset($form['account'])) {
$account_form = &$form['account'];
}
else {
$account_form = &$form;
}
$account = \Drupal::currentUser();
if (!empty($account_form['pass']['#access']) && !$account->hasPermission('open_connect set own password')) {
$account_form['current_pass']['#access'] = FALSE;
$account_form['current_pass_required_values']['#value'] = [];
$account_form['pass']['#access'] = FALSE;
}
}
/**
* Gets the uri to return after authentication.
*
* @param $current_uri
* Current uri.
*
* @return string
* The return uri.
*/
function open_connect_get_return_uri($current_uri) {
return $current_uri == '/user/login' ? '/user' : $current_uri;
}
