WebformShareAccess.php in Webform 8.5
File
modules/webform_share/src/Access/WebformShareAccess.php
View source
<?php
namespace Drupal\webform_share\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
use Drupal\webform\WebformInterface;
use Drupal\webform_node\Access\WebformNodeAccess;
class WebformShareAccess {
public static function checkAccess(WebformInterface $webform) {
$share = $webform
->getSetting('share', TRUE);
$share_node = \Drupal::moduleHandler()
->moduleExists('webform_node') && $webform
->getSetting('share_node', TRUE);
$template = $webform
->isTemplate();
return AccessResult::allowedIf(($share || $share_node) && !$template)
->addCacheTags([
'config:webform.settings',
])
->addCacheableDependency($webform);
}
public static function checkNodeAccess($operation, $entity_access, NodeInterface $node, AccountInterface $account) {
$entity_reference_manager = \Drupal::service('webform.entity_reference_manager');
$webform = $entity_reference_manager
->getWebform($node);
if (!$webform) {
return AccessResult::forbidden()
->addCacheableDependency($node);
}
$share = $webform
->getSetting('share_node', TRUE);
if (!$share) {
return AccessResult::forbidden()
->addCacheTags([
'config:webform.settings',
])
->addCacheableDependency($node)
->addCacheableDependency($webform);
}
return WebformNodeAccess::checkAccess($operation, $entity_access, $node, NULL, $account);
}
}