Unverified Commit b57afe5c authored by alexpott's avatar alexpott
Browse files

Issue #3069696 by Berdir, andypost, dhirendra.mishra, longwave, alexpott:...

Issue #3069696 by Berdir, andypost, dhirendra.mishra, longwave, alexpott: Remove BC layers from the entity system
parent 92608738
......@@ -374,31 +374,6 @@ public function calculateDependencies() {
return $this;
}
/**
* {@inheritdoc}
*/
public function urlInfo($rel = 'edit-form', array $options = []) {
// Unless language was already provided, avoid setting an explicit language.
$options += ['language' => NULL];
return parent::urlInfo($rel, $options);
}
/**
* {@inheritdoc}
*/
public function url($rel = 'edit-form', $options = []) {
// Do not remove this override: the default value of $rel is different.
return parent::url($rel, $options);
}
/**
* {@inheritdoc}
*/
public function link($text = NULL, $rel = 'edit-form', array $options = []) {
// Do not remove this override: the default value of $rel is different.
return parent::link($text, $rel, $options);
}
/**
* {@inheritdoc}
*/
......
......@@ -1244,16 +1244,9 @@ public function __clone() {
* {@inheritdoc}
*/
public function label() {
$label = NULL;
$entity_type = $this->getEntityType();
if (($label_callback = $entity_type->get('label_callback')) && is_callable($label_callback)) {
@trigger_error('Entity type ' . $this->getEntityTypeId() . ' defines a label callback. Support for that is deprecated in drupal:8.0.0 and will be removed in drupal:9.0.0. Override the EntityInterface::label() method instead. See https://www.drupal.org/node/3050794', E_USER_DEPRECATED);
$label = call_user_func($label_callback, $this);
}
elseif (($label_key = $entity_type->getKey('label'))) {
$label = $this->getEntityKey('label');
if ($this->getEntityType()->getKey('label')) {
return $this->getEntityKey('label');
}
return $label;
}
/**
......
......@@ -86,7 +86,8 @@ protected function getQueryServiceName() {
/**
* {@inheritdoc}
*/
protected function doLoadRevisionFieldItems($revision_id) {
protected function doLoadMultipleRevisionsFieldItems($revision_ids) {
return [];
}
/**
......
......@@ -580,45 +580,13 @@ public function loadMultipleRevisions(array $revision_ids) {
/**
* Actually loads revision field item values from the storage.
*
* @param int|string $revision_id
* The revision identifier.
*
* @return \Drupal\Core\Entity\EntityInterface|null
* The specified entity revision or NULL if not found.
*
* @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0.
* \Drupal\Core\Entity\ContentEntityStorageBase::doLoadMultipleRevisionsFieldItems()
* should be implemented instead.
*
* @see https://www.drupal.org/node/2924915
*/
abstract protected function doLoadRevisionFieldItems($revision_id);
/**
* Actually loads revision field item values from the storage.
*
* This method should always be overridden and not called either directly or
* from parent::doLoadMultipleRevisionsFieldItems. It will be marked abstract
* in drupal:9.0.0
*
* @param array $revision_ids
* An array of revision identifiers.
*
* @return \Drupal\Core\Entity\EntityInterface[]
* The specified entity revisions or an empty array if none are found.
*
* @todo Remove this logic and make the method abstract in
* https://www.drupal.org/project/drupal/issues/3069696
*/
protected function doLoadMultipleRevisionsFieldItems($revision_ids) {
@trigger_error('Calling ' . __NAMESPACE__ . 'ContentEntityStorageBase::doLoadMultipleRevisionsFieldItems() directly is deprecated in drupal:8.8.0 and the method will be made abstract in drupal:9.0.0. Storage implementations should override and implement their own loading logic. See https://www.drupal.org/node/3069692', E_USER_DEPRECATED);
$revisions = [];
foreach ($revision_ids as $revision_id) {
$revisions[] = $this->doLoadRevisionFieldItems($revision_id);
}
return $revisions;
}
abstract protected function doLoadMultipleRevisionsFieldItems($revision_ids);
/**
* {@inheritdoc}
......
<?php
namespace Drupal\Core\Entity;
@trigger_error('The ' . __NAMESPACE__ . '\Entity is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\EntityBase. See https://www.drupal.org/node/3021808', E_USER_DEPRECATED);
/**
* Defines a base entity class.
*
* @deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use
* \Drupal\Core\Entity\EntityBase instead.
*
* @see https://www.drupal.org/node/3021808
*/
abstract class Entity extends EntityBase {}
......@@ -148,24 +148,9 @@ public function bundle() {
* {@inheritdoc}
*/
public function label() {
$label = NULL;
$entity_type = $this->getEntityType();
if (($label_callback = $entity_type->get('label_callback')) && is_callable($label_callback)) {
@trigger_error('Entity type ' . $this->getEntityTypeId() . ' defines a label callback. Support for that is deprecated in drupal:8.0.0 and will be removed in drupal:9.0.0. Override the EntityInterface::label() method instead. See https://www.drupal.org/node/3050794', E_USER_DEPRECATED);
$label = call_user_func($label_callback, $this);
}
elseif (($label_key = $entity_type->getKey('label')) && isset($this->{$label_key})) {
$label = $this->{$label_key};
if (($label_key = $this->getEntityType()->getKey('label')) && isset($this->{$label_key})) {
return $this->{$label_key};
}
return $label;
}
/**
* {@inheritdoc}
*/
public function urlInfo($rel = 'canonical', array $options = []) {
@trigger_error('EntityInterface::urlInfo() is deprecated in Drupal 8.0.0 and will be removed in Drupal 9.0.0. EntityInterface::toUrl() instead. See https://www.drupal.org/node/2614344', E_USER_DEPRECATED);
return $this->toUrl($rel, $options);
}
/**
......@@ -249,14 +234,6 @@ protected function linkTemplates() {
return $this->getEntityType()->getLinkTemplates();
}
/**
* {@inheritdoc}
*/
public function link($text = NULL, $rel = 'canonical', array $options = []) {
@trigger_error("EntityInterface::link() is deprecated in Drupal 8.0.0 and will be removed in Drupal 9.0.0. Use EntityInterface::toLink()->toString() instead. Note, the default relationship for configuration entities changes from 'edit-form' to 'canonical'. See https://www.drupal.org/node/2614344", E_USER_DEPRECATED);
return $this->toLink($text, $rel, $options)->toString();
}
/**
* {@inheritdoc}
*/
......@@ -270,23 +247,6 @@ public function toLink($text = NULL, $rel = 'canonical', array $options = []) {
return new Link($text, $url);
}
/**
* {@inheritdoc}
*/
public function url($rel = 'canonical', $options = []) {
@trigger_error('EntityInterface::url() is deprecated in Drupal 8.0.0 and will be removed in Drupal 9.0.0. EntityInterface::toUrl() instead. Note, a \Drupal\Core\Url object is returned. See https://www.drupal.org/node/2614344', E_USER_DEPRECATED);
// While self::toUrl() will throw an exception if the entity has no id,
// the expected result for a URL is always a string.
if ($this->id() === NULL || !$this->hasLinkTemplate($rel)) {
return '';
}
$uri = $this->toUrl($rel);
$options += $uri->getOptions();
$uri->setOptions($options);
return $uri->toString();
}
/**
* Gets an array of placeholders for this entity.
*
......
......@@ -97,26 +97,6 @@ public function getChangeSummary();
*/
public function getChangeList();
/**
* Applies all the detected valid changes.
*
* Use this with care, as it will apply updates for any module, which will
* lead to unpredictable results.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* This exception is thrown if a change cannot be applied without
* unacceptable data loss. In such a case, the site administrator needs to
* apply some other process, such as a custom update function or a
* migration via the Migrate module.
*
* @deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use
* \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::getChangeList()
* and execute each entity type and field storage update manually instead.
*
* @see https://www.drupal.org/node/3034742
*/
public function applyUpdates();
/**
* Returns an entity type definition ready to be manipulated.
*
......
......@@ -183,12 +183,6 @@ protected function init() {
if (!$definition->isDisplayConfigurable($this->displayContext) || (!isset($this->content[$name]) && !isset($this->hidden[$name]))) {
$options = $definition->getDisplayOptions($this->displayContext);
// @todo Remove handling of 'type' in https://www.drupal.org/node/2799641.
if (!isset($options['region']) && !empty($options['type']) && $options['type'] === 'hidden') {
$options['region'] = 'hidden';
@trigger_error("Support for using 'type' => 'hidden' in a component is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use 'region' => 'hidden' instead. See https://www.drupal.org/node/2801513", E_USER_DEPRECATED);
}
if (!empty($options['region']) && $options['region'] === 'hidden') {
$this->removeComponent($name);
}
......@@ -253,13 +247,6 @@ public function id() {
public function preSave(EntityStorageInterface $storage) {
// Ensure that a region is set on each component.
foreach ($this->getComponents() as $name => $component) {
// @todo Remove this BC layer in Drupal 9.
// @see https://www.drupal.org/project/drupal/issues/2799641
if (!isset($component['region']) && isset($component['type']) && $component['type'] === 'hidden') {
@trigger_error("Support for using 'type' => 'hidden' in a component is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use 'region' => 'hidden' instead. See https://www.drupal.org/node/2801513", E_USER_DEPRECATED);
$this->removeComponent($name);
}
// Ensure that a region is set.
if (isset($this->content[$name]) && !isset($component['region'])) {
// Directly set the component to bypass other changes in setComponent().
......@@ -272,29 +259,6 @@ public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
}
/**
* Handles a component type of 'hidden'.
*
* The logic of this method has been duplicated inline in the preSave()
* method so that this method may remain deprecated and trigger an error.
*
* @param string $name
* The name of the component.
* @param array $component
* The component array.
*
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. No
* replacement is provided.
*
* @see https://www.drupal.org/node/2801513
*/
protected function handleHiddenType($name, array $component) {
@trigger_error(__METHOD__ . ' is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. No replacement is provided. See https://www.drupal.org/node/2801513', E_USER_DEPRECATED);
if (!isset($component['region']) && isset($component['type']) && $component['type'] === 'hidden') {
$this->removeComponent($name);
}
}
/**
* {@inheritdoc}
*/
......
......@@ -95,26 +95,6 @@ public function bundle();
*/
public function label();
/**
* Gets the URL object for the entity.
*
* @param string $rel
* The link relationship type, for example: canonical or edit-form.
* @param array $options
* See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for
* the available options.
*
* @return \Drupal\Core\Url
* The URL object.
*
* @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.
* Use \Drupal\Core\Entity\EntityInterface::toUrl() instead.
*
* @see https://www.drupal.org/node/2614344
* @see \Drupal\Core\Entity\EntityInterface::toUrl
*/
public function urlInfo($rel = 'canonical', array $options = []);
/**
* Gets the URL object for the entity.
*
......@@ -153,49 +133,6 @@ public function urlInfo($rel = 'canonical', array $options = []);
*/
public function toUrl($rel = 'canonical', array $options = []);
/**
* Gets the public URL for this entity.
*
* @param string $rel
* The link relationship type, for example: canonical or edit-form.
* @param array $options
* See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for
* the available options.
*
* @return string
* The URL for this entity.
*
* @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.
* Please use toUrl() instead.
*
* @see https://www.drupal.org/node/2614344
* @see \Drupal\Core\Entity\EntityInterface::toUrl
*/
public function url($rel = 'canonical', $options = []);
/**
* Deprecated way of generating a link to the entity. See toLink().
*
* @param string|null $text
* (optional) The link text for the anchor tag as a translated string.
* If NULL, it will use the entity's label. Defaults to NULL.
* @param string $rel
* (optional) The link relationship type. Defaults to 'canonical'.
* @param array $options
* See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for
* the available options.
*
* @return string
* An HTML string containing a link to the entity.
*
* @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.
* Use \Drupal\Core\EntityInterface::toLink()->toString() instead.
*
* @see https://www.drupal.org/node/2614344
* @see \Drupal\Core\Entity\EntityInterface::toLink()
*/
public function link($text = NULL, $rel = 'canonical', array $options = []);
/**
* Generates the HTML for a link to this entity.
*
......
......@@ -104,23 +104,6 @@ protected function getEntityIds() {
return $query->execute();
}
/**
* Gets the label of an entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being listed.
*
* @return string
* The entity label.
*
* @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.
* Use $entity->label() instead. This method used to escape the entity
* label. The render system's autoescape is now relied upon.
*/
protected function getLabel(EntityInterface $entity) {
return $entity->label();
}
/**
* {@inheritdoc}
*/
......
......@@ -18,18 +18,11 @@ public function isPublished();
/**
* Sets the entity as published.
*
* @param bool|null $published
* (optional and deprecated) TRUE to set this entity to published, FALSE to
* set it to unpublished. Defaults to NULL. This parameter is deprecated in
* Drupal 8.3.0 and will be removed before Drupal 9.0.0. Use this method,
* without any parameter, to set the entity as published and
* setUnpublished() to set the entity as unpublished.
*
* @return $this
*
* @see \Drupal\Core\Entity\EntityPublishedInterface::setUnpublished()
*/
public function setPublished($published = NULL);
public function setPublished();
/**
* Sets the entity as unpublished.
......
......@@ -51,16 +51,9 @@ public function isPublished() {
/**
* {@inheritdoc}
*/
public function setPublished($published = NULL) {
if ($published !== NULL) {
@trigger_error('The $published parameter is deprecated since version 8.3.x and will be removed in 9.0.0.', E_USER_DEPRECATED);
$value = (bool) $published;
}
else {
$value = TRUE;
}
public function setPublished() {
$key = $this->getEntityType()->getKey('published');
$this->set($key, $value);
$this->set($key, TRUE);
return $this;
}
......
......@@ -35,8 +35,6 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
public function defaultConfiguration() {
return [
'target_type' => NULL,
// @todo Remove this key in Drupal 9.0.x.
'handler' => $this->getPluginId(),
'entity' => NULL,
];
}
......@@ -52,17 +50,11 @@ public function getConfiguration() {
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
// Resolve backward compatibility level configurations, if any.
$this->resolveBackwardCompatibilityConfiguration($configuration);
// Merge in defaults.
$this->configuration = NestedArray::mergeDeep(
$this->defaultConfiguration(),
$configuration
);
// Ensure a backward compatibility level configuration.
$this->ensureBackwardCompatibilityConfiguration();
}
/**
......@@ -94,75 +86,4 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
*/
public function entityQueryAlter(SelectInterface $query) {}
/**
* Moves the backward compatibility level configurations in the right place.
*
* In order to keep backward compatibility, we copy all settings, except
* 'target_type', 'handler' and 'entity' under 'handler_settings', following
* the structure from the field config. If the plugin was instantiated using
* the 'handler_settings' level, those values will be used. In case of
* conflict, the root level settings will take precedence. The backward
* compatibility aware configuration will have the next structure:
* - target_type
* - handler (will be removed in Drupal 9.0.x, it's the plugin id)
* - entity
* - setting_1
* - setting_2
* ...
* - setting_N
* - handler_settings: (will be removed in Drupal 9.0.x)
* - setting_1
* - setting_2
* ...
* - setting_N
*
* @param array $configuration
* The configuration array to be altered.
*
* @internal
*
* @todo Remove this method call and its method in Drupal 9.
*
* @see https://www.drupal.org/project/drupal/issues/3069757
* @see https://www.drupal.org/node/2870971
*/
protected function resolveBackwardCompatibilityConfiguration(array &$configuration) {
if (isset($this->defaultConfiguration()['handler_settings'])) {
throw new \InvalidArgumentException("{$this->getPluginDefinition()['class']}::defaultConfiguration() should not contain a 'handler_settings' key. All settings should be placed in the root level.");
}
// Extract the BC level from the passed configuration, if any.
if (array_key_exists('handler_settings', $configuration)) {
if (!is_array($configuration['handler_settings'])) {
throw new \InvalidArgumentException("The setting 'handler_settings' is reserved and cannot be used.");
}
@trigger_error("Providing settings under 'handler_settings' is deprecated in drupal:8.4.0 support for 'handler_settings' is removed from drupal:9.0.0. Move the settings in the root of the configuration array. See https://www.drupal.org/node/2870971", E_USER_DEPRECATED);
// Settings passed in the root level take precedence over BC settings.
$configuration += $configuration['handler_settings'];
unset($configuration['handler_settings']);
}
}
/**
* Ensures a backward compatibility level configuration.
*
* @internal
*
* @todo Remove this method call and its method in Drupal 9.
*
* @see https://www.drupal.org/project/drupal/issues/3069757
* @see https://www.drupal.org/node/2870971
*/
protected function ensureBackwardCompatibilityConfiguration() {
$keys = ['handler', 'target_type', 'entity', 'handler_settings'];
// Synchronize back 'handler_settings'.
foreach ($this->configuration as $key => $value) {
// Filter out keys that belong strictly to the root level.
if (!in_array($key, $keys, TRUE)) {
$this->configuration['handler_settings'][$key] = $value;
}
}
}
}
......@@ -44,16 +44,10 @@ class EntityRepository implements EntityRepositoryInterface {
* @param \Drupal\Core\Plugin\Context\ContextRepositoryInterface $context_repository
* The context repository service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, ContextRepositoryInterface $context_repository = NULL) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, ContextRepositoryInterface $context_repository) {
$this->entityTypeManager = $entity_type_manager;
$this->languageManager = $language_manager;
if (isset($context_repository)) {
$this->contextRepository = $context_repository;
}
else {
@trigger_error('The context.repository service must be passed to EntityRepository::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2938929.', E_USER_DEPRECATED);
$this->contextRepository = \Drupal::service('context.repository');
}
$this->contextRepository = $context_repository;
}
/**
......
......@@ -88,18 +88,13 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface|null $memory_cache
* The memory cache.
*/
public function __construct(EntityTypeInterface $entity_type, MemoryCacheInterface $memory_cache = NULL) {
public function __construct(EntityTypeInterface $entity_type, MemoryCacheInterface $memory_cache) {
$this->entityTypeId = $entity_type->id();
$this->entityType = $entity_type;
$this->idKey = $this->entityType->getKey('id');
$this->uuidKey = $this->entityType->getKey('uuid');
$this->langcodeKey = $this->entityType->getKey('langcode');
$this->entityClass = $this->entityType->getClass();
if (!isset($memory_cache)) {
@trigger_error('The $memory_cache parameter was added in Drupal 8.6.x and will be required in 9.0.0. See https://www.drupal.org/node/2973262', E_USER_DEPRECATED);
$memory_cache = \Drupal::service('entity.memory_cache');
}
$this->memoryCache = $memory_cache;
$this->memoryCacheTag = 'entity.memory_cache:' . $this->entityTypeId;
}
......
......@@ -91,18 +91,6 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
*/
protected $links = [];
/**
* The name of a callback that returns the label of the entity.
*
* @var callable|null
*
* @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Override the
* EntityInterface::label() method instead for dynamic labels.
*
* @see \Drupal\Core\Entity\EntityInterface::label()
*/
protected $label_callback = NULL;
/**
* The name of the entity type which provides bundles.
*
......@@ -662,31 +650,6 @@ public function setLinkTemplate($key, $path) {
return $this;
}
/**
* {@inheritdoc}
*/
public function getLabelCallback() {
@trigger_error('EntityType::getLabelCallback() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Override the EntityInterface::label() method instead for dynamic labels. See https://www.drupal.org/node/3050794', E_USER_DEPRECATED);
return $this->label_callback;
}
/**