You are here

pathauto_i18n_user.module in Pathauto i18n 8

Same filename and directory in other branches
  1. 7 modules/pathauto_i18n_user/pathauto_i18n_user.module

Provides tools for creating multilanguage aliases for users.

File

modules/pathauto_i18n_user/pathauto_i18n_user.module
View source
<?php

/**
 * @file
 * Provides tools for creating multilanguage aliases for users.
 */

/**
 * PORTED to 8.x-1.x - pathauto_i18n.module:pathauto_i18n_field_widget_info_alter().
 *
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function pathauto_i18n_user_form_pathauto_patterns_form_alter(&$form, &$form_state) {
  $languages = language_list();
  $default_pattern = $form['user']['pathauto_user_pattern'];

  // Remove parents handlers.
  unset($default_pattern['#parents']);
  $form['user']['token_help']['#weight'] = 1;
  foreach ($languages as $language) {
    $pattern_name = 'pathauto_user_user_' . $language->language . '_pattern';
    $form['user'][$pattern_name] = $default_pattern;
    $form['user'][$pattern_name]['#title'] = t('Pattern for all @language user paths', array(
      '@language' => $language->name,
    ));
    $form['user'][$pattern_name]['#default_value'] = variable_get($pattern_name, '');
  }
}

/**
 * Implements hook_form_alter().
 */
function pathauto_i18n_user_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
    pathauto_i18n_configuration_form($form, empty($form_state['user']) ? new StdClass() : $form_state['user'], 'user', 'user');
  }
}

/**
 * Implements hook_user_insert().
 */
function pathauto_i18n_user_user_insert(&$edit, $account, $category) {
  pathauto_i18n_init_property($account, 'user', 'user');
  pathauto_i18n_process_entity_object($account, 'user', $account->pathauto_i18n_status, 'insert');
}

/**
 * Implements hook_user_update().
 */
function pathauto_i18n_user_user_update(&$edit, $account, $category) {
  pathauto_i18n_init_property($account, 'user', 'user');
  pathauto_i18n_process_entity_object($account, 'user', $account->pathauto_i18n_status, 'update');
}

/**
 * Implements hook_user_delete().
 */
function pathauto_i18n_user_user_delete($account) {
  pathauto_i18n_delete_settings($account->uid, 'user');
}

/**
 * Implements hook_user_load().
 */
function pathauto_i18n_user_user_load($users) {

  // Attach pathauto i18n settings to user object.
  foreach ($users as $user) {
    $uids[] = $user->uid;
  }
  if (!empty($uids)) {
    $result = pathauto_i18n_load_settings($uids, 'user');
    foreach ($result as $record) {
      $users[$record->entity_id]->path['pathauto_i18n_status'] = $record->path_status;
    }
  }
}

/**
 * Implements hook_pathauto_alias_alter().
 */
function pathauto_i18n_user_pathauto_alias_alter(&$alias, &$context) {
  $operations = array(
    'insert',
    'update',
    'bulkupdate',
  );

  // Skip insert of alias for all languages.
  if (!empty($context['module']) && $context['module'] == 'user' && in_array($context['op'], $operations)) {
    $entity = $context['data']['user'];

    // Run bulk update.
    $settings = pathauto_i18n_load_settings_single($entity->uid, 'user');
    if ($context['op'] == 'bulkupdate' && !empty($settings['path_status'])) {
      $entity->pathauto_i18n_status = $settings['path_status'];
      pathauto_i18n_process_entity_object($entity, 'user', $entity->pathauto_i18n_status, 'update');
    }
    if (isset($entity->pathauto_i18n_status) && $entity->pathauto_i18n_status && $context['language'] == LANGUAGE_NONE) {
      $alias = '';
    }
  }
}

/**
 * Implements hook_action_info().
 */
function pathauto_i18n_user_action_info() {
  return array(
    'pathauto_i18n_user_generate_alias' => array(
      'type' => 'user',
      'label' => t('Enable generation of aliases for all languages'),
      'configurable' => FALSE,
      'behavior' => array(
        'changes_property',
      ),
      'triggers' => array(
        'any',
      ),
    ),
    'pathauto_i18n_user_remove_alias' => array(
      'type' => 'user',
      'label' => t('Disable generation of aliases for all languages'),
      'configurable' => FALSE,
      'behavior' => array(
        'changes_property',
      ),
      'triggers' => array(
        'any',
      ),
    ),
  );
}

/**
 * Sets the status of a pathauto_i18n_status to 1.
 *
 * @param object $user
 *   A user object.
 *
 * @param array $context
 *   (optional) Array of additional information about what triggered the action.
 *   Not used for this action.
 *
 * @ingroup actions
 */
function pathauto_i18n_user_generate_alias($user, $context = array()) {
  $user->pathauto_i18n_status = 1;
}

/**
 * Sets the status of a pathauto_i18n_status to 0.
 *
 * @param object $user
 *   A user object.
 *
 * @param array $context
 *   (optional) Array of additional information about what triggered the action.
 *   Not used for this action.
 *
 * @ingroup actions
 */
function pathauto_i18n_user_remove_alias($user, $context = array()) {
  $user->pathauto_i18n_status = 0;
}

Functions

Namesort descending Description
pathauto_i18n_user_action_info Implements hook_action_info().
pathauto_i18n_user_form_alter Implements hook_form_alter().
pathauto_i18n_user_form_pathauto_patterns_form_alter PORTED to 8.x-1.x - pathauto_i18n.module:pathauto_i18n_field_widget_info_alter().
pathauto_i18n_user_generate_alias Sets the status of a pathauto_i18n_status to 1.
pathauto_i18n_user_pathauto_alias_alter Implements hook_pathauto_alias_alter().
pathauto_i18n_user_remove_alias Sets the status of a pathauto_i18n_status to 0.
pathauto_i18n_user_user_delete Implements hook_user_delete().
pathauto_i18n_user_user_insert Implements hook_user_insert().
pathauto_i18n_user_user_load Implements hook_user_load().
pathauto_i18n_user_user_update Implements hook_user_update().