I'm working on a project with many content types and many Panels and variants. We'd like the same social sharing configuration throughout, i.e. a global toolbox. I've thrown together something that meets our needs and am sharing the diff from 4.x to get the conversation started about a proper implementation of this feature.

CommentFileSizeAuthor
addthis-7.x-4.x-global-toolbox.patch6.64 KBdubois
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

matglas86’s picture

Looks nice. I would strongly suggest to move this into a field formatter like the others and then use the settings function on in the .module file to create a configurable global setting. Look kinda like the block settings page.

matglas86’s picture

I had problems running this patch against the lastest commit on 7.x-4.x. Can you checkout if it applies and otherwise reroll it against that head?

This was the error.

addthis-7.x-4.x-global-toolbox.patch:47: trailing whitespace.
 *  Render a basic_toolbox using global settings. 
addthis-7.x-4.x-global-toolbox.patch:53: trailing whitespace.
  $options['#display']['settings']['counter_orientation'] = variable_get(AddThis::GLOBAL_TOOLBOX_COUNTER_ORIENTATION_KEY, 'FALSE'); 
addthis-7.x-4.x-global-toolbox.patch:112: trailing whitespace.
    '#default_value' => variable_get(AddThis::GLOBAL_TOOLBOX_SERVICES_KEY, 'twitter,facebook,compact'), 
warning: 3 lines add whitespace errors.
matglas86’s picture

I have to revise my suggestion because you already added it into a field formatter. :)

Here is the suggestion to look at when it comes to the settings form. You can use this function _addthis_settings_form() in addthis.module. This is the central function that is used in addthis_form_block_admin_configure_alter to generate a settings form based on the field formatters. Its using ajax, just like the settings form for formatters itself on the 'Manage display' page.

    // Retrieve settings.
    $addthis_settings['type'] = AddThis::getInstance()->getBlockDisplayType();
    $addthis_settings['settings'] = AddThis::getInstance()->getBlockDisplaySettings();

    // Create a addthis settings form based on the available configuration.
    $element = _addthis_settings_form(
      isset($form['addthis_settings']['form']) ? $form['addthis_settings']['form'] : array(),
      $form_state,
      isset($addthis_settings['type']) ? $addthis_settings['type'] : NULL,
      isset($addthis_settings['settings']) ? $addthis_settings['settings'] : NULL
    );

And then:

    // Change the submit and callback because our handling is different and the
    // form structure is different form the default implementation.
    $element['type']['#submit'] = array('_addthis_settings_form_block_submit');
    $element['type']['#ajax']['callback'] = '_addthis_settings_form_block_submit_callback';

I hope this helps you getting in the right direction for this functionality.