mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/site_tools.git
synced 2026-05-05 17:55:30 -03:00
Compare commits
5 Commits
0dca85ca8f
...
d113e932ba
| Author | SHA1 | Date | |
|---|---|---|---|
| d113e932ba | |||
| f937b84c50 | |||
| 7aefb543e9 | |||
| 41378004a2 | |||
| acda09c277 |
6
.gitlab-ci.yml
Normal file
6
.gitlab-ci.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
publish-composer:
|
||||
stage: deploy
|
||||
script:
|
||||
- 'curl --data "tag=$CI_COMMIT_TAG" --header "JOB-TOKEN: $CI_JOB_TOKEN" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/composer"'
|
||||
only:
|
||||
- tags
|
||||
10
composer.json
Normal file
10
composer.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "imecc/site_tools",
|
||||
"description": "Módulo Drupal com ferramentas utilitárias reutilizáveis em outros módulos do site.",
|
||||
"type": "drupal-module",
|
||||
"license": "GPL-2.0-or-later",
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"drupal/core": "^10.3 || ^11"
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,11 @@ namespace Drupal\site_tools\Plugin\Condition;
|
||||
|
||||
use Drupal\Core\Condition\ConditionPluginBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Path\CurrentPathStack;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
@@ -29,6 +31,7 @@ class PageUserIsCurrentUser extends ConditionPluginBase implements ContainerFact
|
||||
$plugin_definition,
|
||||
protected RouteMatchInterface $routeMatch,
|
||||
protected AccountInterface $currentUser,
|
||||
protected CurrentPathStack $currentPath,
|
||||
) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
}
|
||||
@@ -40,6 +43,7 @@ class PageUserIsCurrentUser extends ConditionPluginBase implements ContainerFact
|
||||
$plugin_definition,
|
||||
$container->get('current_route_match'),
|
||||
$container->get('current_user'),
|
||||
$container->get('path.current'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -89,7 +93,22 @@ class PageUserIsCurrentUser extends ConditionPluginBase implements ContainerFact
|
||||
$page_uid = (int) $param;
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
// Views pages com arg_0 numérico (ex.: /user/{uid}/blog).
|
||||
$arg0 = $this->routeMatch->getParameter('arg_0');
|
||||
if (is_numeric($arg0)) {
|
||||
$page_uid = (int) $arg0;
|
||||
}
|
||||
// Nós do microsite: usa o autor como usuário da página.
|
||||
elseif (($node = $this->routeMatch->getParameter('node')) instanceof NodeInterface) {
|
||||
$page_uid = (int) $node->getOwnerId();
|
||||
}
|
||||
// Fallback: extrai o UID do path atual /user/{uid}/...
|
||||
elseif (preg_match('#^/user/(\d+)(/|$)#', $this->currentPath->getPath(), $m)) {
|
||||
$page_uid = (int) $m[1];
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return $page_uid === (int) $this->currentUser->id();
|
||||
|
||||
Reference in New Issue
Block a user