first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,175 @@
<?php
/*
* @file
* Function file to administer the MB User module settings.
*/
/**
* Provides the MB User settings form.
*/
function mb_user_admin() {
$module = 'mb_user';
$mb_user_mappings = mb_get_mappings($module);
$mb_user_values = mb_get_values($module);
$form['#mappings'] = $mb_user_mappings;
foreach ($mb_user_mappings as $type => $v) {
// Provide "Cancel" button settings.
$form[$module][$type][$module . '_cancel_' . $type] = array(
'#type' => 'select',
'#options' => mb_cancel_button_positions(),
'#default_value' => variable_get($module . '_cancel_' . $type, 0),
);
// Provide "Save and continue" button settings.
$form[$module][$type][$module . '_sac_' . $type] = array(
'#type' => 'select',
'#options' => mb_save_button_positions($module),
'#default_value' => variable_get($module . '_sac_' . $type, 0)
);
// Provide "Save and create new" button settings.
$form[$module][$type][$module . '_sacn_' . $type] = array(
'#type' => 'select',
'#options' => mb_save_button_positions($module),
'#default_value' => variable_get($module . '_sacn_' . $type, 0)
);
}
$form['submit']['save'] = array(
'#type' => 'submit',
'#name' => 'save',
'#value' => t('Save')
);
$form['submit']['reset'] = array(
'#type' => 'submit',
'#name' => 'reset',
'#value' => t('Reset to defaults'),
);
return $form;
}
/**
* Display the MB User settings form page.
*
* @return
* The complete HTML formatted administer page.
*/
function theme_mb_user_admin($variables) {
_mb_load_css('admin');
$module = 'mb_user';
$mappings = array();
$output = '';
$extra_info = '';
$rows = array();
$form = drupal_get_form($module . '_admin');
$mappings = $form['#mappings'];
$output = '<h3>' . t('User settings') . '</h3>';
$output .= '<p>' . t('Which %module functions are used by different user pages.', array('%module' => t('More Buttons User'))) . '</p>';
$header = array(t('Cancel'), t('Save and continue'), t('Save and create new'));
$i = 1;
foreach ($mappings as $type => $maps) {
// Provide own odd/even functionality.
$evenodd = $i % 2 ? 'odd-mb' : 'even-mb';
$evenodd = $i & 1 ? 'odd-mb' : 'even-mb';
$rows[] = array('data' => array($maps['name'], array('colspan' => 2)), 'class' => array($evenodd . ' ' . $evenodd . '-type'));
// The row contains the form elements.
$rows[] = array(
'data' => array(
drupal_render($form[$module][$type][$module . '_cancel_' . $type]),
drupal_render($form[$module][$type][$module . '_sac_' . $type]),
drupal_render($form[$module][$type][$module . '_sacn_' . $type])
),
'class' => array($evenodd . ' ' . $evenodd . '-elements')
);
unset($form[$module][$type]);
++$i;
}
$output .= theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array('class' => array('mb-admin-table', $module . '-admin-table'))
));
// Display additional informations.
if ($extra_info != '') {
$output .= $extra_info;
}
$output .= drupal_render($output);
$output .= drupal_render_children($form);
$output .= '<p style="text-align: right">' . t('Module development by <a href="@development-url">Quiptime Group</a>.', array('@development-url' => url('http://www.quiptime.com'))) . '</p>';
return $output;
}
/**
* Save settings from admin form.
*/
function mb_user_admin_submit($form, &$form_state) {
$module = 'mb_user';
$mappings = $form['#mappings'];
if ($form_state['clicked_button']['#id'] == 'edit-save') {
// Save the MB User button settings.
foreach ($mappings as $type => $maps) {
variable_set($module . '_cancel_' . $type, $form_state['values'][$module . '_cancel_' . $type]);
variable_set($module . '_sac_' . $type, $form_state['values'][$module . '_sac_' . $type]);
variable_set($module . '_sacn_' . $type, $form_state['values'][$module . '_sacn_' . $type]);
}
drupal_set_message(t('Your changes have been saved.'), 'status');
}
elseif ($form_state['clicked_button']['#id'] == 'edit-reset') {
$form_state['redirect'] = 'admin/config/mb/buttons/more-buttons-user/reset';
}
}
/**
* Menu callback to define the confirm form output.
*
* @return
* The confirm form.
*/
function mb_user_reset() {
$question = t('Are you sure you want to reset all %module settings?', array('%module' => t('More Buttons User')));
$information = '<p>' . t('This action disables the settings for all buttons. This action cannot be undone.') . '</p>';
return confirm_form(array(),
$question,
array('path' => 'admin/config/mb/buttons/more-buttons-user', 'attributes' => array('class' => 'button')), $information,
t('Reset'),
t('Cancel')
);
}
/**
* Resave all system variables of the MB User module to reset the module settings.
*/
function mb_user_reset_submit($form, &$form_state) {
// Resave variables.
$page_types = array_keys(mb_user_type_get_types());
foreach ($page_types as $type) {
variable_set('mb_user_cancel_' . $type, 0);
variable_set('mb_user_sac_' . $type, 0);
variable_set('mb_user_sacn_' . $type, 0);
}
drupal_set_message(t('The %module settings have been set back.', array('%module' => t('More Buttons User'))), 'status');
watchdog('More Buttons User', 'The %module settings have been set back.', array('%module' => t('More Buttons User')), WATCHDOG_NOTICE, l(t('view'), 'admin/config/mb/buttons/more-buttons-user'));
$form_state['redirect'] = 'admin/config/mb/buttons/more-buttons-user';
}

