- π³πΏNew Zealand atowl
We ran into some caching issues with this, where it would not get the new entity (ie page) due to being cached already.
To solve this, moved the logic for doing the preferred link into the preprocess hook, and into its own render array with `#cache => max-age = 0`
As i understand it, it will now always re-render that array into the template. And hence always get the preferred link.
I haven't done anything quite like this before so if that's the wrong approach let me know.Thanks
- π³πΏNew Zealand atowl
Sorry - last patch didn't include the shift of the configuration out of the if statement. This caused a get on null error.
Fixed. - Open on Drupal.org βCore: 10.1.x + Environment: PHP 8.1 & MySQL 5.7last update
about 2 years ago Waiting for branch to pass - Open on Drupal.org βCore: 10.1.x + Environment: PHP 8.1 & MySQL 5.7last update
almost 2 years ago Waiting for branch to pass Had and issue where the copy link button would copy the original URL not the preferred URL
- Open on Drupal.org βCore: 10.1.x + Environment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Waiting for branch to pass - π³πΏNew Zealand atowl
Found an issue with this approach, the max-age should not be set to 0, then drupal never caches it.
instead, so we can use caching, set 'contexts' to 'url'.
Not sure if its the right thing to do, as i don't know enough about caching here. - πΊπΈUnited States shelane
It seems that this request should be for overriding on a per-node basis. Is that correct? Or are you looking to override all shared links to a single URL? That seems a little contrary to the point of the sharing module.
I have recently merged a submitted MR for making a sub-module that allows overrides for sharing on a per-node basis. I can see having an override URL option as part of that.
- π³πΏNew Zealand atowl
Hi Shelane,
Yes its on a per node basis.
i have thought about changing this to a sub-module of our own, so having it installed would just implement the bitly link override.
- π΅π°Pakistan dewancodes
Hi @atowl . What steps are remaining to do final implementation for this issue in order to close this issue?
- π«π·France mably
Not sure it could be merged as is. It should probably be done in another module.
But I like the idea of having the possibility to use a different or modified url than the current page URL.
I will have to think about it.
We could then add a hook that would allow other modules to generate that substitute URL as they like...
- π«π·France mably
@atowl you would probably use that hook in your custom module like this:
/** * Implements hook_better_social_sharing_buttons_node_view_alter(). */ function my_module_better_social_sharing_buttons_node_view_alter(&$items, &$node) { $config = \Drupal::config('my_module.settings'); if ($config->get('preferred_url')) { $url = $node->get($config->get('preferred_url'))->value; if (isset($url)) { $items['page_url'] = $url; } ) }
- π³πΏNew Zealand atowl
So i think with the hooks that have been been implemented in #3504396, this issue can now be closed.
I have created a module that will do the override, which seems to work just fine.Thanks
- Status changed to Closed: won't fix
2 months ago 12:58am 11 March 2025