Problem/Motivation
The Better Social Share block configuration form lets the editor order the platforms with a tabledrag widget, and the chosen order is stored as a weight per platform in the block settings. That weight is never applied when the block is rendered: BetterSocialShareBlock::build() passes $data['social_share_platforms'] to the theme unchanged, so the buttons come out in the array order of the stored configuration instead of the configured order.
The equivalent rendering path for entities does sort by weight (better_social_share_create_data() runs a usort() on the platform list), so the block is inconsistent with the rest of the module.
This was originally reported as a follow-up comment on #3581596, which is about unrelated block configuration defects. It is being split out here so it can be reviewed and merged on its own.
Steps to reproduce
- Place a Better Social Share block in a visible region.
- In the block configuration, enable at least three platforms — for example LinkedIn, Copy Link and Facebook.
- Drag them into a non-alphabetical, non-default order, e.g. LinkedIn first, then Copy Link, then Facebook, and save the block.
- Reopen the block configuration form and confirm the order was stored as configured.
- View a page containing the block.
Expected: the buttons are rendered as LinkedIn, Copy Link, Facebook.
Actual: the buttons are rendered in the stored array order, e.g. Facebook, LinkedIn, Copy Link.
Proposed resolution
Sort the platform list by its weight key in BetterSocialShareBlock::build() before it is handed to the theme, keeping the array keys intact:
$social_share_platforms = $data['social_share_platforms'] ?? []; if (!empty($social_share_platforms)) { uasort($social_share_platforms, function ($a, $b) { return ($a['weight'] ?? 0) <=> ($b['weight'] ?? 0); }); $data['social_share_platforms'] = $social_share_platforms; }
MR !5 on #3581596 already contains this change on the 3581596-block-config-order-issue branch and can be retargeted to this issue.
Remaining tasks
- Move MR !5 from #3581596 to this issue (or open an equivalent MR against
1.1.x). - Review. Note that the change touches the same method as MR !4 on #3581596, so whichever lands second needs a rebase.
- Consider extracting the sorting into a shared helper, since
better_social_share_create_data()already performs the same sort for the entity rendering path. - Add test coverage asserting the rendered button order follows the configured weights.
User interface changes
None as such — the ordering widget already exists in the block configuration form. The rendered output starts honouring it, so sites that placed a block with a customised order will see the buttons change position after the fix.
API changes
None.
Data model changes
None. The weight key is already stored in the block settings; only its interpretation at render time changes.
Issue fork better_social_share-3616132
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
csakiistvanComment #4
csakiistvanComment #5
vinodhini.e commentedHi,
Thanks.
Comment #6
csakiistvanComment #8
sujan shrestha commentedFixed in 1.1.8 (commit 2388a9e). The block now sorts the buttons by the configured weight, using the same code as the content field, so both always match. Covered by a kernel test. Thanks for the clear report and the MR, which this follows.
Comment #9
sujan shrestha commented