diff --git a/core/modules/migrate/src/Plugin/migrate/destination/Entity.php b/core/modules/migrate/src/Plugin/migrate/destination/Entity.php index b7faaae4910..839a0b448b6 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/Entity.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/Entity.php @@ -6,6 +6,7 @@ use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\DependencyTrait; use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\EntityFieldDefinitionTrait; @@ -181,6 +182,35 @@ abstract class Entity extends DestinationBase implements ContainerFactoryPluginI return $entity; } + /** + * Updates an entity with the new values from row. + * + * This method should be implemented in extending classes. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity to update. + * @param \Drupal\migrate\Row $row + * The row object to update from. + * + * @return \Drupal\Core\Entity\EntityInterface + * An updated entity from row values. + * + * @throws \LogicException + * Thrown for config entities, if the destination is for translations and + * either the "property" or "translation" property does not exist. + */ + abstract protected function updateEntity(EntityInterface $entity, Row $row); + + /** + * Populates as much of the stub row as possible. + * + * This method can be implemented in extending classes when needed. + * + * @param \Drupal\migrate\Row $row + * The row of data. + */ + protected function processStubRow(Row $row) {} + /** * Gets the entity ID of the row. * diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php index 5fcb6671d72..545db080270 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php @@ -193,6 +193,9 @@ class EntityConfigBase extends Entity { * @param \Drupal\migrate\Row $row * The row object to update from. * + * @return \Drupal\Core\Entity\EntityInterface + * An updated entity from row values. + * * @throws \LogicException * Thrown if the destination is for translations and either the "property" * or "translation" property does not exist. @@ -226,6 +229,8 @@ class EntityConfigBase extends Entity { } $this->setRollbackAction($row->getIdMap()); } + + return $entity; } /** diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index cd1c24c2916..9724ee64d3c 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -266,15 +266,7 @@ class EntityContentBase extends Entity implements HighestIdInterface, MigrateVal } /** - * Updates an entity with the new values from row. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity to update. - * @param \Drupal\migrate\Row $row - * The row object to update from. - * - * @return \Drupal\Core\Entity\EntityInterface - * An updated entity from row values. + * {@inheritdoc} */ protected function updateEntity(EntityInterface $entity, Row $row) { $empty_destinations = $row->getEmptyDestinationProperties(); @@ -325,10 +317,7 @@ class EntityContentBase extends Entity implements HighestIdInterface, MigrateVal } /** - * Populates as much of the stub row as possible. - * - * @param \Drupal\migrate\Row $row - * The row of data. + * {@inheritdoc} */ protected function processStubRow(Row $row) { $bundle_key = $this->getKey('bundle'); diff --git a/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php b/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php index 096f9a231ae..c9724ad8197 100644 --- a/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php +++ b/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php @@ -242,6 +242,14 @@ class EntityRevision extends RealEntityRevision { * This method is from the parent and we aren't concerned with the inner * workings of its implementation which would trickle into mock assertions. An * empty implementation avoids this. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity to update. + * @param \Drupal\migrate\Row $row + * The row object to update from. + * + * @return \Drupal\Core\Entity\EntityInterface + * An updated entity from row values. */ protected function updateEntity(EntityInterface $entity, Row $row) { return $entity; diff --git a/core/modules/search/src/Plugin/migrate/destination/EntitySearchPage.php b/core/modules/search/src/Plugin/migrate/destination/EntitySearchPage.php index 75d74ac3173..e2210c70341 100644 --- a/core/modules/search/src/Plugin/migrate/destination/EntitySearchPage.php +++ b/core/modules/search/src/Plugin/migrate/destination/EntitySearchPage.php @@ -90,12 +90,7 @@ class EntitySearchPage extends EntityConfigBase { } /** - * Updates the entity with the contents of a row. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The search page entity. - * @param \Drupal\migrate\Row $row - * The row object to update from. + * {@inheritdoc} */ protected function updateEntity(EntityInterface $entity, Row $row) { parent::updateEntity($entity, $row); @@ -105,6 +100,7 @@ class EntitySearchPage extends EntityConfigBase { if ($plugin instanceof ConfigurableSearchPluginBase) { $plugin->setConfiguration($row->getDestinationProperty('configuration')); } + return $entity; } } diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon index d83b67c6b68..82e143308d7 100644 --- a/core/phpstan-baseline.neon +++ b/core/phpstan-baseline.neon @@ -1500,16 +1500,6 @@ parameters: count: 1 path: modules/migrate/src/Plugin/migrate/destination/Config.php - - - message: "#^Call to an undefined method Drupal\\\\migrate\\\\Plugin\\\\migrate\\\\destination\\\\Entity\\:\\:processStubRow\\(\\)\\.$#" - count: 1 - path: modules/migrate/src/Plugin/migrate/destination/Entity.php - - - - message: "#^Call to an undefined method Drupal\\\\migrate\\\\Plugin\\\\migrate\\\\destination\\\\Entity\\:\\:updateEntity\\(\\)\\.$#" - count: 1 - path: modules/migrate/src/Plugin/migrate/destination/Entity.php - - message: "#^Method Drupal\\\\migrate\\\\Plugin\\\\migrate\\\\destination\\\\Entity\\:\\:fields\\(\\) should return array but return statement is missing\\.$#" count: 1