Get the url to export (see portfolios) a post.

@param post_entity $post The post
@return moodle_url
191784
public function get_export_post_url_from_post(post_entity $post) : ?moodle_url {
        global $CFG;

        require_once($CFG->libdir . '/portfoliolib.php');
        $button = new \portfolio_add_button();
        $button->set_callback_options('forum_portfolio_caller', ['postid' => $post->get_id()], 'mod_forum');
        if ($post->has_attachments()) {
            $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
        } else {
            $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
        }

        $url = $button->to_html(PORTFOLIO_ADD_MOODLE_URL);
        return $url ?: null;
    }
574017
public static function get_post_twitter_image( $post ) {
		$image = get_post_meta( $post->ID, '_yoast_wpseo_twitter-image', true );

		if ( empty( $image ) ) {
			$image = self::get_fallback_image( $post );
		}

		return $image;
	}
376391
public function get_view_isolated_post_url_from_post_id(int $discussionid, int $postid) : moodle_url {
        $url = $this->get_discussion_view_url_from_discussion_id($discussionid);
        $url->params(['parent' => $postid]);
        return $url;
    }
392106
public function generatePermalink($object = null)
    {
        $manager = $this->getContainer()->get('compo_articles.manager.articles');

        if ($object) {
            return $manager->getArticleShowPermalink($object);
        }

        return $manager->getArticlesIndexPermalink();
    }
1016431
public function get_pin_discussion_url_from_discussion(discussion_entity $discussion) : moodle_url {
        return new moodle_url('discuss.php', [
            'sesskey' => sesskey(),
            'd' => $discussion->get_id(),
            'pin' => $discussion->is_pinned() ? FORUM_DISCUSSION_UNPINNED : FORUM_DISCUSSION_PINNED
        ]);
    }
1077119
public function convertPostContent($post) {
		$content = $post->Content;
		
		$lines = explode("\n", $content);
		
		$newContent = array();
		$title = '';
		$converted = false;
		
		// store the converted items
		$convertedLinks = array();
		
		foreach ($lines as $line) {
			$url = trim($line);
			if (strlen($url) && $this->isWebpage($url)) {
				$convertedContent = $this->convertUrl($url);
				if ($convertedContent) {
					$converted = true;
					$line = 'CONVERTEDCONTENT:' . count($convertedLinks);
					$convertedLinks[] = $convertedContent;
					$title = strlen($convertedContent['Title']) ? $convertedContent['Title'] : '';
				}
			} 
			$newContent[] = $line;
		}

		$newContent = implode("\n", $newContent);
		$newContent = RestrictedMarkdown::create($newContent)->parse();
		
		// replace the converted bits
		$newContent = preg_replace_callback('/CONVERTEDCONTENT:(\d+)/is', function ($bit) use ($convertedLinks) {
			return isset($convertedLinks[$bit[1]]) ? $convertedLinks[$bit[1]]['Content'] : '';
		}, $newContent);
		
		if ($converted) {
			$post->IsOembed = true;
			$post->OriginalContent = $post->Content;
			$post->Content = $newContent;
			$post->Title = $title;
		}

		return $post;
	}
1049626
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;
  }
404962
public function get_url() {
        $params = array('id' => $this->contextinstanceid);
        if (!empty($this->other['mode'])) {
            $params['mode'] = $this->other['mode'];
        }
        return new \moodle_url("/mod/$this->objecttable/view.php", $params);
    }
562114
public function get_doc_url(\core_search\document $doc) {
        $entry = $this->get_entry($doc->get('itemid'));
        return new \moodle_url('/mod/data/view.php', array( 'd' => $entry->dataid, 'rid' => $entry->id ));
    }
