forked from drupal/drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayoutBuilderTranslationAccessCheck.php
More file actions
50 lines (45 loc) · 1.78 KB
/
LayoutBuilderTranslationAccessCheck.php
File metadata and controls
50 lines (45 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Drupal\layout_builder\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\layout_builder\SectionStorageInterface;
use Drupal\layout_builder\TranslatableSectionStorageInterface;
use Symfony\Component\Routing\Route;
/**
* Provides an access check for the Layout Builder translations.
*
* @ingroup layout_builder_access
*
* @internal
* Tagged services are internal.
*/
class LayoutBuilderTranslationAccessCheck implements AccessInterface {
/**
* Checks routing access to the default translation only layout.
*
* @param \Drupal\layout_builder\SectionStorageInterface $section_storage
* The section storage.
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(SectionStorageInterface $section_storage, Route $route) {
$translation_type = $route->getRequirement('_layout_builder_translation_access');
if ($translation_type === 'untranslated') {
$access = AccessResult::allowedIf(!$section_storage instanceof TranslatableSectionStorageInterface || $section_storage->isDefaultTranslation());
}
elseif ($translation_type === 'translated') {
$access = AccessResult::allowedIf($section_storage instanceof TranslatableSectionStorageInterface && !$section_storage->isDefaultTranslation());
}
else {
throw new \UnexpectedValueException("Unexpected _layout_builder_translation_access route requirement: $translation_type");
}
if ($access instanceof RefinableCacheableDependencyInterface) {
$access->addCacheableDependency($section_storage);
}
return $access;
}
}