function rdf_preprocess_user

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

Implements hook_preprocess_HOOK() for user templates.

File

core/modules/rdf/rdf.module, line 379

Code

function rdf_preprocess_user(&$variables) {
    
    /** @var $account \Drupal\user\UserInterface */
    $account = $variables['elements']['#user'];
    $uri = $account->toUrl();
    $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->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.
    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 = [
                '#tag' => 'meta',
                '#attributes' => [
                    'about' => $account->toUrl()
                        ->toString(),
                    'property' => $name_mapping['properties'],
                    'content' => $account->getDisplayName(),
                    'lang' => '',
                ],
            ];
            $variables['#attached']['html_head'][] = [
                $username_meta,
                'rdf_user_username',
            ];
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.