mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/site_users.git
synced 2026-03-08 01:17:41 -03:00
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:
@@ -9,3 +9,4 @@ dependencies:
|
||||
- drupal:text
|
||||
- drupal:media
|
||||
- drupal:media_library
|
||||
- site_tools:site_tools
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user