diff --git a/core/includes/common.inc b/core/includes/common.inc index 3852870..b389530 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3482,6 +3482,13 @@ function drupal_pre_render_html_tag($element) { function drupal_pre_render_link($element) { // By default, link options to pass to l() are normally set in #options. $element += array('#options' => array()); + + // The title might be a render array. Render it to pass a string to l(). + if (is_array($element['#title'])) { + $element['#title'] = drupal_render($element['#title']); + $element['#options']['html'] = TRUE; + } + // However, within the scope of renderable elements, #attributes is a valid // way to specify attributes, too. Take them into account, but do not override // attributes from #options. diff --git a/core/modules/email/lib/Drupal/email/Plugin/field/formatter/MailToFormatter.php b/core/modules/email/lib/Drupal/email/Plugin/field/formatter/MailToFormatter.php index 33e5920..d9935fb 100644 --- a/core/modules/email/lib/Drupal/email/Plugin/field/formatter/MailToFormatter.php +++ b/core/modules/email/lib/Drupal/email/Plugin/field/formatter/MailToFormatter.php @@ -33,9 +33,16 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { $elements = array(); foreach ($items as $delta => $item) { + $title = array( + '#theme' => 'html_data_wrapper', + '#attributes' => $item['html_data_attributes'], + 'children' => array( + '#markup' => $item['value'], + ), + ); $elements[$delta] = array( '#type' => 'link', - '#title' => $item['value'], + '#title' => $title, '#href' => 'mailto:' . $item['value'], ); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php index fa780a5..ab01ade 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php @@ -120,7 +120,9 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function prepareView(array $entities, $langcode, array &$items) { } + public function prepareView(array $entities, $langcode, array &$items) { + \Drupal::moduleHandler()->invokeAll('formatter_prepare_view', array($entities, $langcode, &$items, $this->fieldDefinition)); + } /** * Returns whether the currently logged in user has access to the field. diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php index ccf28d3..9c72459 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php @@ -18,6 +18,8 @@ * {@inheritdoc} */ public function prepareView(array $entities, $langcode, array &$items) { + parent::prepareView($entities, $langcode, $items); + // Remove files specified to not be displayed. $fids = array(); foreach ($entities as $id => $entity) { diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 3c03d80..8887a24 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -221,6 +221,33 @@ function rdf_theme() { } /** + * Implements hook_formatter_prepare_view(). + */ +function rdf_formatter_prepare_view($entities, $langcode, &$items, $field_definition) { + // Get the field mapping for this field. + $field = $field_definition['field']; + $field_name = $field->getFieldName(); + $mapping = rdf_get_mapping($field_definition['entity_type'], $field_definition['bundle']); + $field_mapping = $mapping->getPreparedFieldMapping($field_name); + + // Attach the prepared RDF attributes to the item. These attributes will be + // placed in the field formatter. + foreach ($items as $entity_id => &$item_list) { + $entity = $entities[$entity_id]; + $uri_info = $entities[$entity_id]->uri(); + foreach ($item_list as $delta => &$item) { + $value = $entity->get($field_name)->offsetGet($delta)->getValue(); + $item['html_data_attributes'] = rdf_rdfa_attributes($field_mapping, $value); + // Add an about attribute to create the relationship between the field + // and its entity. This ensures that data is properly exposed when using + // layout tools like Views and that other changes to the formatter do not + // impact the data (for example, wrapping the field in a link). + $item['html_data_attributes']['about'] = url($uri_info['path']); + } + } +} + +/** * Implements hook_preprocess_HOOK() for html.tpl.php. */ function rdf_preprocess_html(&$variables) { @@ -324,37 +351,6 @@ function rdf_preprocess_node(&$variables) { } /** - * Implements hook_preprocess_HOOK() for field.tpl.php. - */ -function rdf_preprocess_field(&$variables) { - $element = $variables['element']; - $entity_type = $element['#entity_type']; - $bundle = $element['#bundle']; - $field_name = $element['#field_name']; - $field_mapping = rdf_get_mapping($entity_type, $bundle) - ->getPreparedFieldMapping($field_name); - - if (!empty($field_mapping)) { - foreach ($element['#items'] as $delta => $item) { - $variables['item_attributes'][$delta] = rdf_rdfa_attributes($field_mapping, $item); - // If this field is an image, RDFa will not output correctly when the - // image is in a containing tag. If the field is a file, RDFa will - // not output correctly if the filetype icon comes before the link to the - // file. We correct this by adding a resource attribute to the div if - // this field has a URI. - if (isset($item['entity']->uri)) { - if (!empty($element[$delta]['#image_style'])) { - $variables['item_attributes'][$delta]['resource'] = image_style_url($element[$delta]['#image_style'], $item['entity']->getFileUri()); - } - else { - $variables['item_attributes'][$delta]['resource'] = file_create_url($item['entity']->getFileUri()); - } - } - } - } -} - -/** * Implements hook_preprocess_HOOK() for user.tpl.php. */ function rdf_preprocess_user(&$variables) { @@ -559,38 +555,6 @@ function rdf_preprocess_taxonomy_term(&$variables) { } /** - * Implements hook_field_attach_view_alter(). - */ -function rdf_field_attach_view_alter(&$output, $context) { - // Append term mappings on displayed taxonomy links. - foreach (element_children($output) as $field_name) { - $element = &$output[$field_name]; - if ($element['#field_type'] == 'taxonomy_term_reference' && $element['#formatter'] == 'taxonomy_term_reference_link') { - foreach ($element['#items'] as $delta => $item) { - // This function is invoked during entity preview when taxonomy term - // reference items might contain free-tagging terms that do not exist - // yet and thus have no $item['entity']. - if (isset($item['entity'])) { - $term = $item['entity']; - $mapping = rdf_get_mapping('taxonomy_term', $term->bundle()); - $bundle_mapping = $mapping->getPreparedBundleMapping(); - if (!empty($bundle_mapping['types'])) { - $element[$delta]['#options']['attributes']['typeof'] = $bundle_mapping['types']; - } - $name_field_mapping = $mapping->getPreparedFieldMapping('name'); - if (!empty($name_field_mapping['properties'])) { - // A property attribute is used with an empty datatype attribute so - // the term name is parsed as a plain literal in RDFa 1.0 and 1.1. - $element[$delta]['#options']['attributes']['property'] = $name_field_mapping['properties']; - $element[$delta]['#options']['attributes']['datatype'] = ''; - } - } - } - } - } -} - -/** * Implements hook_preprocess_HOOK() for theme_image(). */ function rdf_preprocess_image(&$variables) { diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextPlainFormatter.php b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextPlainFormatter.php index 813bb92..7971f64 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextPlainFormatter.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextPlainFormatter.php @@ -40,7 +40,13 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { foreach ($items as $delta => $item) { // The text value has no text format assigned to it, so the user input // should equal the output, including newlines. - $elements[$delta] = array('#markup' => nl2br(check_plain($item['value']))); + $elements[$delta] = array( + '#theme' => 'html_data_wrapper', + '#attributes' => $item['html_data_attributes'], + 'children' => array( + '#markup' => nl2br(check_plain($item['value'])), + ), + ); } return $elements;