Commit 63d299d9 authored by catch's avatar catch
Browse files

Issue #2051721 by yched: Get rid of field_get_items().

parent e33ddd1b
......@@ -840,6 +840,9 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options
*
* @return
* An array with available field items keyed by delta.
*
* @deprecated as of Drupal 8.0. Use
* $entity->getTranslation($langcode)->{$field_name}
*/
function field_get_items(EntityInterface $entity, $field_name, $langcode = NULL) {
$entity = $entity->getBCEntity();
......
......@@ -1881,9 +1881,9 @@ function file_get_file_references(File $file, $field = NULL, $age = FIELD_LOAD_R
// the referenced file. This will fail if the usage checked is in a
// non-current revision because field items are from the current
// revision.
if (!$match && ($field_items = field_get_items($entity, $field_name))) {
foreach ($field_items as $item) {
if ($file->id() == $item[$field_column]) {
if (!$match && ($items = $entity->get($field_name))) {
foreach ($items as $item) {
if ($file->id() == $item->{$field_column}) {
$match = TRUE;
break;
}
......
......@@ -5,7 +5,7 @@
* Builds placeholder replacement tokens for node-related data.
*/
use Drupal\Core\Language\Language;
/**
* Implements hook_token_info().
......@@ -98,7 +98,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
$langcode = $options['langcode'];
}
else {
$langcode = NULL;
$langcode = Language::LANGCODE_DEFAULT;
}
$sanitize = !empty($options['sanitize']);
......@@ -137,17 +137,18 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
case 'body':
case 'summary':
if ($items = field_get_items($node, 'body', $langcode)) {
if (($items = $node->getTranslation($langcode)->get('body')) && !$items->isEmpty()) {
$item = $items[0];
$instance = field_info_instance('node', 'body', $node->type);
$field_langcode = field_language($node, 'body', $langcode);
// If the summary was requested and is not empty, use it.
if ($name == 'summary' && !empty($items[0]['summary'])) {
$output = $sanitize ? text_sanitize($instance['settings']['text_processing'], $field_langcode, $items[0], 'summary') : $items[0]['summary'];
if ($name == 'summary' && !empty($item->summary)) {
$output = $sanitize ? text_sanitize($instance['settings']['text_processing'], $field_langcode, $item->getValue(), 'summary') : $item->summary;
}
// Attempt to provide a suitable version of the 'body' field.
else {
$output = $sanitize ? text_sanitize($instance['settings']['text_processing'], $field_langcode, $items[0], 'value') : $items[0]['value'];
$output = $sanitize ? text_sanitize($instance['settings']['text_processing'], $field_langcode, $item->getValue(), 'value') : $item->value;
// A summary was requested.
if ($name == 'summary') {
// Generate an optionally trimmed summary of the body field.
......@@ -163,7 +164,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
$length = $settings['trim_length'];
}
$output = text_summary($output, $instance['settings']['text_processing'] ? $items[0]['format'] : NULL, $length);
$output = text_summary($output, $instance['settings']['text_processing'] ? $item->format : NULL, $length);
}
}
$replacements[$original] = $output;
......
......@@ -139,8 +139,8 @@ public function getArgument() {
foreach ($fields as $name => $info) {
$field_info = field_info_field($name);
if ($field_info['type'] == 'taxonomy_term_reference') {
foreach (field_get_items($node, $name) as $item) {
$taxonomy[$item['tid']] = $field_info['settings']['allowed_values'][0]['vocabulary'];
foreach ($node->get($name) as $item) {
$taxonomy[$item->target_id] = $field_info['settings']['allowed_values'][0]['vocabulary'];
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment