mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/site_users.git
synced 2026-03-10 02:07:41 -03:00
Implementa o field type 'social_link' com seletor de rede e URL de
perfil, composto por:
- SocialLinkItem: field type com colunas 'network' (varchar 64) e
'url' (varchar 2048), cardinalidade ilimitada
- SocialLinkWidget: widget com select de rede e input de URL
- SocialLinkFormatter: formatter que renderiza links com classe CSS
por rede (social-link--{network}), target _blank e rel noopener
- config/optional: field.storage e field.field para user
- config/translations/pt-br: tradução do label e description
- hook_install e update_10002: configura form/view displays
- UserInfoBlock: expõe social_links via getSocialLinks()
- Template: adiciona seção de redes sociais e remove referências
obsoletas a category e dept_code
- translations/site_users.pt-br.po: strings do novo field type
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Drupal\site_users\Plugin\Field\FieldFormatter;
|
|
|
|
use Drupal\Core\Field\FieldItemListInterface;
|
|
use Drupal\Core\Field\FormatterBase;
|
|
use Drupal\Core\Url;
|
|
use Drupal\site_users\Plugin\Field\FieldType\SocialLinkItem;
|
|
|
|
/**
|
|
* Plugin implementation of the 'social_link_formatter' formatter.
|
|
*
|
|
* @FieldFormatter(
|
|
* id = "social_link_formatter",
|
|
* label = @Translation("Social link"),
|
|
* field_types = {
|
|
* "social_link"
|
|
* }
|
|
* )
|
|
*/
|
|
class SocialLinkFormatter extends FormatterBase {
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function viewElements(FieldItemListInterface $items, $langcode): array {
|
|
$elements = [];
|
|
$networks = SocialLinkItem::getNetworks();
|
|
|
|
foreach ($items as $delta => $item) {
|
|
if ($item->isEmpty()) {
|
|
continue;
|
|
}
|
|
|
|
$network_label = $networks[$item->network] ?? $item->network;
|
|
|
|
$elements[$delta] = [
|
|
'#type' => 'link',
|
|
'#title' => $network_label,
|
|
'#url' => Url::fromUri($item->url),
|
|
'#attributes' => [
|
|
'class' => ['social-link', 'social-link--' . $item->network],
|
|
'target' => '_blank',
|
|
'rel' => 'noopener noreferrer',
|
|
],
|
|
];
|
|
}
|
|
|
|
return $elements;
|
|
}
|
|
|
|
}
|