summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-08-21 07:57:07 (GMT)
committerNathaniel Catchpole2017-08-21 07:57:07 (GMT)
commitfb3c8d4ed7750ddf8e832cd0e18f862490271e34 (patch)
treed8d195c98dc873592eae953060dced3b2b21d8bc
parent78ae240146cb30f9d5bb94a059ab4860f286297a (diff)
Issue #2143089 by imadalin, yched, dawehner, harsha012, Wim Leers, c.nish2k3, bradjones1, damiankloip, xjm: Clean up normalizer parameter and variable names to use 'field_items' consistently etc
-rw-r--r--core/modules/hal/src/Normalizer/ContentEntityNormalizer.php8
-rw-r--r--core/modules/hal/src/Normalizer/FieldNormalizer.php23
-rw-r--r--core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php6
-rw-r--r--core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php8
4 files changed, 22 insertions, 23 deletions
diff --git a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
index 1fc118d..eb45247 100644
--- a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
+++ b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
@@ -74,15 +74,15 @@ class ContentEntityNormalizer extends NormalizerBase {
// If the fields to use were specified, only output those field values.
if (isset($context['included_fields'])) {
- $fields = [];
+ $field_items = [];
foreach ($context['included_fields'] as $field_name) {
- $fields[] = $entity->get($field_name);
+ $field_items[] = $entity->get($field_name);
}
}
else {
- $fields = $entity->getFields();
+ $field_items = $entity->getFields();
}
- foreach ($fields as $field) {
+ foreach ($field_items as $field) {
// Continue if the current user does not have access to view this field.
if (!$field->access('view', $context['account'])) {
continue;
diff --git a/core/modules/hal/src/Normalizer/FieldNormalizer.php b/core/modules/hal/src/Normalizer/FieldNormalizer.php
index 167499a..ca973b6 100644
--- a/core/modules/hal/src/Normalizer/FieldNormalizer.php
+++ b/core/modules/hal/src/Normalizer/FieldNormalizer.php
@@ -18,18 +18,18 @@ class FieldNormalizer extends SerializationFieldNormalizer {
/**
* {@inheritdoc}
*/
- public function normalize($field, $format = NULL, array $context = []) {
+ public function normalize($field_items, $format = NULL, array $context = []) {
$normalized_field_items = [];
// Get the field definition.
- $entity = $field->getEntity();
- $field_name = $field->getName();
- $field_definition = $field->getFieldDefinition();
+ $entity = $field_items->getEntity();
+ $field_name = $field_items->getName();
+ $field_definition = $field_items->getFieldDefinition();
// If this field is not translatable, it can simply be normalized without
// separating it into different translations.
if (!$field_definition->isTranslatable()) {
- $normalized_field_items = $this->normalizeFieldItems($field, $format, $context);
+ $normalized_field_items = $this->normalizeFieldItems($field_items, $format, $context);
}
// Otherwise, the languages have to be extracted from the entity and passed
// in to the field item normalizer in the context. The langcode is appended
@@ -38,15 +38,14 @@ class FieldNormalizer extends SerializationFieldNormalizer {
foreach ($entity->getTranslationLanguages() as $language) {
$context['langcode'] = $language->getId();
$translation = $entity->getTranslation($language->getId());
- $translated_field = $translation->get($field_name);
- $normalized_field_items = array_merge($normalized_field_items, $this->normalizeFieldItems($translated_field, $format, $context));
+ $translated_field_items = $translation->get($field_name);
+ $normalized_field_items = array_merge($normalized_field_items, $this->normalizeFieldItems($translated_field_items, $format, $context));
}
}
// Merge deep so that links set in entity reference normalizers are merged
// into the links property.
- $normalized = NestedArray::mergeDeepArray($normalized_field_items);
- return $normalized;
+ return NestedArray::mergeDeepArray($normalized_field_items);
}
/**
@@ -62,10 +61,10 @@ class FieldNormalizer extends SerializationFieldNormalizer {
* @return array
* The array of normalized field items.
*/
- protected function normalizeFieldItems($field, $format, $context) {
+ protected function normalizeFieldItems($field_items, $format, $context) {
$normalized_field_items = [];
- if (!$field->isEmpty()) {
- foreach ($field as $field_item) {
+ if (!$field_items->isEmpty()) {
+ foreach ($field_items as $field_item) {
$normalized_field_items[] = $this->serializer->normalize($field_item, $format, $context);
}
}
diff --git a/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php b/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php
index 3d20312..33beb37 100644
--- a/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php
+++ b/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php
@@ -26,9 +26,9 @@ class ComplexDataNormalizer extends NormalizerBase {
*/
public function normalize($object, $format = NULL, array $context = []) {
$attributes = [];
- /** @var \Drupal\Core\TypedData\TypedDataInterface $field */
- foreach ($object as $name => $field) {
- $attributes[$name] = $this->serializer->normalize($field, $format, $context);
+ /** @var \Drupal\Core\TypedData\TypedDataInterface $property */
+ foreach ($object as $name => $property) {
+ $attributes[$name] = $this->serializer->normalize($property, $format, $context);
}
return $attributes;
}
diff --git a/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php b/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php
index f1ca82d..d3abef6 100644
--- a/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php
+++ b/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php
@@ -15,15 +15,15 @@ class ContentEntityNormalizer extends EntityNormalizer {
/**
* {@inheritdoc}
*/
- public function normalize($object, $format = NULL, array $context = []) {
+ public function normalize($entity, $format = NULL, array $context = []) {
$context += [
'account' => NULL,
];
$attributes = [];
- foreach ($object as $name => $field) {
- if ($field->access('view', $context['account'])) {
- $attributes[$name] = $this->serializer->normalize($field, $format, $context);
+ foreach ($entity as $name => $field_items) {
+ if ($field_items->access('view', $context['account'])) {
+ $attributes[$name] = $this->serializer->normalize($field_items, $format, $context);
}
}