rdf_preprocess_username(&$variables)
Implements hook_preprocess_HOOK() for username.html.twig.
File
- core/modules/rdf/rdf.module, line 397
- Enables semantically enriched output for Drupal sites in the form of RDFa.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | function rdf_preprocess_username(& $variables ) { // Because lang is set on the HTML element that wraps the page, the // username inherits this language attribute. However, since the username // might not be transliterated to the same language that the content is in, // we do not want it to inherit the language attribute, so we set the // attribute to an empty string. if ( empty ( $variables [ 'attributes' ][ 'lang' ])) { $variables [ 'attributes' ][ 'lang' ] = '' ; } // The profile URI is used to identify the user account. The about attribute // is used to set the URI as the default subject of the properties embedded // as RDFa in the child elements. Even if the user profile is not accessible // to the current user, we use its URI in order to identify the user in RDF. // We do not use this attribute for the anonymous user because we do not have // 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' ]]); } // Add RDF type of user. $mapping = rdf_get_mapping( 'user' , 'user' ); $bundle_mapping = $mapping ->getPreparedBundleMapping(); if (! empty ( $bundle_mapping [ 'types' ])) { $variables [ 'attributes' ][ 'typeof' ] = $bundle_mapping [ 'types' ]; } // Annotate the username in RDFa. A property attribute is used with an empty // datatype attribute to ensure the username is parsed as a plain literal // in RDFa 1.0 and 1.1. $name_mapping = $mapping ->getPreparedFieldMapping( 'name' ); if (! empty ( $name_mapping )) { $variables [ 'attributes' ][ 'property' ] = $name_mapping [ 'properties' ]; $variables [ 'attributes' ][ 'datatype' ] = '' ; } // Add the homepage RDFa markup if present. $homepage_mapping = $mapping ->getPreparedFieldMapping( 'homepage' ); if (! empty ( $variables [ 'homepage' ]) && ! empty ( $homepage_mapping )) { $variables [ 'attributes' ][ 'rel' ] = $homepage_mapping [ 'properties' ]; } // Long usernames are truncated by template_preprocess_username(). Store the // full name in the content attribute so it can be extracted in RDFa. if ( $variables [ 'truncated' ]) { $variables [ 'attributes' ][ 'content' ] = $variables [ 'name_raw' ]; } } |
Please login to continue.