FilterFormat.php 1.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
<?php

namespace Drupal\filter\Plugin\migrate\source\d7;

use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
use Drupal\migrate\Row;

/**
 * Drupal 7 filter source from database.
 *
 * @MigrateSource(
 *   id = "d7_filter_format"
 * )
 */
class FilterFormat extends DrupalSqlBase {

  /**
   * {@inheritdoc}
   */
  public function query() {
    return $this->select('filter_format', 'f')->fields('f');
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    return array(
      'format' => $this->t('Format ID.'),
      'name' => $this->t('The name of the format.'),
      'cache' => $this->t('Whether the format is cacheable.'),
      'status' => $this->t('The status of the format'),
      'weight' => $this->t('The weight of the format'),
      'filters' => $this->t('The filters configured for the format.'),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    // Find filters for this format.
    $filters = $this->select('filter', 'f')
      ->fields('f')
      ->condition('format', $row->getSourceProperty('format'))
      ->condition('status', 1)
      ->execute()
      ->fetchAllAssoc('name');

    foreach ($filters as $id => $filter) {
      $filters[$id]['settings'] = unserialize($filter['settings']);
    }
    $row->setSourceProperty('filters', $filters);

    return parent::prepareRow($row);
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    $ids['format']['type'] = 'string';
    return $ids;
  }

}