EntityTypeFilter.php in Replication 8.2
File
src/Plugin/ReplicationFilter/EntityTypeFilter.php
View source
<?php
namespace Drupal\replication\Plugin\ReplicationFilter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\replication\Plugin\ReplicationFilter\ReplicationFilterBase;
class EntityTypeFilter extends ReplicationFilterBase {
public function defaultConfiguration() {
return [
'types' => [],
];
}
public function filter(EntityInterface $entity) {
$configuration = $this
->getConfiguration();
$types = $configuration['types'];
foreach ($types as $type) {
$type = trim($type, '.');
$split = explode('.', $type);
$entity_type_id = $split[0];
$bundle = isset($split[1]) ? $split[1] : NULL;
if ($bundle == NULL && $entity
->getEntityTypeId() == $entity_type_id) {
return TRUE;
}
if ($entity
->getEntityTypeId() == $entity_type_id && $entity
->bundle() == $bundle) {
return TRUE;
}
}
return FALSE;
}
}