You are here

function rdf_preprocess_user in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/rdf/rdf.module \rdf_preprocess_user()

Implements hook_preprocess_HOOK() for user templates.

File

core/modules/rdf/rdf.module, line 356
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',
      ];
    }
  }
}