public function Activity::getRelatedEntityUrl in Open Social 8.9
Same name and namespace in other branches
- 8 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 8.2 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 8.3 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 8.4 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 8.5 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 8.6 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 8.7 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 8.8 modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 10.3.x modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 10.0.x modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 10.1.x modules/custom/activity_creator/src/Entity/Activity.php \Drupal\activity_creator\Entity\Activity::getRelatedEntityUrl()
- 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 222
Class
- Activity
- Defines the Activity entity.
Namespace
Drupal\activity_creator\EntityCode
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;
}