Delete files on rollback in Migrate? I have a migration that pulls in a PDF with it and populates a content type. When I rollback the migration, it does not delete the PDFs with it.

How can I tell a migration on rollback to clean up after itself? Is there something I can put in the YAML? Is there an event I can hook into?
I wound up doing this to solve this case:

&lt;?php

namespace Drupal\mymodule\Plugin\migrate\destination;

use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
use Drupal\migrate\Plugin\MigrationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\node\NodeInterface;

/**
 * We need rollback support for deleting files.
 *
 * @MigrateDestination(
 *   id = "myplugin"
 * )
 */
class MyPlugin extends EntityContentBase {

  /** @var string $entityType */
  public static $entityType = 'node';

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
    return parent::create($container, $configuration, 'entity:' . static::$entityType, $plugin_definition, $migration);
  }

  /**
   * {@inheritdoc}
   */
  public function rollback(array $destination_identifier) {
    $entity = $this-&gt;storage-&gt;load(reset($destination_identifier));

    // Delete attached files on Working Papers.
    if ($entity &amp;&amp; $entity instanceof NodeInterface) {
      if ($entity-&gt;bundle() === 'working_paper') {
        $fid = $entity-&gt;get('field_paper_working_paper')-&gt;target_id;

        if ($fid) {
          $storage_handler = \Drupal::entityTypeManager()-&gt;getStorage('file');
          $entities = $storage_handler-&gt;load($fid);
          $storage_handler-&gt;delete([$entities]);
        }
      }
    }

    // Execute the normal rollback from here.
    parent::rollback($destination_identifier);
  }

}


In the migration yaml definition, point destination at this instead of entity:node:

destination:
  plugin: myplugin
  bundle: working_paper


The $entityType member and create method seemed to be required as well, otherwise Migrate did not seem to know how to parse this into a node of a particular type, despite extending from EntityContentBase.

The reason for wanting to do this is that its cumbersome especially while developing that files are not removed along with their entity on rollback. In my case, I have strictest confidence in that the rollback of this entity does not affect anything else because this is the only place this file will ever appear.

Is this the best way to add this type of behavior?