diff --git a/src/Changes/Changes.php b/src/Changes/Changes.php index 98ae886..10217f4 100644 --- a/src/Changes/Changes.php +++ b/src/Changes/Changes.php @@ -118,15 +118,15 @@ class Changes implements ChangesInterface { ->getRange($this->lastSeq, NULL); // Setup filter plugin. - $parameters = ($this->parameters instanceof ParameterBag) ? $this->parameters : new ParameterBag(); + $parameters = ($this->parameters instanceof ParameterBag) ? $this->parameters->all() : []; $filter = NULL; if (is_string($this->filterName) && $this->filterName) { - $filter = $this->filterManager->createInstance($this->filterName, $parameters->all()); + $filter = $this->filterManager->createInstance($this->filterName, $parameters); } // If UUIDs are sent as a parameter, but no filter is set, automatically // select the "uuid" filter. - elseif ($parameters->has('uuids')) { - $filter = $this->filterManager->createInstance('uuid', $parameters->all()); + elseif (isset($parameters['uuids'])) { + $filter = $this->filterManager->createInstance('uuid', $parameters); } // Format the result array. diff --git a/src/Entity/ReplicationSettings.php b/src/Entity/ReplicationSettings.php index 5a03649..4d4ff0f 100644 --- a/src/Entity/ReplicationSettings.php +++ b/src/Entity/ReplicationSettings.php @@ -47,7 +47,7 @@ class ReplicationSettings extends ConfigEntityBase implements ReplicationSetting /** * The replication filter parameters. * - * @var string[string] + * @var array */ protected $parameters; diff --git a/src/Entity/ReplicationSettingsInterface.php b/src/Entity/ReplicationSettingsInterface.php index f046c9f..86defa4 100644 --- a/src/Entity/ReplicationSettingsInterface.php +++ b/src/Entity/ReplicationSettingsInterface.php @@ -19,7 +19,7 @@ interface ReplicationSettingsInterface extends ConfigEntityInterface { /** * Get the replication filter parameters. * - * @return string[string] + * @return array */ public function getParameters(); diff --git a/src/Plugin/ReplicationFilter/EntityTypeFilter.php b/src/Plugin/ReplicationFilter/EntityTypeFilter.php index 041847c..e1e945a 100644 --- a/src/Plugin/ReplicationFilter/EntityTypeFilter.php +++ b/src/Plugin/ReplicationFilter/EntityTypeFilter.php @@ -4,13 +4,14 @@ namespace Drupal\replication\Plugin\ReplicationFilter; use Drupal\Core\Entity\EntityInterface; use Drupal\replication\Plugin\ReplicationFilter\ReplicationFilterBase; +use Symfony\Component\Console\Exception\LogicException; /** * Provides a filter based on entity type. * * Supported configuration: - * entity_type_id: a comma delimited list of entity type id's to include - * bundle: a comma delimited list of bundles matching the type ids + * entity_type_id: a comma delimited list of entity type ID's to include + * bundle: a comma delimited list of bundles matching the type ID's * * @ReplicationFilter( * id = "entity_type", @@ -29,7 +30,7 @@ class EntityTypeFilter extends ReplicationFilterBase { // Ensure length of entity_type_ids and bundles are equal. if (count($entity_type_ids) != count($bundles)) { - return FALSE; + throw new LogicException('The entity_type_id and bundle filter parameters must have equal length.'); } $entity_type_id = $entity->getEntityTypeId(); diff --git a/src/Plugin/ReplicationFilter/PublishedFilter.php b/src/Plugin/ReplicationFilter/PublishedFilter.php index b20965a..d38b526 100644 --- a/src/Plugin/ReplicationFilter/PublishedFilter.php +++ b/src/Plugin/ReplicationFilter/PublishedFilter.php @@ -3,8 +3,9 @@ namespace Drupal\replication\Plugin\ReplicationFilter; use Drupal\Core\Entity\EntityInterface; -use Drupal\node\NodeInterface; use Drupal\replication\Plugin\ReplicationFilter\ReplicationFilterBase; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; /** * Provides a filter for published entities. @@ -17,16 +18,47 @@ use Drupal\replication\Plugin\ReplicationFilter\ReplicationFilterBase; * description = @Translation("Replicate only nodes that are published.") * ) */ -class PublishedFilter extends ReplicationFilterBase { +class PublishedFilter extends ReplicationFilterBase implements ContainerFactoryPluginInterface { + + /** + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + + /** + * Constructs a new PublishedFilter. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager')); + } /** * {@inheritdoc} */ public function filter(EntityInterface $entity) { - if (!$entity instanceof NodeInterface) { - return FALSE; + $definition = $this->entityTypeManager->getDefinition($entity->getEntityTypeId()); + if ($definition->get('status')) { + return $entity->status; } - return $entity->isPublished(); + // Assume all entities without 'status' are published. + return TRUE; } } diff --git a/tests/src/Unit/Plugin/ReplicationFilter/EntityTypeFilterTest.php b/tests/src/Unit/Plugin/ReplicationFilter/EntityTypeFilterTest.php index 124579c..3d4433d 100644 --- a/tests/src/Unit/Plugin/ReplicationFilter/EntityTypeFilterTest.php +++ b/tests/src/Unit/Plugin/ReplicationFilter/EntityTypeFilterTest.php @@ -17,7 +17,7 @@ class EntityTypeFilterTest extends \PHPUnit_Framework_TestCase { * Test filtering entity types. * * @param string $entity_type_id - * The entity type id filter parameter. + * The entity type ID filter parameter. * @param string $bundle * The bundle filter parameter. * @param string $expected