cforge-2.0.x-dev/modules/cforge_address/src/Plugin/migrate/destination/Neighbourhoods.php

modules/cforge_address/src/Plugin/migrate/destination/Neighbourhoods.php
<?php

namespace Drupal\cforge_address\Plugin\migrate\destination;

use Drupal\cforge_address\Entity\Neighbourhood;
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;

/**
 * Provides variable destination plugin.
 *
 * @MigrateDestination(
 *   id = "cf_neighbourhoods"
 * )
 */
class Neighbourhoods extends EntityConfigBase {

  /**
    * {@inheritdoc}
    */
  public function import(Row $row, array $old_destination_id_values = []) {
    $hood_list = $row->getSourceProperty('cforge_neighbourhoods');
    if (empty($hood_list)) {
      \Drupal::messenger()->addWarning('No Neighbourhoods found to migrate: '.implode('; ', $row->getSource()));
      return [];
    }

    $hoods = Neighbourhood::import(explode("\n", $hood_list));
    //just return one nid because only one is expected
    return [reset($hoods)->id()];
  }

  /**
   * {@inheritDoc}
   */
  public function getIds() {
    return [
      'id' => [
        'type' => 'string',
        'max_length' => 8,
        'is_ascii' => TRUE,
      ],
    ];
  }


  protected static function getEntityTypeId($plugin_id) {
    return 'neighbourhood';
  }


}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc