diff --git a/src/Plugin/Condition/PageUserIsCurrentUser.php b/src/Plugin/Condition/PageUserIsCurrentUser.php index edefed7..3e3f343 100644 --- a/src/Plugin/Condition/PageUserIsCurrentUser.php +++ b/src/Plugin/Condition/PageUserIsCurrentUser.php @@ -4,6 +4,7 @@ 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; @@ -30,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); } @@ -41,6 +43,7 @@ class PageUserIsCurrentUser extends ConditionPluginBase implements ContainerFact $plugin_definition, $container->get('current_route_match'), $container->get('current_user'), + $container->get('path.current'), ); } @@ -90,13 +93,22 @@ class PageUserIsCurrentUser extends ConditionPluginBase implements ContainerFact $page_uid = (int) $param; } else { - // Rotas sem parâmetro 'user' (e.g., nós do microsite em /user/{id}/...): - // usa o autor do nó como usuário da página. - $node = $this->routeMatch->getParameter('node'); - if (!($node instanceof NodeInterface)) { + // 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; } - $page_uid = (int) $node->getOwnerId(); } return $page_uid === (int) $this->currentUser->id();