You are here

public function Activity::getRelatedEntityUrl in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  2. 8.2 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  3. 8.3 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  4. 8.4 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  5. 8.5 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  6. 8.6 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  7. 8.7 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  8. 8.8 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  9. 10.3.x modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  10. 10.0.x modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  11. 10.1.x modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
  12. 10.2.x modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()

Get related entity url.

Return value

\Drupal\Core\Url|string Returns empty string or URL object of related entity canonical url.

Overrides ActivityInterface::getRelatedEntityUrl

File

modules/custom/activity_creator/src/Entity/Activity.php, line 201

Class

Activity
Defines the Activity entity.

Namespace

Drupal\activity_creator\Entity

Code

public function getRelatedEntityUrl() {
  $link = "";
  $related_object = $this
    ->get('field_activity_entity')
    ->getValue();
  if (!empty($related_object)) {
    $target_type = $related_object['0']['target_type'];
    $target_id = $related_object['0']['target_id'];

    // Make an exception for Votes.
    if ($target_type === 'vote') {

      /** @var \Drupal\votingapi\Entity\Vote $vote */
      if ($vote = entity_load($target_type, $target_id)) {
        $target_type = $vote
          ->getVotedEntityType();
        $target_id = $vote
          ->getVotedEntityId();
      }
    }
    elseif ($target_type === 'group_content') {

      /** @var \Drupal\group\Entity\GroupContent $group_content */
      if ($group_content = entity_load($target_type, $target_id)) {
        $target_type = $group_content
          ->getEntity()
          ->getEntityTypeId();
        $target_id = $group_content
          ->getEntity()
          ->id();
      }
    }
    $entity = entity_load($target_type, $target_id);
    if (!empty($entity)) {

      /** @var \Drupal\Core\Url $link */
      $link = $entity
        ->urlInfo('canonical');
    }
  }
  return $link;
}