protected static function WebformVariantAccess::checkVariantAccess in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Access/WebformVariantAccess.php \Drupal\webform\Access\WebformVariantAccess::checkVariantAccess()
Check whether the webform variant is enabled.
Parameters
\Drupal\webform\WebformInterface $webform: A webform.
string|null $webform_variant: A webform variant id.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
2 calls to WebformVariantAccess::checkVariantAccess()
- WebformVariantAccess::checkVariantCreateAccess in src/
Access/ WebformVariantAccess.php - Check whether the webform variant create is enabled.
- WebformVariantAccess::checkVariantSettingsAccess in src/
Access/ WebformVariantAccess.php - Check whether the webform variant settings is enabled.
File
- src/
Access/ WebformVariantAccess.php, line 52
Class
- WebformVariantAccess
- Defines the custom access control variant for the webform variants.
Namespace
Drupal\webform\AccessCode
protected static function checkVariantAccess(WebformInterface $webform, $webform_variant = NULL) {
if (!$webform
->hasVariants()) {
$access_result = AccessResult::forbidden();
}
else {
/** @var \Drupal\webform\Plugin\WebformVariantManagerInterface $variant_manager */
$variant_manager = \Drupal::service('plugin.manager.webform.variant');
$variant_definitions = $variant_manager
->getDefinitions();
$variant_definitions = $variant_manager
->removeExcludeDefinitions($variant_definitions);
if ($webform_variant) {
$access_result = AccessResult::allowedIf(!empty($variant_definitions[$webform_variant]));
}
else {
unset($variant_definitions['broken']);
$access_result = AccessResult::allowedIf(!empty($variant_definitions));
}
}
return $access_result
->addCacheTags([
'config:webform.settings',
]);
}