At the moment the only additional html that can be used is the one from settings, despite the fact that it can be edited that still limited having one additional html used over all website.

With few changes we can pass custom settings from another module into addtoany

Proposed changes:

function addtoany_create_buttons($url = NULL, $title = NULL, $config = NULL) {
  global $base_path;

  if(is_null($config)){
    $config = \Drupal::config('addtoany.settings'); 
  }
function addtoany_create_node_buttons($node, $config = NULL) {
  $url = isset($node) ? $node->url('canonical', array('absolute' => true)) : NULL;
  $title = isset($node) ? $node->label() : NULL;
  return addtoany_create_buttons($url, $title, $config);
}

This way in a custom module we can use something like this to pass different settings:

function my_custom_module_ENTITY_TYPE_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
  if ($display->getComponent('addtoany') && $node->isPublished()) {
    $config = \Drupal::config('my_custom_module.settings'); 
    $build['addtoany'] = array(
      '#addtoany_html' => addtoany_create_node_buttons($node, $config),
      '#theme' => 'addtoany_standard',
    );
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rrotari created an issue. See original summary.

rrotari’s picture

FileSize
1.74 KB

Proposed sollution

rrotari’s picture

Issue summary: View changes
rrotari’s picture

rrotari’s picture

rrotari’s picture

FileSize
1.79 KB
rrotari’s picture

rrotari’s picture

Status: Active » Needs review
rrotari’s picture

rrotari’s picture

  • rrotari authored 7c2d3ad on 8.x-1.x
    Issue #2837846 by rrotari, micropat: Allow custom additional html to be...
micropat’s picture

Title: Allow custom additional html to be used » Allow custom instances of Additional HTML, Icon Size, etc.
Assigned: rrotari » Unassigned
Status: Needs review » Fixed

Thanks for the request & patch! Test drive it from dev, then see it in the next AddToAny release, version 8.x-1.8.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

donquixote’s picture

Can we do something equivalent for Drupal 7?

If we do it like the code below, there will be no BC break at all.

function addtoany_create_buttons($url, $title) {
  $options = array();
  foreach (array(
    'additional_html' => '',
    'additional_html_placement' => 'before',
     ..
  ) as $k => $default) {
    $options[$k] = variable_get('addtoany_' . $k, $default);
  }

  return addtoany_do_create_buttons($url, $title, $options);
}

// @todo Better function name?
function addtoany_do_create_buttons($url, $title, $options) {
  ..
}

Or do it like the Drupal 8 patch, and add an extra optional parameter to addtoany_create_buttons().