You are here

public function CommunityActivityContext::isValidEntity in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  2. 8 modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  3. 8.2 modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  4. 8.3 modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  5. 8.4 modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  6. 8.5 modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  7. 8.6 modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  8. 8.8 modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  9. 10.3.x modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  10. 10.0.x modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  11. 10.1.x modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::isValidEntity()
  12. 10.2.x modules/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\CommunityActivityContext::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/custom/activity_basics/src/Plugin/ActivityContext/CommunityActivityContext.php, line 31

Class

CommunityActivityContext
Provides a 'CommunityActivityContext' activity context.

Namespace

Drupal\activity_basics\Plugin\ActivityContext

Code

public function isValidEntity(EntityInterface $entity) {

  // Special cases for comments.
  if ($entity
    ->getEntityTypeId() === 'comment') {

    // Returns the entity to which the comment is attached.
    $entity = $entity
      ->getCommentedEntity();
  }
  if (!isset($entity)) {
    return FALSE;
  }

  // Check if it's placed in a group (regardless off content type).
  if (GroupContent::loadByEntity($entity)) {
    return FALSE;
  }
  if ($entity
    ->getEntityTypeId() === 'post') {
    if (!$entity->field_recipient_group
      ->isEmpty()) {
      return FALSE;
    }
    elseif (!$entity->field_recipient_user
      ->isEmpty()) {
      return FALSE;
    }
  }
  return TRUE;
}