Mercurial > hg > isophonics-drupal-site
diff core/modules/rdf/rdf.module @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 129ea1e6d783 |
children |
line wrap: on
line diff
--- a/core/modules/rdf/rdf.module Thu Feb 28 13:21:36 2019 +0000 +++ b/core/modules/rdf/rdf.module Thu May 09 15:33:08 2019 +0100 @@ -5,6 +5,7 @@ * Enables semantically enriched output for Drupal sites in the form of RDFa. */ +use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Template\Attribute; use Drupal\rdf\Entity\RdfMapping; @@ -241,7 +242,7 @@ // bubbleable metadata, because it can be outside of a render context. $comment->rdf_data['entity_uri'] = $entity->toUrl()->toString(TRUE)->getGeneratedUrl(); if ($comment->hasParentComment()) { - $comment->rdf_data['pid_uri'] = $comment->getParentComment()->url(); + $comment->rdf_data['pid_uri'] = $comment->getParentComment()->toUrl()->toString(); } } } @@ -323,13 +324,30 @@ // Adds RDFa markup for the date. $created_mapping = $mapping->getPreparedFieldMapping('created'); - if (!empty($created_mapping) && $variables['display_submitted']) { + if (!empty($created_mapping)) { $date_attributes = rdf_rdfa_attributes($created_mapping, $variables['node']->get('created')->first()->toArray()); $rdf_metadata = [ '#theme' => 'rdf_metadata', '#metadata' => [$date_attributes], ]; - $variables['metadata'] = \Drupal::service('renderer')->render($rdf_metadata); + + // Depending on whether custom preprocessing is enabled, the 'created' + // field may appear in either of two different places, so check both of + // those places here. + // @see template_preprocess_node. + if (!empty($variables['display_submitted'])) { + // If custom preprocessing is enabled, then detect if the 'created' + // field is displayed by checking the 'display_submitted' variable. In + // this case, for back-compatibility, put the metadata into a special + // variable. + $variables['metadata'] = \Drupal::service('renderer')->render($rdf_metadata); + } + elseif (isset($variables['elements']['created'])) { + // Otherwise, detect if the 'created' field is displayed by checking if + // it is present in the 'elements variable. Put the metadata into + // title_suffix, along with other metadata added by this module. + $variables['title_suffix']['rdf_meta_created'] = $rdf_metadata; + } } // Adds RDFa markup annotating the number of comments a node has. @@ -360,7 +378,7 @@ function rdf_preprocess_user(&$variables) { /** @var $account \Drupal\user\UserInterface */ $account = $variables['elements']['#user']; - $uri = $account->urlInfo(); + $uri = $account->toUrl(); $mapping = rdf_get_mapping('user', 'user'); $bundle_mapping = $mapping->getPreparedBundleMapping(); @@ -368,7 +386,7 @@ // will automatically describe the user. if (!empty($bundle_mapping['types'])) { $variables['attributes']['typeof'] = $bundle_mapping['types']; - $variables['attributes']['about'] = $account->url(); + $variables['attributes']['about'] = $account->toUrl()->toString(); } // If we are on the user account page, add the relationship between the // sioc:UserAccount and the foaf:Person who holds the account. @@ -380,7 +398,7 @@ $username_meta = [ '#tag' => 'meta', '#attributes' => [ - 'about' => $account->url(), + 'about' => $account->toUrl()->toString(), 'property' => $name_mapping['properties'], 'content' => $account->getDisplayName(), 'lang' => '', @@ -412,7 +430,7 @@ // a user profile URI for it (only a homepage which cannot be used as user // profile in RDF.) if ($variables['uid'] > 0) { - $variables['attributes']['about'] = \Drupal::url('entity.user.canonical', ['user' => $variables['uid']]); + $variables['attributes']['about'] = Url::fromRoute('entity.user.canonical', ['user' => $variables['uid']])->toString(); } // Add RDF type of user. @@ -454,7 +472,7 @@ // the URI of the resource described within the HTML element, while the // typeof attribute indicates its RDF type (e.g., sioc:Post, foaf:Document, // and so on.) - $variables['attributes']['about'] = $comment->url(); + $variables['attributes']['about'] = $comment->toUrl()->toString(); $variables['attributes']['typeof'] = $bundle_mapping['types']; } @@ -549,7 +567,7 @@ $term = $variables['term']; $mapping = rdf_get_mapping('taxonomy_term', $term->bundle()); $bundle_mapping = $mapping->getPreparedBundleMapping(); - $variables['attributes']['about'] = $term->url(); + $variables['attributes']['about'] = $term->toUrl()->toString(); $variables['attributes']['typeof'] = empty($bundle_mapping['types']) ? NULL : $bundle_mapping['types']; // Add RDFa markup for the taxonomy term name as metadata, if present.