BlockedIp.php in Drupal 8
File
core/modules/ban/src/Plugin/migrate/destination/BlockedIp.php
View source
<?php
namespace Drupal\ban\Plugin\migrate\destination;
use Drupal\ban\BanIpManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
class BlockedIp extends DestinationBase implements ContainerFactoryPluginInterface {
protected $banManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, BanIpManagerInterface $ban_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
$this->banManager = $ban_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $migration, $container
->get('ban.ip_manager'));
}
public function getIds() {
return [
'ip' => [
'type' => 'string',
],
];
}
public function fields(MigrationInterface $migration = NULL) {
return [
'ip' => $this
->t('The blocked IP address.'),
];
}
public function import(Row $row, array $old_destination_id_values = []) {
$this->banManager
->banIp($row
->getDestinationProperty('ip'));
}
}