Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -11,7 +11,7 @@ use Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\StringTranslation\TranslationWrapper;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Constraint plugin manager.
@ -91,22 +91,22 @@ class ConstraintManager extends DefaultPluginManager {
*/
public function registerDefinitions() {
$this->getDiscovery()->setDefinition('Callback', array(
'label' => new TranslationWrapper('Callback'),
'label' => new TranslatableMarkup('Callback'),
'class' => '\Symfony\Component\Validator\Constraints\Callback',
'type' => FALSE,
));
$this->getDiscovery()->setDefinition('Blank', array(
'label' => new TranslationWrapper('Blank'),
'label' => new TranslatableMarkup('Blank'),
'class' => '\Symfony\Component\Validator\Constraints\Blank',
'type' => FALSE,
));
$this->getDiscovery()->setDefinition('NotBlank', array(
'label' => new TranslationWrapper('Not blank'),
'label' => new TranslatableMarkup('Not blank'),
'class' => '\Symfony\Component\Validator\Constraints\NotBlank',
'type' => FALSE,
));
$this->getDiscovery()->setDefinition('Email', array(
'label' => new TranslationWrapper('Email'),
'label' => new TranslatableMarkup('Email'),
'class' => '\Drupal\Core\Validation\Plugin\Validation\Constraint\EmailConstraint',
'type' => array('string'),
));

View file

@ -7,7 +7,8 @@
namespace Drupal\Core\Validation;
use Symfony\Component\Translation\TranslatorInterface;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Translates strings using Drupal's translation system.
@ -27,8 +28,9 @@ class DrupalTranslator implements TranslatorInterface {
* Implements \Symfony\Component\Translation\TranslatorInterface::trans().
*/
public function trans($id, array $parameters = array(), $domain = NULL, $locale = NULL) {
return t($id, $this->processParameters($parameters), $this->getOptions($domain, $locale));
// If a TranslatableMarkup object is passed in as $id, return it since the
// message has already been translated.
return $id instanceof TranslatableMarkup ? $id : t($id, $this->processParameters($parameters), $this->getOptions($domain, $locale));
}
/**
@ -41,6 +43,17 @@ class DrupalTranslator implements TranslatorInterface {
if (!isset($ids[1])) {
throw new \InvalidArgumentException(sprintf('The message "%s" cannot be pluralized, because it is missing a plural (e.g. "There is one apple|There are @count apples").', $id));
}
// Normally, calls to formatPlural() need to use literal strings, like
// formatPlural($count, '1 item', '@count items')
// so that the Drupal project POTX string extractor will correctly
// extract the strings for translation and save them in a format that
// formatPlural() can work with. However, this is a special case, because
// Drupal is supporting a constraint message format from Symfony. So
// although $id looks like a variable here, it is actually coming from a
// static string in a constraint class that the POTX extractor knows about
// and has processed to work with formatPlural(), so this specific call to
// formatPlural() will work correctly.
return \Drupal::translation()->formatPlural($number, $ids[0], $ids[1], $this->processParameters($parameters), $this->getOptions($domain, $locale));
}
@ -64,8 +77,14 @@ class DrupalTranslator implements TranslatorInterface {
protected function processParameters(array $parameters) {
$return = array();
foreach ($parameters as $key => $value) {
// We allow the values in the parameters to be safe string objects. This
// can be useful when we want to use parameter values that are
// TranslatableMarkup.
if ($value instanceof MarkupInterface) {
$value = (string) $value;
}
if (is_object($value)) {
// t() does not work will objects being passed as replacement strings.
// t() does not work with objects being passed as replacement strings.
}
// Check for symfony replacement patterns in the form "{{ name }}".
elseif (strpos($key, '{{ ') === 0 && strrpos($key, ' }}') == strlen($key) - 3) {

View file

@ -16,6 +16,7 @@ use Drupal\Core\TypedData\Type\IntegerInterface;
use Drupal\Core\TypedData\Type\StringInterface;
use Drupal\Core\TypedData\Type\UriInterface;
use Drupal\Core\TypedData\Validation\TypedDataAwareValidatorTrait;
use Drupal\Component\Render\MarkupInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
@ -49,7 +50,7 @@ class PrimitiveTypeConstraintValidator extends ConstraintValidator {
if ($typed_data instanceof IntegerInterface && filter_var($value, FILTER_VALIDATE_INT) === FALSE) {
$valid = FALSE;
}
if ($typed_data instanceof StringInterface && !is_scalar($value)) {
if ($typed_data instanceof StringInterface && !is_scalar($value) && !($value instanceof MarkupInterface)) {
$valid = FALSE;
}
// Ensure that URIs comply with http://tools.ietf.org/html/rfc3986, which

View file

@ -0,0 +1,32 @@
<?php
/**
* @file
* Contains \Drupal\Core\Validation\Plugin\Validation\Constraint\RegexConstraint.
*/
namespace Drupal\Core\Validation\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraints\Regex;
/**
* Regex constraint.
*
* Overrides the symfony constraint to use Drupal-style replacement patterns.
*
* @Constraint(
* id = "Regex",
* label = @Translation("Regex", context = "Validation")
* )
*/
class RegexConstraint extends Regex {
public $message = 'This value is not valid.';
/**
* Overrides Range::validatedBy().
*/
public function validatedBy() {
return '\Symfony\Component\Validator\Constraints\RegexValidator';
}
}

View file

@ -0,0 +1,31 @@
<?php
/**
* @file
* Contains \Drupal\Core\Validation\Plugin\Validation\Constraint\UniqueFieldConstraint.
*/
namespace Drupal\Core\Validation\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
/**
* Checks if an entity field has a unique value.
*
* @Constraint(
* id = "UniqueField",
* label = @Translation("Unique field constraint", context = "Validation"),
* )
*/
class UniqueFieldConstraint extends Constraint {
public $message = 'A @entity_type with @field_name %value already exists.';
/**
* {@inheritdoc}
*/
public function validatedBy() {
return '\Drupal\Core\Validation\Plugin\Validation\Constraint\UniqueFieldValueValidator';
}
}

View file

@ -7,6 +7,7 @@
namespace Drupal\Core\Validation\Plugin\Validation\Constraint;
use Drupal\Component\Utility\Unicode;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
@ -37,7 +38,11 @@ class UniqueFieldValueValidator extends ConstraintValidator {
->execute();
if ($value_taken) {
$this->context->addViolation($constraint->message, array("%value" => $item->value));
$this->context->addViolation($constraint->message, [
'%value' => $item->value,
'@entity_type' => $entity->getEntityType()->getLowercaseLabel(),
'@field_name' => Unicode::strtolower($items->getFieldDefinition()->getLabel()),
]);
}
}
}

View file

@ -0,0 +1,24 @@
<?php
/**
* @file
* Contains \Drupal\Core\Validation\TranslatorInterface.
*/
namespace Drupal\Core\Validation;
use Symfony\Component\Translation\TranslatorInterface as SymfonyTranslatorInterface;
/**
* Defines an interface used in validation.
*
* This extends the interface used by the Symfony validator in order to indicate
* that the Drupal code is actually independent from the Symfony translation
* component.
*
* @see https://github.com/symfony/symfony/pull/6189
* @see https://github.com/symfony/symfony/issues/15714
*/
interface TranslatorInterface extends SymfonyTranslatorInterface {
}