Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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',
);
}
}
Comment | File | Size | Author |
---|---|---|---|
#9 | addtoany-custom-settings-2837846-9-D8.patch | 1.61 KB | rrotari |
Comments
Comment #2
rrotariProposed sollution
Comment #3
rrotariComment #4
rrotariComment #5
rrotariComment #6
rrotariComment #7
rrotariComment #8
rrotariComment #9
rrotariComment #10
rrotariComment #12
micropat CreditAttribution: micropat commentedThanks for the request & patch! Test drive it from dev, then see it in the next AddToAny release, version 8.x-1.8.
Comment #14
donquixote CreditAttribution: donquixote commentedCan we do something equivalent for Drupal 7?
If we do it like the code below, there will be no BC break at all.
Or do it like the Drupal 8 patch, and add an extra optional parameter to addtoany_create_buttons().