diff --git a/core/modules/migrate/src/Plugin/migrate/destination/Entity.php b/core/modules/migrate/src/Plugin/migrate/destination/Entity.php index b7faaae49101816a3877e86d200d67d35398a152..839a0b448b6d12147f1c2b7042eb747af67628a3 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\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 @@ protected function getEntity(Row $row, array $old_destination_id_values) { 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 5fcb6671d72590eefd352c6fb7fff672196c40d8..545db0802705c84d78d047564597c6e2f2f40c89 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 @@ public function getIds() { * @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 @@ protected function updateEntity(EntityInterface $entity, Row $row) { } $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 cd1c24c2916e1aad6abad7e52d7e2dbeb09c9646..9724ee64d3c6232768add553f851ad2f256dbc49 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 @@ public function getIds() { } /** - * 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 @@ protected function updateEntity(EntityInterface $entity, Row $row) { } /** - * 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 096f9a231ae42d0cb48f41d90421496b0adbd2fd..c9724ad8197654187abcad10ca56e3489b8ae21a 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 @@ public function save(ContentEntityInterface $entity, array $old_destination_id_v * 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 75d74ac3173cdcd628e89a630335a5aebf26c256..e2210c7034111c1b7c5d6c0270814af551b7e400 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 @@ public function import(Row $row, array $old_destination_id_values = []) { } /** - * 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 @@ protected function updateEntity(EntityInterface $entity, Row $row) { if ($plugin instanceof ConfigurableSearchPluginBase) { $plugin->setConfiguration($row->getDestinationProperty('configuration')); } + return $entity; } } diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon index d83b67c6b683526d80369fcab5bb0d21f85b3245..82e143308d71c10e097adc78b9d7d4c41226b987 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