You are here

function rdf_comment_storage_load in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rdf/rdf.module \rdf_comment_storage_load()
  2. 9 core/modules/rdf/rdf.module \rdf_comment_storage_load()

Implements hook_ENTITY_TYPE_storage_load() for comment entities.

File

core/modules/rdf/rdf.module, line 234
Enables semantically enriched output for Drupal sites in the form of RDFa.

Code

function rdf_comment_storage_load($comments) {
  foreach ($comments as $comment) {

    // Pages with many comments can show poor performance. This information
    // isn't needed until rdf_preprocess_comment() is called, but set it here
    // to optimize performance for websites that implement an entity cache.
    $created_mapping = rdf_get_mapping('comment', $comment
      ->bundle())
      ->getPreparedFieldMapping('created');

    /** @var \Drupal\comment\CommentInterface $comment*/
    $comment->rdf_data['date'] = rdf_rdfa_attributes($created_mapping, $comment
      ->get('created')
      ->first()
      ->toArray());
    if ($entity = $comment
      ->getCommentedEntity()) {

      // The current function is a storage level hook, so avoid to bubble
      // bubbleable metadata, because it can be outside of a render context.
      $comment->rdf_data['entity_uri'] = $entity
        ->toUrl()
        ->toString(TRUE)
        ->getGeneratedUrl();
    }
    if ($parent = $comment
      ->getParentComment()) {
      $comment->rdf_data['pid_uri'] = $parent
        ->toUrl()
        ->toString(TRUE)
        ->getGeneratedUrl();
    }
  }
}