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();
        }
      }
      elseif ($target_type === 'event_enrollment') {
        $entity_storage = \Drupal::entityTypeManager()
          ->getStorage($target_type);
        $entity = $entity_storage->load($target_id);

        // Lets make the Event node the target for Enrollments.
        if ($entity !== NULL) {
          /** @var \Drupal\social_event\Entity\EventEnrollment $entity */
          $event_id = $entity->getFieldValue('field_event', 'target_id');
          $target_id = $event_id;
          $target_type = 'node';
        }
      }
      elseif ($target_type === 'flagging') {
        $flagging = Flagging::load($target_id);
        $target_type = $flagging->getFlaggableType();
        $target_id = $flagging->getFlaggableId();
      }

      $entity_storage = \Drupal::entityTypeManager()
        ->getStorage($target_type);
      $entity = $entity_storage->load($target_id);
      if ($entity !== NULL) {
        /** @var \Drupal\Core\Url $link */
        $link = $entity->urlInfo('canonical');
      }
    }
    return $link;
  }
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();
        }
      }
      elseif ($target_type === 'event_enrollment') {
        $entity_storage = \Drupal::entityTypeManager()
          ->getStorage($target_type);
        $entity = $entity_storage->load($target_id);

        // Lets make the Event node the target for Enrollments.
        if ($entity !== NULL) {
          /** @var \Drupal\social_event\Entity\EventEnrollment $entity */
          $event_id = $entity->getFieldValue('field_event', 'target_id');
          $target_id = $event_id;
          $target_type = 'node';
        }
      }
      elseif ($target_type === 'flagging') {
        $flagging = Flagging::load($target_id);
        $target_type = $flagging->getFlaggableType();
        $target_id = $flagging->getFlaggableId();
      }

      $entity_storage = \Drupal::entityTypeManager()
        ->getStorage($target_type);
      $entity = $entity_storage->load($target_id);
      if ($entity !== NULL) {
        /** @var \Drupal\Core\Url $link */
        $link = $entity->urlInfo('canonical');
      }
    }
    return $link;
  }
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 ( ) ; } } elseif ( $ target_type === 'event_enrollment' ) { $ entity_storage = \ Drupal :: entityTypeManager ( ) -> getStorage ( $ target_type ) ; $ entity = $ entity_storage -> load ( $ target_id ) ; // Lets make the Event node the target for Enrollments. if ( $ entity !== NULL ) { /** @var \Drupal\social_event\Entity\EventEnrollment $entity */ $ event_id = $ entity -> getFieldValue ( 'field_event' , 'target_id' ) ; $ target_id = $ event_id ; $ target_type = 'node' ; } } elseif ( $ target_type === 'flagging' ) { $ flagging = Flagging :: load ( $ target_id ) ; $ target_type = $ flagging -> getFlaggableType ( ) ; $ target_id = $ flagging -> getFlaggableId ( ) ; } $ entity_storage = \ Drupal :: entityTypeManager ( ) -> getStorage ( $ target_type ) ; $ entity = $ entity_storage -> load ( $ target_id ) ; if ( $ entity !== NULL ) { /** @var \Drupal\Core\Url $link */ $ link = $ entity -> urlInfo ( 'canonical' ) ; } } return $ link ; }
Get related entity url.

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