diff --git a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/AllowedValuesConstraintValidator.php b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/AllowedValuesConstraintValidator.php index 776a302..7ad2cfd 100644 --- a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/AllowedValuesConstraintValidator.php +++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/AllowedValuesConstraintValidator.php @@ -21,7 +21,7 @@ class AllowedValuesConstraintValidator extends ChoiceValidator { */ public function validate($value, Constraint $constraint) { if ($this->context->getMetadata()->getTypedData() instanceof AllowedValuesInterface) { - $account = \Drupal::request()->attributes->get('_account'); + $account = \Drupal::currentUser(); $allowed_values = $this->context->getMetadata()->getTypedData()->getSettableValues($account); $constraint->choices = $allowed_values; } diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php index e8c97db..003f82b 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php @@ -203,7 +203,7 @@ function testTypedDataAPI() { // Test with anonymous user. $user = drupal_anonymous_user(); - \Drupal::request()->attributes->set('_account', $user); + $this->container->set('current_user', $user); $available_values = $data->getPossibleValues(); $this->assertEqual($available_values, array('filtered_html', 'full_html', 'plain_text')); @@ -239,7 +239,7 @@ function testTypedDataAPI() { $this->assertFilterFormatViolation($violations, 'filtered_html'); // Set user with access to 'filtered_html' format. - \Drupal::request()->attributes->set('_account', $filtered_html_user); + $this->container->set('current_user', $filtered_html_user); $violations = $data->validate(); $this->assertEqual(count($violations), 0, "No validation violation for accessible format 'filtered_html' found."); diff --git a/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php b/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php index 1d18356..f218438 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php +++ b/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php @@ -122,10 +122,8 @@ public static function validateElement(array $element, array &$form_state) { */ protected function getOptions(FieldItemInterface $item) { if (!isset($this->options)) { - $module_handler = \Drupal::moduleHandler(); - // Limit the settable options for the current user account. - $options = $item->getSettableOptions(\Drupal::request()->attributes->get('_account')); + $options = $item->getSettableOptions(\Drupal::currentUser()); // Add an empty option if the widget needs one. if ($empty_option = $this->getEmptyOption()) { @@ -142,6 +140,7 @@ protected function getOptions(FieldItemInterface $item) { $options = array('_none' => $label) + $options; } + $module_handler = \Drupal::moduleHandler(); $context = array( 'fieldDefinition' => $this->fieldDefinition, 'entity' => $item->getParent()->getParent(),