The code snippets in comments #4 and #5 don't work anymore (Drupal 8.6, Drush...

Contribution Date
Technology
Contribution Project
Contribution Details

The code snippets in comments #4 and #5 don't work anymore (Drupal 8.6, Drush 9.4). I adapted the code in an event subscriber instead. Here's the snippet:

<?php namespace Drupal\zi_migrate_support\EventSubscriber; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\migrate\Event\MigrateEvents; use Drupal\migrate\Event\MigrateImportEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Class MigrateSubscriber. */ class MigrateSubscriber implements EventSubscriberInterface { protected $entityTypeManager; protected $fieldConfigStorage; public function __construct(EntityTypeManagerInterface $entity_type_manager) { $this->entityTypeManager = $entity_type_manager; $this->fieldConfigStorage = $entity_type_manager->getStorage('field_config'); } public function preImport(MigrateImportEvent $event) { $this->setFilefieldPathsStatus('node.article.field_photos', FALSE); $this->setFilefieldPathsStatus('node.article.field_videos', FALSE); $this->setFilefieldPathsStatus('node.announcement.field_image', FALSE); $this->setGeocodeStatus('node.article.field_location_coordinates', FALSE); } public function postImport(MigrateImportEvent $event) { $this->setFilefieldPathsStatus('node.article.field_photos', TRUE); $this->setFilefieldPathsStatus('node.article.field_videos', TRUE); $this->setFilefieldPathsStatus('node.announcement.field_image', TRUE); $this->setGeocodeStatus('node.article.field_location_coordinates', TRUE); } protected function setFilefieldPathsStatus($field_name, $enabled) { $field_config = $this->fieldConfigStorage->load($field_name); $field_config->setThirdPartySetting('filefield_paths', 'enabled', $enabled); $field_config->save(); } protected function setGeocodeStatus($field_name, $enabled) { $field_config = $this->fieldConfigStorage->load($field_name); $field_config->setThirdPartySetting('geocoder_field', 'method', $enabled ? 'source' : 'none'); $field_config->save(); } public static function getSubscribedEvents() { $events = []; $events[MigrateEvents::PRE_IMPORT][] = ['preImport']; $events[MigrateEvents::POST_IMPORT][] = ['postImport']; return $events; } }

The code should be self explanatory. It's a little beyond scope of this issue but this also shows how to disable geocoding during migrations.

To register the event subscribed, here is the snippet from the services.yml file.

services: zi_migrate_support.migrate_event_subscriber: class: Drupal\zi_migrate_support\EventSubscriber\MigrateSubscriber arguments: ['@entity_type.manager'] tags: - { name: event_subscriber }
Issue Status
Needs work
Contribution Author
Files count
0
Patches count
0