From af7ebfb947ccca7a33834e65a7ab85c2e96d59c1 Mon Sep 17 00:00:00 2001 From: "Quintino A. G. Souza" Date: Wed, 25 Feb 2026 08:23:42 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20Exp=C3=B5e=20links=20sociais=20do=20usu?= =?UTF-8?q?=C3=A1rio=20no=20bloco=20ShareLinks=20do=20site=5Ftools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implementa hook_site_tools_share_links() para fornecer os links do campo field_user_social_links ao ShareLinksBlock quando em página de perfil de usuário. Adiciona site_tools como dependência do módulo. Co-Authored-By: Claude Sonnet 4.6 --- site_users.info.yml | 1 + site_users.module | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/site_users.info.yml b/site_users.info.yml index cf1c69a..b1f4ed8 100644 --- a/site_users.info.yml +++ b/site_users.info.yml @@ -9,3 +9,4 @@ dependencies: - drupal:text - drupal:media - drupal:media_library + - site_tools:site_tools diff --git a/site_users.module b/site_users.module index 6c0fdc9..7d09fc6 100644 --- a/site_users.module +++ b/site_users.module @@ -12,8 +12,10 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; use Drupal\field\FieldConfigInterface; use Drupal\media\MediaInterface; +use Drupal\site_users\Plugin\Field\FieldType\SocialLinkItem; use Drupal\user\UserInterface; /** @@ -329,6 +331,49 @@ function site_users_user_presave(UserInterface $user) { } } +/** + * Implements hook_site_tools_share_links(). + */ +function site_users_site_tools_share_links(): array { + $user = \Drupal::routeMatch()->getParameter('user'); + + if (!($user instanceof UserInterface)) { + return []; + } + + if (!$user->hasField('field_user_social_links') || $user->get('field_user_social_links')->isEmpty()) { + return []; + } + + $links = []; + $networks = SocialLinkItem::getNetworks(); + + foreach ($user->get('field_user_social_links') as $delta => $item) { + if ($item->isEmpty()) { + continue; + } + + $network_label = $networks[$item->network] ?? $item->network; + + $links['social_' . $item->network] = [ + 'content' => [ + '#type' => 'link', + '#title' => $network_label, + '#url' => Url::fromUri($item->url), + '#attributes' => [ + 'class' => ['social-link', 'social-link--' . $item->network], + 'target' => '_blank', + 'rel' => 'noopener noreferrer', + ], + ], + 'weight' => $delta, + 'provider' => 'site_users', + ]; + } + + return $links; +} + /** * Obtém a foto padrão de um usuário. *