protected function processRequestPayload(array $payload, EntityTypeInterface $entity_type, $path_prefix = '')
 {
     $processed_payload = [];
     $allowed_attribute_names = $this->getAllowedAttributeNames($entity_type);
     foreach ($allowed_attribute_names as $attribute_name) {
         // skip processing if attribute not in payload or not on entity type
         if (!isset($payload[$attribute_name]) || !$entity_type->hasAttribute($attribute_name)) {
             continue;
         }
         $attribute = $entity_type->getAttribute($attribute_name);
         $current_prefix = $path_prefix ? $path_prefix . '.' . $attribute_name : $attribute_name;
         if ($attribute instanceof ListAttribute) {
             $processed_payload[$attribute_name] = [];
             foreach ((array) $payload[$attribute_name] as $position => $embed_payload) {
                 $value_path = $current_prefix . '.' . $position;
                 if ($attribute instanceof EmbeddedEntityListAttribute) {
                     if (!isset($embed_payload['@type']) || !($embed_type = $attribute->getEmbeddedEntityTypeMap()->getItem($embed_payload['@type']))) {
                         // skip processing for invalid @type
                         $processed_payload[$attribute_name][$position] = $embed_payload;
                     } else {
                         $processed_payload[$attribute_name][$position] = $this->processRequestPayload($embed_payload, $embed_type, $value_path);
                         // reapply @type into processed payload
                         $processed_payload[$attribute_name][$position]['@type'] = $embed_payload['@type'];
                     }
                 } elseif ($attribute instanceof HandlesFileListInterface) {
                     $processed_payload[$attribute_name][$position] = $this->prepareUploadedFile($embed_payload, $attribute, $value_path);
                 } else {
                     // generic list attribute handling
                     $processed_payload[$attribute_name] = $payload[$attribute_name];
                 }
                 // reapply action into processed payload
                 if (isset($embed_payload['__action'])) {
                     $processed_payload[$attribute_name][$position]['__action'] = $embed_payload['__action'];
                 }
             }
         } else {
             $processed_payload[$attribute_name] = $payload[$attribute_name];
         }
         // filter empty placeholders and apply list actions
         if ($attribute instanceof ListAttribute) {
             $processed_payload[$attribute_name] = ArrayToolkit::filterEmptyValues($processed_payload[$attribute_name]);
             $processed_payload[$attribute_name] = $this->applyListAttributeActions($attribute, $processed_payload[$attribute_name]);
             // inline_mode means that we never want to produce 'remove' embedded entity commands
             // so we just remove the key if the payload is empty after processing.
             if ($attribute->getOption('inline_mode', false) === true && empty($processed_payload[$attribute_name])) {
                 unset($processed_payload[$attribute_name]);
             }
         }
     }
     return $processed_payload;
 }
 public static function filterEmptyPayloadComingFromFiles(HandlesFileInterface $attribute, array $payload)
 {
     $filtered_payload = [];
     foreach ($payload as $image_data) {
         if (isset($image_data['[{@= index @}]'])) {
             continue;
         }
         $value = ArrayToolkit::filterEmptyValues($image_data);
         if (!empty($value)) {
             $filtered_payload[] = $value;
         }
     }
     return $filtered_payload;
 }