You are here

class SourceFilter in Migrate Tools 8.5

Same name and namespace in other branches
  1. 8.4 src/SourceFilter.php \Drupal\migrate_tools\SourceFilter

Class to filter source by an ID list.

Hierarchy

  • class \Drupal\migrate_tools\SourceFilter extends \Drupal\migrate_tools\FilterIterator

Expanded class hierarchy of SourceFilter

File

src/SourceFilter.php, line 11

Namespace

Drupal\migrate_tools
View source
class SourceFilter extends \FilterIterator {

  /**
   * List of specific source IDs to import.
   *
   * @var array
   */
  protected $idList;

  /**
   * SourceFilter constructor.
   *
   * @param \Drupal\migrate\Plugin\MigrateSourceInterface $source
   *   The ID map.
   * @param array $id_list
   *   The id list to use in the filter.
   */
  public function __construct(MigrateSourceInterface $source, array $id_list) {
    parent::__construct($source);
    $this->idList = $id_list;
  }

  /**
   * {@inheritdoc}
   */
  public function accept() {

    // No idlist filtering, don't filter.
    if (empty($this->idList)) {
      return TRUE;
    }

    // Some source plugins do not extend SourcePluginBase. These cannot be
    // filtered so warn and return all values.
    if (!$this
      ->getInnerIterator() instanceof SourcePluginBase) {
      trigger_error(sprintf('The source plugin %s is not an instance of %s. Extend from %s to support idlist filtering.', $this
        ->getInnerIterator()
        ->getPluginId(), SourcePluginBase::class, SourcePluginBase::class));
      return TRUE;
    }

    // Row is included.
    if (in_array(array_values($this
      ->getInnerIterator()
      ->getCurrentIds()), $this->idList)) {
      return TRUE;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SourceFilter::$idList protected property List of specific source IDs to import.
SourceFilter::accept public function
SourceFilter::__construct public function SourceFilter constructor.