View File

@@ -0,0 +1,13 @@
name = More Buttons User
description = "Provides additional buttons for content in user context such as <em>Cancel</em> and <em>Save and continue</em>."
package = "More Buttons"
dependencies[] = mb
core = 7.x
files[] = mb_user.module
; Information added by drupal.org packaging script on 2011-02-25
version = "7.x-1.x-dev"
core = "7.x"
project = "mb"
datestamp = "1298619614"

View File

@@ -0,0 +1,19 @@
<?php
/**
* @file
* Installs, updates, and uninstalls More Buttons User.
*/
/**
* Implements hook_uninstall().
*/
function mb_user_uninstall() {
// Remove variables.
$page_types = array_keys(mb_user_type_get_types());
foreach ($page_types as $type) {
variable_del('mb_content_cancel_' . $type);
variable_del('mb_content_sac_' . $type);
variable_del('mb_content_sacn_' . $type);
}
}

View File

@@ -0,0 +1,236 @@
<?php
/**
* @file
* Provides additional buttons for content in user context.
*
* Currently available context:
* - User account
*
* Currently available buttons:
* - Cancel
* - Save and Continue
* - Save and create new
*
* The "Save and create new" button is only usable for users wth the permission "Administer users".
*/
/**
* Implements hook_permission().
*/
function mb_user_permission() {
return array(
'access mb user' => array(
'title' => t('Use More User Buttons'),
'description' => t('Use the buttons defined by More Buttons User.')
)
);
}
/**
* Implements hook_menu().
*/
function mb_user_menu() {
$items = array();
$items['admin/config/mb/buttons/more-buttons-user'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('mb_user_admin'),
'title' => 'Users',
'access arguments' => array('administer site configuration'),
'description' => 'An overview of what page types uses buttons of the MB User module.',
'file' => 'mb_user.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 11
);
$items['admin/config/mb/buttons/more-buttons-user/reset'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('mb_user_reset'),
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
'file' => 'mb_user.admin.inc'
);
return $items;
}
/**
* Implements hook_theme().
*/
function mb_user_theme() {
return array(
'mb_user_admin' => array(
'variables' => array('form' => NULL),
)
);
}
/**
* Implements hook_form_alter().
*/
function mb_user_form_alter(&$form, &$form_state, $form_id) {
$module = 'mb_user';
switch ($form_id) {
case 'user_profile_form':
$default_values = mb_default_values();
$mb_user_values = mb_get_values('mb');
if (!isset($form['actions']['submit']['#weight'])) {
$form['actions']['submit']['#weight'] = 10;
}
if (isset($form['actions']['cancel'])) {
$form['actions']['cancel']['#weight'] = 25;
}
$settings = array();
$settings['cancel'] = variable_get($module . '_cancel_user_account', 0);
$settings['sac'] = variable_get($module . '_sac_user_account', 0);
$settings['sacn'] = variable_get($module . '_sacn_user_account', 0);
// The "Cancel" form element on user account page.
if ($settings['cancel'] > 0) {
if ($settings['cancel'] == 1) {
$weight_cancel = $form['actions']['submit']['#weight'] - 1;
}
elseif ($settings['cancel'] == 2) {
$weight_cancel = 16;
}
// Define the "Cancel" form element.
$form['actions']['cancel_mb'] = array(
'#type' => 'submit',
'#value' => isset($mb_user_values['cancel']) ? t('@cancel-value', array('@cancel-value' => t($mb_user_values['cancel']))) : t($default_values['cancel']),
'#weight' => $weight_cancel,
'#validate' => array('mb_user_cancel_validate')
);
}
// The "Save and continue" form element on user account page.
if ($settings['sac'] > 0) {
// Left
if ($settings['sac'] == 1) {
$weight_sac = $form['actions']['submit']['#weight'] - 0.025;
}
// Right
if ($settings['sac'] == 2) {
$weight_sac = $form['actions']['submit']['#weight'] - 0.050;
}
//
if ($settings['sac'] == 3) {
$weight_sac = $form['actions']['submit']['#weight'] + 1.025;
}
//
if ($settings['sac'] == 4) {
$weight_sac = $form['actions']['submit']['#weight'] + 1.050;
}
// Define the "Save and continue" form element.
$submit = $form['#submit'];
$submit[] = 'mb_user_sac_submit';
$form['actions']['sac'] = array(
'#type' => 'submit',
'#value' => isset($mb_user_values['sac']) ? t('@sac-value', array('@sac-value' => t($mb_user_values['sac']))) : t($default_values['sac']),
'#weight' => $weight_sac,
'#submit' => $submit
);
}
// The "Save and create new" form element on user account page.
if ($settings['sacn'] > 0 && user_access('administer users')) {
//
if ($settings['sacn'] == 1) {
$weight_sacn = $form['actions']['submit']['#weight'] - 0.025;
}
//
if ($settings['sacn'] == 2) {
$weight_sacn = $form['actions']['submit']['#weight'] - 0.050;
}
//
if ($settings['sacn'] == 3) {
$weight_sacn = $form['actions']['submit']['#weight'] + 1.025;
}
//
if ($settings['sacn'] == 4) {
$weight_sacn = $form['actions']['submit']['#weight'] + 1.050;
}
// Define the "Save and create new" form element.
$submit = $form['#submit'];
$submit[] = 'mb_user_sacn_submit';
$form['actions']['sacn'] = array(
'#type' => 'submit',
'#value' => isset($mb_user_values['sacn']) ? t('@sacn-value', array('@sacn-value' => t($mb_user_values['sacn']))) : t($default_values['sacn']),
'#weight' => $weight_sacn,
'#submit' => $submit
);
}
break;
}
}
/**
* Implements hook_form_validate().
*
* Handle the "Cancel" button validation.
*/
function mb_user_cancel_validate($form, &$form_state) {
// This is the cancel action. No validation required.
mb_user_cancel_action($form, $form_state);
}
/**
* The "Cancel" button action.
*
* @see mb_user_cancel_validate()
*/
function mb_user_cancel_action($form, &$form_state) {
// Hide the error messages.
drupal_get_messages('error');
$redirect = 'user/' . $form['#user']->uid;
drupal_goto($redirect);
}
/**
* Implements hook_form_submit().
*
* Handle the "Save and continue" button action.
*/
function mb_user_sac_submit($form, &$form_state) {
$redirect = 'user/' . $form['#user']->uid . '/edit';
drupal_goto($redirect);
}
/**
* Implements hook_form_submit().
*
* Handle the "Save and create new" button action.
*/
function mb_user_sacn_submit($form, &$form_state) {
$redirect = 'admin/people/create';
drupal_goto($redirect);
}
/**
* Get the types of pages allowed to use more buttons.
*
* At the moment are only supported the user accounts.
*
* @return array
*/
function mb_user_type_get_types() {
$account = array();
$account['type'] = 'user_account';
$account['name'] = t('User account');
$page_types = array('user_account' => $account);
return $page_types;
}