You are here

public function D6Webform::postRollback in Webform: Migrate 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/migrate/source/d6/D6Webform.php \Drupal\webform_migrate\Plugin\migrate\source\d6\D6Webform::postRollback()

Performs post-rollback tasks.

Parameters

\Drupal\migrate\Event\MigrateRollbackEvent $event: The post-rollback event object.

Overrides SourcePluginBase::postRollback

File

src/Plugin/migrate/source/d6/D6Webform.php, line 685

Class

D6Webform
Drupal 6 webform source from database.

Namespace

Drupal\webform_migrate\Plugin\migrate\source\d6

Code

public function postRollback(MigrateRollbackEvent $event) {

  // Remove any Webform from webform if webform no longer exists.
  $webforms = $this
    ->query()
    ->execute();
  foreach ($webforms as $webform) {
    $webform_nid = $webform['nid'];
    $webform_id = 'webform_' . $webform_nid;
    $webform = Webform::load($webform_id);
    if (empty($webform)) {

      /** @var \Drupal\node\NodeInterface $node */
      $node = Node::load($webform['nid']);
      if (!empty($node) && $node
        ->getType() == 'webform') {
        if (!empty($node->webform->target_id) && $node->webform->target_id == $webform_id) {
          $node->webform->target_id = NULL;
          $node
            ->save();
        }
      }
    }
  }
}