Commit 9867fc40 authored by Philippe Mouchel's avatar Philippe Mouchel
Browse files

Provide a nadministration page for sharer toolbar

[refs #70413]
parent 6e9ba6a8
<?php
/**
* @file sharer_toolbar.forms.inc
* Forms configuration
*/
/**
* Sharer toolbar configuration form.
*/
function sharer_toolbar_config_form($form, &$form_state) {
module_load_include('inc', 'sharer_toolbar');
// To make checkboxes sortable
$form['#tree'] = TRUE;
// List all available sharers
$sharers = _sharer_toolbar_get_ordered_available_sharers();
$sharers_configuration = variable_get('sharer_toolbar_sharers_configuration', array());
foreach ($sharers as $delta => $sharer) {
$sid = $sharer['sid'];
$sharer_conf = (isset($sharers_configuration[$sid])) ? $sharers_configuration[$sid] : array();
// Checkbox to activate or not sharer.
$form['sharers'][$sid]['status'] = array(
'#type' => 'checkbox',
'#default_value' => (isset($sharer_conf['status'])) ? $sharer_conf['status'] : 0,
);
// Textfield to hold sharer name.
$form['sharers'][$sid]['name'] = array(
'#type' => 'textfield',
'#default_value' => (isset($sharer_conf['name'])) ? $sharer_conf['name'] : $sharer['name'],
);
// Textfield to hold sharer icon class.
$form['sharers'][$sid]['icon_class'] = array(
'#type' => 'textfield',
'#default_value' => (isset($sharer_conf['icon_class'])) ? $sharer_conf['icon_class'] : $sharer['icon_class'],
);
// Invisible field, but contains sort info (weights).
$form['sharers'][$sid]['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#title_display' => 'invisible',
'#default_value' => $delta,
);
}
// Submit button
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}
/**
* Sharer toolbar configuration form submit.
*/
function sharer_toolbar_config_form_submit($form, &$form_state) {
$sharers = $form_state['values']['sharers'];
$sharers_order = array();
$sharers_configuration = array();
// Iterate on orders to store informations
foreach ($sharers as $sid => $sharer_conf) {
// Store weight
$sharers_order[$sharer_conf['weight']] = $sid;
// Store configuration
$sharers_configuration[$sid] = array(
'name' => $sharer_conf['name'],
'icon_class' => $sharer_conf['icon_class'],
'status' => $sharer_conf['status'],
);
}
// Save values
variable_set('sharer_toolbar_sharers_order', $sharers_order);
variable_set('sharer_toolbar_sharers_configuration', $sharers_configuration);
// Confirmation
drupal_set_message(t('Sharer toolbar configuration has been saved.'));
}
<?php
/**
* @file sharer_toolbar.inc
* Helper functions
*/
/**
* List all available environments,
* ordered by config form weight if available
*/
function _sharer_toolbar_get_ordered_available_sharers() {
$ordered_sharers = array();
// List all available sharers by invoking:
// - hook_sharer_toolbar_available_sharer()
// - hook_sharer_toolbar_available_sharer_alter()
$available_sharers = module_invoke_all('sharer_toolbar_available_sharer');
drupal_alter('sharer_toolbar_available_sharer', $available_sharers);
// Generate ordered list if sharers order is already defined
$sharers_order = variable_get('sharer_toolbar_sharers_order', array());
if (!empty($sharers_order)) {
foreach ($sharers_order as $weight => $sid) {
$ordered_sharers[$weight] = $available_sharers[$sid];
}
}
// Else, keep default order and index sharers array numerically
else {
$ordered_sharers = array_values($available_sharers);
}
// Return ordered sharers
ksort($ordered_sharers);
return $ordered_sharers;
}
name = Sharer Toolbar
description = Provide several social «sharers», from Facebook, Twitter, LinkedIn and email sharing.
core = 7.x
configure = admin/config/services/social-sharer-toolbar
<?php
/**
* @file sharer_toolbar.install
* Installation file.
*/
/**
* Implements hook_uninstall().
*/
function sharer_toolbar_uninstall() {
// Delete sharers configuration
variable_del('sharer_toolbar_sharers_configuration');
// Delete sharers order
variable_del('sharer_toolbar_sharers_order');
}
......@@ -4,3 +4,85 @@
* @file sharer_toolbar.module
* Hooks implementations and code logic related to Sharer Toolbar module
*/
/**
* Implements hook_permission().
*/
function sharer_toolbar_permission() {
return array(
'admin sharer toolbar' => array(
'title' => t('Administer sharer toolbar'),
'description' => t('Choose which social sharer to be displayed and other stuffs.'),
),
);
}
/**
* Implements hook_menu().
*/
function sharer_toolbar_menu() {
return array(
'admin/config/services/social-sharer-toolbar' => array(
'title' => 'Sharer toolbar configuration',
'description' => 'Configure sharer toolbar.',
'page callback' => 'drupal_get_form',
'page arguments' => array('sharer_toolbar_config_form'),
'access arguments' => array('admin sharer toolbar'),
'file' => 'sharer_toolbar.forms.inc',
)
);
}
/**
* Implements hook_theme().
*/
function sharer_toolbar_theme($existing, $type, $theme, $path) {
return array(
'sharer_toolbar_config_form' => array(
'render element' => 'form',
'file' => 'sharer_toolbar.theme.inc',
),
);
}
/**
* Implements hook_sharer_toolbar_available_sharer().
*/
function sharer_toolbar_sharer_toolbar_available_sharer() {
// Define default sharers
return array(
// Facebook sharer
'facebook' => array(
'sid' => 'facebook',
'name' => 'Facebook',
'icon_class' => 'icon-facebook',
),
// Twitter sharer
'twitter' => array(
'sid' => 'twitter',
'name' => 'Twitter',
'icon_class' => 'icon-twitter',
),
// Twitter sharer
'linkedin' => array(
'sid' => 'linkedin',
'name' => 'LinkedIn',
'icon_class' => 'icon-linkedin',
),
// Email sharer
'email' => array(
'sid' => 'email',
'name' => 'Email',
'icon_class' => 'icon-email',
),
);
}
<?php
/**
* @file sharer_toolbar.theme.inc
* Theming functions
*/
/**
* Sharer toolbar configuration form theming function.
*/
function theme_sharer_toolbar_config_form($variables) {
$form = $variables['form'];
// Define table header
$header = array(
t('Order'),
t('Status'),
t('Name'),
t('Icon class'),
t('Weight'),
);
// Render form rows as table rows
$rows = array();
foreach (element_children($form['sharers']) as $sid) {
$form['sharers'][$sid]['weight']['#attributes']['class'] = array('sharers-order-weight');
$rows[] = array(
'data' => array(
array('class' => array('sharer-cross')),
drupal_render($form['sharers'][$sid]['status']),
drupal_render($form['sharers'][$sid]['name']),
drupal_render($form['sharers'][$sid]['icon_class']),
drupal_render($form['sharers'][$sid]['weight']),
),
'class' => array('draggable'),
);
}
// Render draggable table
$output = drupal_render($form['note']);
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'sharers-order')));
$output .= drupal_render_children($form);
// Add draggable feature to table#sharers-order
drupal_add_tabledrag('sharers-order', 'order', 'sibling', 'sharers-order-weight');
return $output;
}
# French translation of Sharer Toolbar module
# Copyright (c) 2015 by Savoir-faire Linux
#
msgid ""
msgstr ""
"Project-Id-Version: Sharer Toolbar 7.x-1.0"
"POT-Creation-Date: 2015-04-10 12:00+0000\n"
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
"Language-Team: French\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n>1);\n"
msgid "Sharer toolbar configuration"
msgstr "Configuration de la barre de partage"
msgid "Configure sharer toolbar."
msgstr "Configurer la barre de partage"
msgid "Sharer toolbar configuration has been saved."
msgstr "La configuration de la barre de partage a été sauvegardée."
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment