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.

Command icon 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

csakiistvan created an issue. See original summary.

csakiistvan’s picture

csakiistvan’s picture

Status: Active » Needs review
vinodhini.e’s picture

Hi,

  • Reproduced the issue on Drupal 10.6.10
  • Placed the Better Social Share block and configured multiple social platforms.
  • Reordered the platforms in the block configuration and saved the changes.
  • Verified that the configured order was not reflected on the frontend.
  • Applied MR !5 (or the provided patch) and retested.
  • The social share buttons now follow the configured order correctly on the frontend.
  • Tested several reorder combinations and all worked as expected.

Thanks.

csakiistvan’s picture

Status: Needs review » Reviewed & tested by the community

  • sujan shrestha committed 2388a9e4 on 1.1.x
    fix: #3616132 #3581596 #3494444 #3611578 #3593205 #3623926 #3550561 #...
sujan shrestha’s picture

Version: 1.1.x-dev » 1.1.8

Fixed 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.

sujan shrestha’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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