You are here

public function EntityTypeFilter::filter in Replication 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/ReplicationFilter/EntityTypeFilter.php \Drupal\replication\Plugin\ReplicationFilter\EntityTypeFilter::filter()

Filter the given entity.

Parameters

EntityInterface $entity: The entity to filter.

Return value

bool Return TRUE if it should be included, else FALSE.

Overrides ReplicationFilterInterface::filter

File

src/Plugin/ReplicationFilter/EntityTypeFilter.php, line 34

Class

EntityTypeFilter
Provides a filter based on entity type.

Namespace

Drupal\replication\Plugin\ReplicationFilter

Code

public function filter(EntityInterface $entity) {
  $configuration = $this
    ->getConfiguration();
  $types = $configuration['types'];
  foreach ($types as $type) {

    // Handle cases like "node.".
    $type = trim($type, '.');
    $split = explode('.', $type);
    $entity_type_id = $split[0];
    $bundle = isset($split[1]) ? $split[1] : NULL;

    // Filter for only the entity type id.
    if ($bundle == NULL && $entity
      ->getEntityTypeId() == $entity_type_id) {
      return TRUE;
    }

    // Filter for both the entity type id and bundle.
    if ($entity
      ->getEntityTypeId() == $entity_type_id && $entity
      ->bundle() == $bundle) {
      return TRUE;
    }
  }
  return FALSE;
}