feat: Expõe links sociais do usuário no bloco ShareLinks do site_tools

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 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 08:23:42 -03:00
parent 5c18c4db82
commit af7ebfb947
2 changed files with 46 additions and 0 deletions

View File

@@ -9,3 +9,4 @@ dependencies:
- drupal:text
- drupal:media
- drupal:media_library
- site_tools:site_tools

View File

@@ -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.
*