Skip to content
Snippets Groups Projects
Commit 010bf30f authored by Jürgen Haas's avatar Jürgen Haas Committed by Jürgen Haas
Browse files

Issue #3303087 by jurgenhaas, mxh: Misleading debug message from the load entity plugin

parent 6a21040f
No related branches found
No related tags found
1 merge request!226Issue #3280069: eca_base: Provide an action for translating text
......@@ -3,6 +3,7 @@
namespace Drupal\eca_content\Plugin\Action;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResultReasonInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
......@@ -52,8 +53,18 @@ class LoadEntity extends ConfigurableActionBase {
*/
public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
$access_result = AccessResult::forbidden();
$reason = NULL;
if ($entity = $this->doLoadEntity($object)) {
$access_result = $entity->access('view', $account, TRUE);
if (!$access_result->isAllowed()) {
$reason = 'No permission to view the entity.';
}
}
else {
$reason = 'No entity available.';
}
if ($reason !== NULL && $access_result instanceof AccessResultReasonInterface) {
$access_result->setReason($reason);
}
return $return_as_object ? $access_result : $access_result->isAllowed();
}
......
......@@ -3,6 +3,7 @@
namespace Drupal\eca\Entity\Objects;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Core\Access\AccessResultReasonInterface;
use Drupal\eca\Plugin\Action\ActionInterface;
use Drupal\eca\Entity\Eca;
use Drupal\Core\Action\ActionInterface as CoreActionInterface;
......@@ -92,12 +93,17 @@ class EcaAction extends EcaObject implements ObjectWithPluginInterface {
$this->eventDispatcher()->dispatch($before_event, EcaEvents::BEFORE_ACTION_EXECUTION);
try {
$access_granted = $this->plugin->access($object);
/** @var \Drupal\Core\Access\AccessResultReasonInterface $access_result */
$access_result = $this->plugin->access($object, NULL, TRUE);
$access_granted = $access_result->isAllowed();
if ($access_granted) {
$this->plugin->execute($object);
}
else {
$this->logger()->warning('Access denied to %actionlabel (%actionid) from ECA %ecalabel (%ecaid) for event %event.', $context);
$context['%reason'] = $access_result instanceof AccessResultReasonInterface ?
$access_result->getReason() :
'unknown';
$this->logger()->warning('Access denied to %actionlabel (%actionid) from ECA %ecalabel (%ecaid) for event %event: %reason', $context);
}
}
catch (\Exception $ex) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment