upgrades core to 8.4.2

This commit is contained in:
Bachir Soussi Chiadmi
2017-11-14 16:09:54 +01:00
parent bd60eff9b3
commit c2b4e25be4
3504 changed files with 140306 additions and 38684 deletions
+2 -2
View File
@@ -16,14 +16,14 @@ class DeleteForm extends ConfirmFormBase {
/**
* The alias storage service.
*
* @var AliasStorageInterface $path
* @var AliasStorageInterface
*/
protected $aliasStorage;
/**
* The path alias being deleted.
*
* @var array $pathAlias
* @var array
*/
protected $pathAlias;
@@ -34,4 +34,42 @@ class PathFieldItemList extends FieldItemList {
\Drupal::service('path.alias_storage')->delete($conditions);
}
/**
* {@inheritdoc}
*/
public function getValue($include_computed = FALSE) {
$this->ensureLoaded();
return parent::getValue($include_computed);
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
$this->ensureLoaded();
return parent::isEmpty();
}
/**
* {@inheritdoc}
*/
public function getIterator() {
$this->ensureLoaded();
return parent::getIterator();
}
/**
* Automatically create the first item for computed fields.
*
* This ensures that ::getValue() and ::isEmpty() calls will behave like a
* non-computed field.
*
* @todo: Move this to the base class in https://www.drupal.org/node/2392845.
*/
protected function ensureLoaded() {
if (!isset($this->list[0]) && $this->definition->isComputed()) {
$this->list[0] = $this->createItem(0);
}
}
}
@@ -17,11 +17,26 @@ use Drupal\Core\TypedData\DataDefinition;
* description = @Translation("An entity field containing a path alias and related data."),
* no_ui = TRUE,
* default_widget = "path",
* list_class = "\Drupal\path\Plugin\Field\FieldType\PathFieldItemList"
* list_class = "\Drupal\path\Plugin\Field\FieldType\PathFieldItemList",
* constraints = {"PathAlias" = {}},
* )
*/
class PathItem extends FieldItemBase {
/**
* Whether the alias has been loaded from the alias storage service yet.
*
* @var bool
*/
protected $isLoaded = FALSE;
/**
* Whether the alias is currently being set.
*
* @var bool
*/
protected $isLoading = FALSE;
/**
* {@inheritdoc}
*/
@@ -30,9 +45,19 @@ class PathItem extends FieldItemBase {
->setLabel(t('Path alias'));
$properties['pid'] = DataDefinition::create('integer')
->setLabel(t('Path id'));
$properties['langcode'] = DataDefinition::create('string')
->setLabel(t('Language Code'));
return $properties;
}
/**
* {@inheritdoc}
*/
public function __get($name) {
$this->ensureLoaded();
return parent::__get($name);
}
/**
* {@inheritdoc}
*/
@@ -40,6 +65,30 @@ class PathItem extends FieldItemBase {
return [];
}
/**
* {@inheritdoc}
*/
public function getValue() {
$this->ensureLoaded();
return parent::getValue();
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
$this->ensureLoaded();
return parent::isEmpty();
}
/**
* {@inheritdoc}
*/
public function getIterator() {
$this->ensureLoaded();
return parent::getIterator();
}
/**
* {@inheritdoc}
*/
@@ -47,6 +96,47 @@ class PathItem extends FieldItemBase {
$this->alias = trim($this->alias);
}
/**
* {@inheritdoc}
*/
public function __set($name, $value) {
// Also ensure that existing values are loaded when setting a value, this
// ensures that it is possible to set a new value immediately after loading
// an entity.
$this->ensureLoaded();
parent::__set($name, $value);
}
/**
* {@inheritdoc}
*/
public function set($property_name, $value, $notify = TRUE) {
// Also ensure that existing values are loaded when setting a value, this
// ensures that it is possible to set a new value immediately after loading
// an entity.
$this->ensureLoaded();
return parent::set($property_name, $value, $notify);
}
/**
* {@inheritdoc}
*/
public function get($property_name) {
$this->ensureLoaded();
return parent::get($property_name);
}
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE) {
// Also ensure that existing values are loaded when setting a value, this
// ensures that it is possible to set a new value immediately after loading
// an entity.
$this->ensureLoaded();
return parent::setValue($values, $notify);
}
/**
* {@inheritdoc}
*/
@@ -88,4 +178,42 @@ class PathItem extends FieldItemBase {
return 'alias';
}
/**
* Ensures the alias properties are loaded if available.
*
* This ensures that the properties will always be loaded and act like
* non-computed fields when calling ::__get() and getValue().
*
* @todo: Determine if this should be moved to the base class in
* https://www.drupal.org/node/2392845.
*/
protected function ensureLoaded() {
// Make sure to avoid a infinite loop if setValue() has be called from this
// block which calls ensureLoaded().
if (!$this->isLoaded && !$this->isLoading) {
$entity = $this->getEntity();
if (!$entity->isNew()) {
// @todo Support loading languge neutral aliases in
// https://www.drupal.org/node/2511968.
$alias = \Drupal::service('path.alias_storage')->load([
'source' => '/' . $entity->toUrl()->getInternalPath(),
'langcode' => $this->getLangcode(),
]);
if ($alias) {
$this->isLoading = TRUE;
$this->setValue($alias);
$this->isLoading = FALSE;
}
else {
// If there is no existing alias, default the langcode to the current
// language.
// @todo Set the langcode to not specified for untranslatable fields
// in https://www.drupal.org/node/2689459.
$this->langcode = $this->getLangcode();
}
}
$this->isLoaded = TRUE;
}
}
}
@@ -5,7 +5,6 @@ namespace Drupal\path\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Symfony\Component\Validator\ConstraintViolationInterface;
/**
@@ -26,23 +25,6 @@ class PathWidget extends WidgetBase {
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$entity = $items->getEntity();
$path = [];
if (!$entity->isNew()) {
$conditions = ['source' => '/' . $entity->urlInfo()->getInternalPath()];
if ($items->getLangcode() != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
$conditions['langcode'] = $items->getLangcode();
}
$path = \Drupal::service('path.alias_storage')->load($conditions);
if ($path === FALSE) {
$path = [];
}
}
$path += [
'pid' => NULL,
'source' => !$entity->isNew() ? '/' . $entity->urlInfo()->getInternalPath() : NULL,
'alias' => '',
'langcode' => $items->getLangcode(),
];
$element += [
'#element_validate' => [[get_class($this), 'validateFormElement']],
@@ -50,22 +32,22 @@ class PathWidget extends WidgetBase {
$element['alias'] = [
'#type' => 'textfield',
'#title' => $element['#title'],
'#default_value' => $path['alias'],
'#default_value' => $items[$delta]->alias,
'#required' => $element['#required'],
'#maxlength' => 255,
'#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page.'),
];
$element['pid'] = [
'#type' => 'value',
'#value' => $path['pid'],
'#value' => $items[$delta]->pid,
];
$element['source'] = [
'#type' => 'value',
'#value' => $path['source'],
];
'#value' => !$entity->isNew() ? '/' . $entity->toUrl()->getInternalPath() : NULL,
];
$element['langcode'] = [
'#type' => 'value',
'#value' => $path['langcode'],
'#value' => $items[$delta]->langcode,
];
return $element;
}
@@ -0,0 +1,19 @@
<?php
namespace Drupal\path\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
/**
* Validation constraint for changing path aliases in pending revisions.
*
* @Constraint(
* id = "PathAlias",
* label = @Translation("Path alias.", context = "Validation"),
* )
*/
class PathAliasConstraint extends Constraint {
public $message = 'You can only change the URL alias for the <em>published</em> version of this content.';
}
@@ -0,0 +1,57 @@
<?php
namespace Drupal\path\Plugin\Validation\Constraint;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Constraint validator for changing path aliases in pending revisions.
*/
class PathAliasConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
private $entityTypeManager;
/**
* Creates a new PathAliasConstraintValidator instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
$entity = !empty($value->getParent()) ? $value->getEntity() : NULL;
if ($entity && !$entity->isNew() && !$entity->isDefaultRevision()) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $original */
$original = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id());
if ($value->alias != $original->path->alias) {
$this->context->addViolation($constraint->message);
}
}
}
}
@@ -19,7 +19,7 @@ class UrlAlias extends DestinationBase implements ContainerFactoryPluginInterfac
/**
* The alias storage service.
*
* @var \Drupal\Core\Path\AliasStorage $aliasStorage
* @var \Drupal\Core\Path\AliasStorage
*/
protected $aliasStorage;
@@ -9,7 +9,7 @@ use Drupal\path\Plugin\migrate\source\UrlAliasBase;
*
* @MigrateSource(
* id = "d6_url_alias",
* source_provider = "path"
* source_module = "path"
* )
*/
class UrlAlias extends UrlAliasBase {
@@ -9,7 +9,7 @@ use Drupal\path\Plugin\migrate\source\UrlAliasBase;
*
* @MigrateSource(
* id = "d7_url_alias",
* source_provider = "path"
* source_module = "path"
* )
*/
class UrlAlias extends UrlAliasBase {