mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/site_tools.git
synced 2026-03-10 10:27:41 -03:00
Initial commit
Módulo site_tools com ferramentas utilitárias para outros módulos: - Bloco ShareLinks para compartilhamento em redes sociais - Seção "Local Modules" no menu de configuração do Drupal Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
64
src/Plugin/Block/ShareLinksBlock.php
Normal file
64
src/Plugin/Block/ShareLinksBlock.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\site_tools\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\Attribute\Block;
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Bloco para exibir links de compartilhamento de conteúdo.
|
||||
*
|
||||
* Este bloco coleta links de compartilhamento de outros módulos
|
||||
* através do hook_site_tools_share_links() e os exibe em um
|
||||
* container estilizado.
|
||||
*/
|
||||
#[Block(
|
||||
id: 'site_tools_share_links',
|
||||
admin_label: new TranslatableMarkup('Share Links'),
|
||||
category: new TranslatableMarkup('Site Tools'),
|
||||
)]
|
||||
class ShareLinksBlock extends BlockBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(): array {
|
||||
$links = site_tools_collect_share_links();
|
||||
|
||||
// Se não houver links, não renderiza o bloco.
|
||||
if (empty($links)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'#theme' => 'site_tools_share_links',
|
||||
'#links' => $links,
|
||||
'#attributes' => [
|
||||
'class' => ['site-tools-share-links'],
|
||||
],
|
||||
'#attached' => [
|
||||
'library' => ['site_tools/share_links'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheContexts(): array {
|
||||
// Cache varia por URL pois os links dependem do conteúdo atual.
|
||||
return array_merge(parent::getCacheContexts(), ['url.path']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheTags(): array {
|
||||
// Permite que módulos invalidem o cache quando necessário.
|
||||
return array_merge(parent::getCacheTags(), ['site_tools_share_links']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user