If I implement a simple entityrevision destination plugin which sets its own id, attempts to account for the changed id length, and does nothing more, the plugin will fail.

/**
 * @file
 *
 */

namespace Drupal\migrate_foo\Plugin\migrate\destination;

use Drupal\migrate\Plugin\migrate\destination\EntityRevision;

/**
 * Provides FOO entity revision destination plugin.
 *
 * Refer to the parent class for configuration keys:
 * \Drupal\migrate\Plugin\migrate\destination\EntityContentBase
 *
 * @see EntityRevision
 *
 * @MigrateDestination(
 *   id = "foo_entity_revision",
 *   deriver = "Drupal\migrate\Plugin\Derivative\MigrateEntityRevision"
 * )
 */
class FooEntityRevisionDestination extends EntityRevision {

  /**
   * {@inheritdoc}
   */
  protected static function getEntityTypeId($plugin_id) {
    // Remove foo_entity_revision:
    return substr($plugin_id, 20);
  }

}

The only method implemented in this plugin is getEntityTypeId(), which should return 'node' from foo_entity_revision:node. EntityContentBase::create() calls EntityRevision::getEntityTypeId() rather than FooEntityRevision::getEntityTypeId().

As a result we end up in EntityTypeManager getDefinition() throwing an exception of 'The "on:node" entity type does not exist' and receive a migrate failure message of "Unable to get entity".

If Entity::getEntityTypeId(), EntityRevision::getEntityTypeId() checked for the position of the colon, there would be no need for EntityRevision or FooEntityRevision to implement the method, and it wouldn't matter that for some reason EntityContentBase::create() calls EntityRevision::getEntityTypeId() instead of FooEntityRevision::getEntityTypeId(). This could go into Drupal\migrate\Plugin\migrate\destination\Entity and the same method would not be required in EntityRevision.php:

  /**
   * {@inheritdoc}
   */
  protected static function getEntityTypeId($plugin_id) {
    // Remove entity_revision:
    return substr($plugin_id, strpos($plugin_id, ':') + 1);
  }

Attaching example migration which can be used to reproduce this issue.

I thought this might be because derivative destinations were required to implement create(), but EntityRevision doesn't do this.

A workaround is to come up with any destination identifier which is conveniently the same length as the one you're extending, eg "foo_entity_revi"

Comments

xurizaemon created an issue. See original summary.

xurizaemon’s picture

Issue summary: View changes
xurizaemon’s picture

Issue summary: View changes
xurizaemon’s picture

StatusFileSize
new718 bytes
xurizaemon’s picture

Issue summary: View changes
xurizaemon’s picture

Issue summary: View changes
xurizaemon’s picture

Let's see if this passes tests?

xurizaemon’s picture

Status: Active » Closed (works as designed)

@mikelutz said in Slack:

> Your problem isn't that your extension can't override the getEntityTypeId method. Your problem is you need to write your own deriver. The entity revision deriver creates derivatives with the EntityRevision class, not your custom class.

Thanks!