You are here

public function FollowTaxonomyActivityContext::isValidEntity in Open Social 10.3.x

Same name and namespace in other branches
  1. 10.0.x modules/social_features/social_follow_taxonomy/src/Plugin/ActivityContext/FollowTaxonomyActivityContext.php \Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext::isValidEntity()
  2. 10.1.x modules/social_features/social_follow_taxonomy/src/Plugin/ActivityContext/FollowTaxonomyActivityContext.php \Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext::isValidEntity()
  3. 10.2.x modules/social_features/social_follow_taxonomy/src/Plugin/ActivityContext/FollowTaxonomyActivityContext.php \Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext::isValidEntity()

Determines if the entity is valid for this context.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object.

Return value

bool TRUE if it's valid entity.

Overrides ActivityContextBase::isValidEntity

File

modules/social_features/social_follow_taxonomy/src/Plugin/ActivityContext/FollowTaxonomyActivityContext.php, line 204

Class

FollowTaxonomyActivityContext
Provides a 'FollowTaxonomyActivityContext' activity context plugin.

Namespace

Drupal\social_follow_taxonomy\Plugin\ActivityContext

Code

public function isValidEntity(EntityInterface $entity) {
  if (!$entity instanceof ContentEntityInterface) {
    return FALSE;
  }

  // Check entity type.
  switch ($entity
    ->getEntityTypeId()) {
    case 'node':
    case 'post':
      foreach ($this
        ->getListOfTagsFields() as $field_name) {
        if ($entity
          ->hasField($field_name) && !$entity
          ->get($field_name)
          ->isEmpty()) {
          return TRUE;
        }
      }
      return FALSE;
  }
  return FALSE;
}