FilterFormat.php 2.62 KB
Newer Older
1 2
<?php

3
namespace Drupal\filter\Plugin\migrate\source\d6;
4 5 6 7 8

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

/**
9
 * Drupal 6 filter source from database.
10 11 12 13 14 15 16 17 18 19 20
 *
 * @MigrateSource(
 *   id = "d6_filter_format"
 * )
 */
class FilterFormat extends DrupalSqlBase {

  /**
   * {@inheritdoc}
   */
  public function query() {
21
    return $this->select('filter_formats', 'f')->fields('f');
22 23 24 25 26 27 28 29
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    return array(
      'format' => $this->t('Format ID.'),
30 31 32 33
      'name' => $this->t('The name of the format.'),
      'cache' => $this->t('Whether the format is cacheable.'),
      'roles' => $this->t('The role IDs which can use the format.'),
      'filters' => $this->t('The filters configured for the format.'),
34 35 36 37 38 39 40 41 42 43 44 45
    );
  }

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    $filters = array();
    $roles = $row->getSourceProperty('roles');
    $row->setSourceProperty('roles', array_values(array_filter(explode(',', $roles))));
    $format = $row->getSourceProperty('format');
    // Find filters for this row.
46
    $results = $this->select('filters', 'f')
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
      ->fields('f', array('module', 'delta', 'weight'))
      ->condition('format', $format)
      ->execute();
    foreach ($results as $raw_filter) {
      $module = $raw_filter['module'];
      $delta = $raw_filter['delta'];
      $filter = array(
        'module' => $module,
        'delta' => $delta,
        'weight' => $raw_filter['weight'],
        'settings' => array(),
      );
      // Load the filter settings for the filter module, modules can use
      // hook_migration_d6_filter_formats_prepare_row() to add theirs.
      if ($raw_filter['module'] == 'filter') {
        if (!$delta) {
          if ($setting = $this->variableGet("allowed_html_$format", NULL)) {
            $filter['settings']['allowed_html'] = $setting;
          }
          if ($setting = $this->variableGet("filter_html_help_$format", NULL)) {
            $filter['settings']['filter_html_help'] = $setting;
          }
          if ($setting = $this->variableGet("filter_html_nofollow_$format", NULL)) {
            $filter['settings']['filter_html_nofollow'] = $setting;
          }
        }
        elseif ($delta == 2 && ($setting = $this->variableGet("filter_url_length_$format", NULL))) {
          $filter['settings']['filter_url_length'] = $setting;
        }
      }
      $filters[] = $filter;
    }

    $row->setSourceProperty('filters', $filters);
    return parent::prepareRow($row);
  }

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

92
}