comparison core/modules/user/src/ContextProvider/CurrentUserContext.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children 12f9dff5fda9
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
2 2
3 namespace Drupal\user\ContextProvider; 3 namespace Drupal\user\ContextProvider;
4 4
5 use Drupal\Core\Cache\CacheableMetadata; 5 use Drupal\Core\Cache\CacheableMetadata;
6 use Drupal\Core\Entity\EntityManagerInterface; 6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\Plugin\Context\Context;
8 use Drupal\Core\Plugin\Context\ContextDefinition;
9 use Drupal\Core\Plugin\Context\ContextProviderInterface; 7 use Drupal\Core\Plugin\Context\ContextProviderInterface;
8 use Drupal\Core\Plugin\Context\EntityContext;
10 use Drupal\Core\Session\AccountInterface; 9 use Drupal\Core\Session\AccountInterface;
11 use Drupal\Core\StringTranslation\StringTranslationTrait; 10 use Drupal\Core\StringTranslation\StringTranslationTrait;
12 11
13 /** 12 /**
14 * Sets the current user as a context. 13 * Sets the current user as a context.
54 // @todo Do not validate protected fields to avoid bug in TypedData, 53 // @todo Do not validate protected fields to avoid bug in TypedData,
55 // remove this in https://www.drupal.org/project/drupal/issues/2934192. 54 // remove this in https://www.drupal.org/project/drupal/issues/2934192.
56 $current_user->_skipProtectedUserFieldConstraint = TRUE; 55 $current_user->_skipProtectedUserFieldConstraint = TRUE;
57 } 56 }
58 57
59 $context = new Context(new ContextDefinition('entity:user', $this->t('Current user')), $current_user); 58 $context = EntityContext::fromEntity($current_user, $this->t('Current user'));
60 $cacheability = new CacheableMetadata(); 59 $cacheability = new CacheableMetadata();
61 $cacheability->setCacheContexts(['user']); 60 $cacheability->setCacheContexts(['user']);
62 $context->addCacheableDependency($cacheability); 61 $context->addCacheableDependency($cacheability);
63 62
64 $result = [ 63 $result = [