Skip to content
Snippets Groups Projects

Issue #2946333 by tedbow, J-Lee, heddn, johnwebdev, nginex, hswong3i, cgoffin,...

35 files
+ 2384
117
Compare changes
  • Side-by-side
  • Inline
Files
35
<?php
namespace Drupal\layout_builder\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\layout_builder\LayoutTempstoreRepositoryInterface;
use Drupal\layout_builder\SectionStorageInterface;
/**
* Checks access based on whether the layout is locked.
*
* @ingroup layout_builder_access
*
* @internal
* Tagged services are internal.
*/
class LayoutBuilderLockAccessCheck implements AccessInterface {
/**
* The layout tempstore repository.
*
* @var \Drupal\layout_builder\LayoutTempstoreRepositoryInterface
*/
protected $layoutTempstoreRepository;
/**
* Constructs a LayoutBuilderLockAccessCheck.
*
* @param \Drupal\layout_builder\LayoutTempstoreRepositoryInterface $layout_tempstore_repository
* The layout tempstore repository.
*/
public function __construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository) {
$this->layoutTempstoreRepository = $layout_tempstore_repository;
}
/**
* Checks for a lock on the layout.
*
* @param \Drupal\layout_builder\SectionStorageInterface $section_storage
* The section storage.
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(SectionStorageInterface $section_storage, AccountInterface $account) {
$lock = $this->layoutTempstoreRepository->getLock($section_storage);
return AccessResult::allowedIf(!$lock || $account->id() === $lock->getOwnerId())->setCacheMaxAge(0);
}
}
Loading