passwd_only-8.x-1.x-dev/passwd_only.module

passwd_only.module
<?php

use Drupal\Core\Url;
/**
 * @file
 * Creates an user, who has the ability to login by password only.
 */

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Password Only Login.
 *
 * @mainpage
 *
 * @section project_page Project page
 * - @link https://drupal.org/project/passwd_only Drupal project "Password Only Login" @endlink
 *
 * @section git_repository Git repository
 * - @link http://drupalcode.org/project/passwd_only.git Drupal git repository "Password Only Login" @endlink
 */

/**
 * @defgroup drupal_hooks Drupal hooks
 * @{
 * Hooks used by the module.
 */

/**
 * Implements hook_help().
 */
function passwd_only_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    case 'help.page.passwd_only':
      $output = '';
      $output .= '<p>' . t('First of all you have to select a Drupal user account or create an new Drupal user account. The password you set for this account is the login password which is used by the password only login forms.') . '</p>';

      $output .= '<h2>' . t('Password Only Login page') . ' </h2>';

      $output .= '<p>' .
        t(
          'Go to <a href=":page">Password Only Login page</a> to log in only with password.',
          [':page' => Url::fromRoute('password_only.log-in-form')->toString()]
        ) . '</p>';

      $output .= '<h2>' . t('Password Only Login block') . ' </h2>';

      $output .= '<p>' .
        t(
          'Go to the <a href=":blocks">blocks administration page</a> and enable the Password Only Login block for your theme.',
          [':blocks' => Url::fromRoute('block.admin_display')->toString()]
        ) . '</p>';
      return $output;
  }

}

/**
 * Implements hook_user_view().
 */
function passwd_only_user_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  $config = \Drupal::config('passwd_only.all');
  if ($config->get('user') == $entity->id()) {
    $build['passwd_only'] = [
      '#type' => 'item',
      '#title' => t('Password Only Login'),
      '#markup' => t('This user is the password only login account.'),
    ];
  }
}

/**
 * Implements hook_user_delete().
 */
function passwd_only_user_delete(EntityInterface $entity) {
  $config = \Drupal::service('config.factory')->getEditable('passwd_only.all');
  if ($config->get('user') == $entity->id()) {
    $config->set('user', 0)->save();
  }
}

/**
 * @} End of "defgroup drupal_hooks".
 */

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc