diff --git a/docroot/modules/humsci/hs_blocks/src/Plugin/Block/SocialMediaBlock.php b/docroot/modules/humsci/hs_blocks/src/Plugin/Block/SocialMediaBlock.php
index 4d8210b27..4887aa9a7 100644
--- a/docroot/modules/humsci/hs_blocks/src/Plugin/Block/SocialMediaBlock.php
+++ b/docroot/modules/humsci/hs_blocks/src/Plugin/Block/SocialMediaBlock.php
@@ -103,11 +103,12 @@ public function blockSubmit($form, FormStateInterface $form_state): void {
* {@inheritdoc}
*/
public function build(): array {
+ $links = array_map([$this, 'linkWithIcon'], $this->configuration['links']);
$build = [
'#theme' => 'hs_blocks_social_media',
'#icon_size' => $this->configuration['icon_size'],
'#layout' => $this->configuration['layout'],
- '#links' => $this->configuration['links'],
+ '#links' => $links,
'#cache' => [
'tags' => array_merge($this->getCacheTags(), ['block_view']),
'contexts' => ['user', 'user.permissions'],
@@ -146,4 +147,116 @@ public static function validateLinks(array $element, FormStateInterface $form_st
}
}
+ /**
+ * Adds the social media icon and name information to a link.
+ *
+ * @param array $link
+ * The link item.
+ *
+ * @return array
+ * The updated link item with the icon and social provider name.
+ */
+ protected function linkWithIcon(array $link) {
+ $url = $link['link_url'];
+ $providers = [
+ [
+ 'domains' => ['facebook.com', 'fb.com', 'fb.me'],
+ 'icon_classes' => 'fa-brands fa-square-facebook',
+ 'name' => 'Facebook',
+ ],
+ [
+ 'domains' => ['twitter.com', 'x.com'],
+ 'icon_classes' => 'fa-brands fa-square-x-twitter',
+ 'name' => 'Twitter',
+ ],
+ [
+ 'domains' => ['linkedin.com', 'lnkd.in'],
+ 'icon_classes' => 'fa-brands fa-linkedin',
+ 'name' => 'Linkedin',
+ ],
+ [
+ 'domains' => ['instagram.com', 'instagr.am'],
+ 'icon_classes' => 'fa-brands fa-square-instagram',
+ 'name' => 'Instagram',
+ ],
+ [
+ 'domains' => ['youtube.com', 'youtu.be'],
+ 'icon_classes' => 'fa-brands fa-square-youtube',
+ 'name' => 'Youtube',
+ ],
+ [
+ 'domains' => ['vimeo.com'],
+ 'icon_classes' => 'fa-brands fa-vimeo',
+ 'name' => 'Vimeo',
+ ],
+ [
+ 'domains' => ['snapchat.com'],
+ 'icon_classes' => 'fa-brands fa-square-snapchat',
+ 'name' => 'Snapchat',
+ ],
+ [
+ 'domains' => ['soundcloud.com'],
+ 'icon_classes' => 'fa-brands fa-soundcloud',
+ 'name' => 'Soundcloud',
+ ],
+ [
+ 'domains' => ['spotify.com'],
+ 'icon_classes' => 'fa-brands fa-spotify',
+ 'name' => 'Spotify',
+ ],
+ [
+ 'domains' => ['apple.com'],
+ 'icon_classes' => 'fa-brands fa-apple',
+ 'name' => 'Apple',
+ ],
+ [
+ 'domains' => ['telegram.me', 't.me'],
+ 'icon_classes' => 'fa-brands fa-telegram',
+ 'name' => 'Telegram',
+ ],
+ [
+ 'domains' => ['mailto:'],
+ 'icon_classes' => 'fa-solid fa-square-envelope',
+ 'name' => 'Email',
+ ],
+ [
+ 'domains' => ['pinterest.com', 'pin.it'],
+ 'icon_classes' => 'fa-brands fa-square-pinterest',
+ 'name' => 'Pinterest',
+ ],
+ [
+ 'domains' => ['tiktok.com'],
+ 'icon_classes' => 'fa-brands fa-tiktok',
+ 'name' => 'Tiktok',
+ ],
+ ];
+
+ $icon_classes = '';
+ $icon_name = '';
+
+ foreach ($providers as $provider) {
+ foreach ($provider['domains'] as $domain) {
+ if (strpos($url, $domain) !== FALSE) {
+ $icon_classes = $provider['icon_classes'];
+ $icon_name = $provider['name'];
+ break 2;
+ }
+ }
+ }
+
+ if (!$icon_classes) {
+ $icon_classes = 'fa-solid fa-globe';
+ // Use the domain as the name if the provider is not listed above.
+ if (preg_match('/https?:\/\/(.+?)\//', $url, $matches)) {
+ $icon_name = $matches[1];
+ }
+ }
+
+ return [
+ 'link_url' => $url,
+ 'link_title' => $link['link_title'] ?: $icon_name,
+ 'icon_classes' => $icon_classes,
+ ];
+ }
+
}
diff --git a/docroot/modules/humsci/hs_blocks/templates/block--social-media.html.twig b/docroot/modules/humsci/hs_blocks/templates/block--social-media.html.twig
index 709399cfa..bc4aea964 100644
--- a/docroot/modules/humsci/hs_blocks/templates/block--social-media.html.twig
+++ b/docroot/modules/humsci/hs_blocks/templates/block--social-media.html.twig
@@ -1,19 +1,12 @@
-Icon size: {{ (icon_size) }}
-
-Layout: {{ layout }}
-
{% if links %}
-