diff --git a/src/Plugin/ReplicationFilter/EntityTypeFilter.php b/src/Plugin/ReplicationFilter/EntityTypeFilter.php index 1be4820..ea105a4 100644 --- a/src/Plugin/ReplicationFilter/EntityTypeFilter.php +++ b/src/Plugin/ReplicationFilter/EntityTypeFilter.php @@ -8,9 +8,8 @@ use Drupal\replication\Plugin\ReplicationFilter\ReplicationFilterBase; /** * Provides a filter based on entity type. * - * Use the configuration "types" with values in the format - * "{entity_type_id}.{bundle}", for example, "node.article". This can also be a - * comma delimited list like "node.article,node.page". + * Use the configuration "types" which is an array of values in the format + * "{entity_type_id}.{bundle}". * * @ReplicationFilter( * id = "entity_type", @@ -23,12 +22,18 @@ class EntityTypeFilter extends ReplicationFilterBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return [ + 'types' => [], + ]; + } + + /** + * {@inheritdoc} + */ public function filter(EntityInterface $entity) { $configuration = $this->getConfiguration(); - $types = isset($configuration['types']) ? $configuration['types'] : ''; - $types = str_replace(' ', '', $types); - $types = explode(',', $types); - $types = array_filter($types); + $types = $configuration['types']; foreach ($types as $type) { // Handle cases like "node.". diff --git a/src/Plugin/ReplicationFilter/PublishedFilter.php b/src/Plugin/ReplicationFilter/PublishedFilter.php index b637da3..a049fb1 100644 --- a/src/Plugin/ReplicationFilter/PublishedFilter.php +++ b/src/Plugin/ReplicationFilter/PublishedFilter.php @@ -11,10 +11,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a filter for published entities. * - * Use the configuration "include_unpublisheable_entities" to determine what + * Use the configuration "include_unpublishable_entities" to determine what * happens to entities that do not have a "status" field, if set to TRUE they * will be included by the filter, else excluded. - * with values in the format * * @ReplicationFilter( * id = "published", @@ -25,8 +24,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class PublishedFilter extends ReplicationFilterBase implements ContainerFactoryPluginInterface { /** + * The entity type manager to check for "status" entity key. + * * @var \Drupal\Core\Entity\EntityTypeManagerInterface - * The entity type manager to check for "status" entity key. */ protected $entityTypeManager; @@ -59,7 +59,7 @@ class PublishedFilter extends ReplicationFilterBase implements ContainerFactoryP */ public function defaultConfiguration() { return [ - 'include_unpublisheable_entities' => FALSE, + 'include_unpublishable_entities' => FALSE, ]; } @@ -78,7 +78,7 @@ class PublishedFilter extends ReplicationFilterBase implements ContainerFactoryP } // Determine what to do with entities without a 'status' field. $configuration = $this->getConfiguration(); - return $configuration['include_unpublisheable_entities']; + return $configuration['include_unpublishable_entities']; } } diff --git a/src/Plugin/ReplicationFilter/ReplicationFilterBase.php b/src/Plugin/ReplicationFilter/ReplicationFilterBase.php index bd82751..50c0b75 100644 --- a/src/Plugin/ReplicationFilter/ReplicationFilterBase.php +++ b/src/Plugin/ReplicationFilter/ReplicationFilterBase.php @@ -44,6 +44,9 @@ abstract class ReplicationFilterBase extends PluginBase implements ReplicationFi * passed as "query_params" to a CouchDB filter function. */ public function getConfiguration() { + if ($this->configuration == NULL) { + return $this->defaultConfiguration(); + } return $this->configuration; } @@ -57,13 +60,6 @@ abstract class ReplicationFilterBase extends PluginBase implements ReplicationFi /** * {@inheritdoc} */ - public function defaultConfiguration() { - return array(); - } - - /** - * {@inheritdoc} - */ public function calculateDependencies() { return array(); } diff --git a/src/Plugin/ReplicationFilter/UuidFilter.php b/src/Plugin/ReplicationFilter/UuidFilter.php index 47d841f..c7bd4ae 100644 --- a/src/Plugin/ReplicationFilter/UuidFilter.php +++ b/src/Plugin/ReplicationFilter/UuidFilter.php @@ -8,7 +8,7 @@ use Drupal\replication\Plugin\ReplicationFilter\ReplicationFilterBase; /** * Provides filtering by UUID. * - * Use the configuration "uuids" with comma delimited values, e.g. "101,102". + * Use the configuration "uuids" which is an array of uuids, e.g. "101,102". * * Note: if the entity a UUID refers to references another entity, that * referenced entity's UUID must also be included in order to maintain data @@ -25,12 +25,18 @@ class UuidFilter extends ReplicationFilterBase { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return [ + 'uuids' => [], + ]; + } + + /** + * {@inheritdoc} + */ public function filter(EntityInterface $entity) { $configuration = $this->getConfiguration(); - $uuids = isset($configuration['uuids']) ? $configuration['uuids'] : ''; - $uuids = explode(',', $uuids); - $uuids = array_map('trim', $uuids); - return in_array($entity->uuid(), $uuids); + return in_array($entity->uuid(), $configuration['uuids']); } } diff --git a/tests/src/Functional/ReplicationFilterTest.php b/tests/src/Functional/ReplicationFilterTest.php index 08dd3ee..ed11241 100644 --- a/tests/src/Functional/ReplicationFilterTest.php +++ b/tests/src/Functional/ReplicationFilterTest.php @@ -77,7 +77,7 @@ class ReplicationFilterTest extends WebTestBase { $parameters = ['uuids' => $entity1->uuid()]; $changes = $changes_factory->get($workspace)->filter('uuid')->parameters($parameters)->getNormal(); - $this->assertEqual(1, count($changes), 'Expect there is 1 entity in the changeset.'); + $this->assertEqual(1, count($changes), 'Expect there is 1 entity in the changeset for UUIDs filter.'); } /** @@ -109,7 +109,7 @@ class ReplicationFilterTest extends WebTestBase { $entity2->save(); $changes = $changes_factory->get($workspace)->filter('published')->getNormal(); - $this->assertEqual(1, count($changes), 'Expect there is 1 entity in the changeset.'); + $this->assertEqual(1, count($changes), 'Expect there is 1 entity in the changeset for published filter.'); } /** @@ -142,9 +142,9 @@ class ReplicationFilterTest extends WebTestBase { $entity2->workspace = $workspace; $entity2->save(); - $parameters = ['entity_type_id' => 'node', 'bundle' => 'article']; + $parameters = ['types' => 'node.article']; $changes = $changes_factory->get($workspace)->filter('entity_type')->parameters($parameters)->getNormal(); - $this->assertEqual(1, count($changes), 'Expect there is 1 entity in the changeset.'); + $this->assertEqual(1, count($changes), 'Expect there is 1 entity in the changeset for entity type filter.'); } } diff --git a/tests/src/Kernel/Plugin/ReplicationFilter/PublishedFilterTest.php b/tests/src/Kernel/Plugin/ReplicationFilter/PublishedFilterTest.php index 944da25..cf1b718 100644 --- a/tests/src/Kernel/Plugin/ReplicationFilter/PublishedFilterTest.php +++ b/tests/src/Kernel/Plugin/ReplicationFilter/PublishedFilterTest.php @@ -1,11 +1,9 @@ container->get('plugin.manager.replication_filter'); $configuration = [ - 'include_unpublisheable_entities' => $include_unpublisheable_entities, + 'include_unpublishable_entities' => $include_unpublishable_entities, ]; $filter = $filter_manager->createInstance('published', $configuration); - $entity = call_user_func($entity_class . '::create', $entity_values); + $entity = $this->container + ->get('entity_type.manager') + ->getStorage($entity_type_id) + ->create($entity_values); $value = $filter->filter($entity); - $this->assertEquals($expected, $value); + $this->assertSame($expected, $value); } /** * Test default configuration for published filter. */ - public function testDefaultConfig($include_unpublisheable_entities, $entity_class, $entity_values, $expected) { + public function testDefaultConfig() { /** @var \Drupal\replication\Plugin\ReplicationFilterManagerInterface $filter_manager */ $filter_manager = $this->container->get('plugin.manager.replication_filter'); $filter = $filter_manager->createInstance('published'); @@ -124,10 +125,10 @@ class PublishedFilterTest extends KernelTestBase { ]; return [ - [FALSE, Node::class, $published_node, TRUE], - [FALSE, Node::class, $unpublished_node, FALSE], - [TRUE, BlockContent::class, $block, TRUE], - [FALSE, BlockContent::class, $block, FALSE], + [FALSE, 'node', $published_node, TRUE], + [FALSE, 'node', $unpublished_node, FALSE], + [TRUE, 'block_content', $block, TRUE], + [FALSE, 'block_content', $block, FALSE], ]; }