rdf_preprocess_user

rdf_preprocess_user(&$variables)

Implements hook_preprocess_HOOK() for user templates.

File

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

Code

function rdf_preprocess_user(&$variables) {
  /** @var $account \Drupal\user\UserInterface */
  $account = $variables['elements']['#user'];
  $uri = $account->urlInfo();
  $mapping = rdf_get_mapping('user', 'user');
  $bundle_mapping = $mapping->getPreparedBundleMapping();

  // Adds RDFa markup to the user profile page. Fields displayed in this page
  // will automatically describe the user.
  if (!empty($bundle_mapping['types'])) {
    $variables['attributes']['typeof'] = $bundle_mapping['types'];
    $variables['attributes']['about'] = $account->url();
  }
  // If we are on the user account page, add the relationship between the
  // sioc:UserAccount and the foaf:Person who holds the account.
  if (\Drupal::routeMatch()->getRouteName() == $uri->getRouteName()) {
    // Adds the markup for username as language neutral literal, see
    // rdf_preprocess_username().
    $name_mapping = $mapping->getPreparedFieldMapping('name');
    if (!empty($name_mapping['properties'])) {
      $username_meta = array(
        '#tag' => 'meta',
        '#attributes' => array(
          'about' => $account->url(),
          'property' => $name_mapping['properties'],
          'content' => $account->getDisplayName(),
          'lang' => '',
        ),
      );
      $variables['#attached']['html_head'][] = [$username_meta, 'rdf_user_username'];
    }
  }
}
doc_Drupal
2016-10-29 09:36:33
Comments
Leave a Comment

Please login to continue.