Mercurial > hg > isophonics-drupal-site
annotate core/modules/migrate_drupal_ui/src/MigrateAccessCheck.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\migrate_drupal_ui; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Core\Access\AccessResultAllowed; |
Chris@0 | 6 use Drupal\Core\Session\AccountInterface; |
Chris@0 | 7 |
Chris@0 | 8 /** |
Chris@0 | 9 * Checks access for migrate_drupal_ui routes. |
Chris@0 | 10 * |
Chris@0 | 11 * The Migrate Drupal UI can only be used by user 1. This is because any other |
Chris@0 | 12 * user might have different permissions on the source and target site. |
Chris@0 | 13 * |
Chris@0 | 14 * This class is designed to be used with '_custom_access' route requirement. |
Chris@0 | 15 * |
Chris@0 | 16 * @see \Drupal\Core\Access\CustomAccessCheck |
Chris@0 | 17 */ |
Chris@0 | 18 class MigrateAccessCheck { |
Chris@0 | 19 |
Chris@0 | 20 /** |
Chris@0 | 21 * Checks if the user is user 1 and grants access if so. |
Chris@0 | 22 * |
Chris@0 | 23 * @param \Drupal\Core\Session\AccountInterface $account |
Chris@0 | 24 * The current user account. |
Chris@0 | 25 * |
Chris@0 | 26 * @return \Drupal\Core\Access\AccessResult |
Chris@0 | 27 * The access result. |
Chris@0 | 28 */ |
Chris@0 | 29 public function checkAccess(AccountInterface $account) { |
Chris@0 | 30 // The access result is uncacheable because it is just limiting access to |
Chris@0 | 31 // the migrate UI which is not worth caching. |
Chris@0 | 32 return AccessResultAllowed::allowedIf((int) $account->id() === 1)->mergeCacheMaxAge(0); |
Chris@0 | 33 } |
Chris@0 | 34 |
Chris@0 | 35 } |