mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/site_tools.git
synced 2026-03-08 01:17:42 -03:00
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>
60 lines
1.5 KiB
Plaintext
60 lines
1.5 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Módulo Site Tools - ferramentas utilitárias para o site.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Drupal\Core\Routing\RouteMatchInterface;
|
|
|
|
/**
|
|
* Implements hook_help().
|
|
*/
|
|
function site_tools_help(string $route_name, RouteMatchInterface $route_match): ?string {
|
|
if ($route_name === 'help.page.site_tools') {
|
|
return '<p>' . t('Site Tools provides reusable utilities for other modules, including a share links block.') . '</p>';
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_theme().
|
|
*/
|
|
function site_tools_theme(): array {
|
|
return [
|
|
'site_tools_share_links' => [
|
|
'variables' => [
|
|
'links' => [],
|
|
'attributes' => [],
|
|
],
|
|
'template' => 'site-tools-share-links',
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Invoca hook_site_tools_share_links() para coletar links de compartilhamento.
|
|
*
|
|
* @return array
|
|
* Array de links de compartilhamento fornecidos por outros módulos.
|
|
* Cada link deve ter as chaves:
|
|
* - 'content': Render array ou markup do link.
|
|
* - 'weight': (opcional) Peso para ordenação.
|
|
* - 'provider': (opcional) Nome do módulo que fornece o link.
|
|
*/
|
|
function site_tools_collect_share_links(): array {
|
|
$links = \Drupal::moduleHandler()->invokeAll('site_tools_share_links');
|
|
\Drupal::moduleHandler()->alter('site_tools_share_links', $links);
|
|
|
|
// Ordena por peso.
|
|
uasort($links, function ($a, $b) {
|
|
$weight_a = $a['weight'] ?? 0;
|
|
$weight_b = $b['weight'] ?? 0;
|
|
return $weight_a <=> $weight_b;
|
|
});
|
|
|
|
return $links;
|
|
}
|