mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/site_tools.git
synced 2026-03-11 10:57: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:
59
site_tools.module
Normal file
59
site_tools.module
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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;
|
||||
}
|
||||
Reference in New Issue
Block a user