You are here

function rrssb_settings in Ridiculously Responsive Social Sharing Buttons 8.2

Same name and namespace in other branches
  1. 7.2 rrssb.module \rrssb_settings()
  2. 7 rrssb.module \rrssb_settings()

Fetch buttons settings.

Parameters

string $buttonSet: Button set to fetch settings for.

Return value

array Key is button name, value is an array of button config and settings merged. For config values, see hook_rrssb_buttons. Settings values are 'enabled', 'weight', 'username'.

2 calls to rrssb_settings()
rrssb_gen_css in ./rrssb.module
Auto-generate CSS for buttons.
rrssb_get_buttons in ./rrssb.module
Returns a Drupal render array for the buttons.

File

./rrssb.module, line 232

Code

function rrssb_settings($buttonSet) {

  // Get all buttons.
  $buttons = rrssb_button_config();
  $config = \Drupal::config("rrssb.button_set.{$buttonSet}");
  if (!$config) {
    return [];
  }
  $chosen = $config
    ->get('chosen');
  $defaults = [
    'enabled' => FALSE,
    'weight' => 0,
    'username' => '',
  ];
  $follow = $config
    ->get('follow');

  // Set some defaults.
  foreach ($buttons as $name => &$button) {

    // Merge in the current config, with suitable defaults and checking.
    if (isset($chosen[$name])) {
      $button += $chosen[$name];
    }
    $button += $defaults;
    $button['username'] = Html::escape($button['username']);
    if ($follow) {
      $button['text'] = $button['title_follow'];
    }
  }

  // Sort buttons by configured weight.
  uasort($buttons, [
    'Drupal\\Component\\Utility\\SortArray',
    'sortByWeightElement',
  ]);

  // Filter to only include enabled ones with a URL configured.
  $key = $follow ? 'follow_url' : 'share_url';
  $buttons = array_filter($buttons, function ($button) use ($key) {
    return $button['enabled'] && isset($button[$key]);
  });
  return $buttons;
}