981167
protected function prepare_links( $post ) {
		$base = sprintf( '%s/%s', $this->namespace, $this->rest_base );

		// Entity meta.
		$links = array(
			'self' => array(
				'href'   => rest_url( trailingslashit( $base ) . $post->ID ),
			),
			'collection' => array(
				'href'   => rest_url( $base ),
			),
			'about'      => array(
				'href'   => rest_url( 'wp/v2/types/' . $this->post_type ),
			),
		);

		if ( ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'author' ) )
			&& ! empty( $post->post_author ) ) {
			$links['author'] = array(
				'href'       => rest_url( 'wp/v2/users/' . $post->post_author ),
				'embeddable' => true,
			);
		}

		if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'comments' ) ) {
			$replies_url = rest_url( 'wp/v2/comments' );
			$replies_url = add_query_arg( 'post', $post->ID, $replies_url );
			$links['replies'] = array(
				'href'         => $replies_url,
				'embeddable'   => true,
			);
		}

		if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) {
			$links['version-history'] = array(
				'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ),
			);
		}
		$post_type_obj = get_post_type_object( $post->post_type );
		if ( $post_type_obj->hierarchical && ! empty( $post->post_parent ) ) {
			$links['up'] = array(
				'href'       => rest_url( trailingslashit( $base ) . (int) $post->post_parent ),
				'embeddable' => true,
			);
		}

		// If we have a featured media, add that.
		if ( $featured_media = get_post_thumbnail_id( $post->ID ) ) {
			$image_url = rest_url( 'wp/v2/media/' . $featured_media );
			$links['https://api.w.org/featuredmedia'] = array(
				'href'       => $image_url,
				'embeddable' => true,
			);
		}
		if ( ! in_array( $post->post_type, array( 'attachment', 'nav_menu_item', 'revision' ), true ) ) {
			$attachments_url = rest_url( 'wp/v2/media' );
			$attachments_url = add_query_arg( 'parent', $post->ID, $attachments_url );
			$links['https://api.w.org/attachment'] = array(
				'href'       => $attachments_url,
			);
		}

		$taxonomies = get_object_taxonomies( $post->post_type );
		if ( ! empty( $taxonomies ) ) {
			$links['https://api.w.org/term'] = array();

			foreach ( $taxonomies as $tax ) {
				$taxonomy_obj = get_taxonomy( $tax );
				// Skip taxonomies that are not public.
				if ( empty( $taxonomy_obj->show_in_rest ) ) {
					continue;
				}

				$tax_base = ! empty( $taxonomy_obj->rest_base ) ? $taxonomy_obj->rest_base : $tax;
				$terms_url = add_query_arg(
					'post',
					$post->ID,
					rest_url( 'wp/v2/' . $tax_base )
				);

				$links['https://api.w.org/term'][] = array(
					'href'       => $terms_url,
					'taxonomy'   => $tax,
					'embeddable' => true,
				);
			}
		}

		return $links;
	}
1211098
function pathObjectUrl($entity, $type = LinkGeneratorService::TYPE_LINK_DEFAULT, array $parameters = array()) {
        if($entity === null){
            return "";
        }
        return $this->linkGeneratorService->generateOnlyUrl($entity, $type, $parameters);
    }
1282384
public static function get( $post ) {
		$post = is_a( $post, 'WP_Post' ) ? $post : get_post( $post );
		$type = $post->post_type;
		if ( 'page' === $type ) {
			$template_slug = get_page_template_slug( $post->ID );
			if ( ! empty( $template_slug ) ) {
				$type .= '-' . wp_basename( $template_slug, '.php' );
			}
		}
		return $type;
	}
45277
private static function get_fallback_image( $post ) {
		$image = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );

		if ( empty( $image ) ) {
			$logo = Acf::get_option_field( SiteIdentity::LOGO_KEY );
			$image = is_array( $logo ) ? $logo['src'] : get_site_icon_url();
		}

		return $image;
	}
1177979
public function render_forum_post_email(\mod_forum\output\forum_post_email $post) {
        $data = $post->export_for_template($this, $this->target === RENDERER_TARGET_TEXTEMAIL);
        return $this->render_from_template('mod_forum/' . $this->forum_post_template(), $data);
    }
652062
public function getPermalinkAfter($postId, $post)
    {
        if (wp_is_post_revision($postId)) {
            return;
        }

        remove_action('save_post', array($this, 'getPermalinkAfter'), 10, 2);

        $this->permalinkAfter = get_permalink($this->postId);

        if ($post->post_status === 'trash') {
            $this->trashed = true;
        }

        if ($this->permalinkBefore && !empty($this->permalinkBefore)) {
            $this->detectChangedPermalink();
        }
    }
453842
public function findByPost(Post $post)
    {
        return $this->createQueryBuilder('t')
            ->innerJoin('t.posts', 'p')
            ->where('p.id = :postId')
            ->setParameter('postId', $post->getId())
            ->getQuery()->getResult();
    }
495181
public function can_export_post(stdClass $user, post_entity $post) : bool {
        global $CFG;
        $context = $this->get_context();
        return $CFG->enableportfolios  && (has_capability('mod/forum:exportpost', $context, $user) ||
            ($post->is_owned_by_user($user) && has_capability('mod/forum:exportownpost', $context, $user)));
    }