Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FormDataPart.php

function FormDataPart::prepareFields

1 call to FormDataPart::prepareFields()
FormDataPart::getParts in vendor/symfony/mime/Part/Multipart/FormDataPart.php

File

vendor/symfony/mime/Part/Multipart/FormDataPart.php, line 48

Class

FormDataPart
Implements RFC 7578.

Namespace

Symfony\Component\Mime\Part\Multipart

Code

private function prepareFields(array $fields) : array {
    $values = [];
    $prepare = function ($item, $key, $root = null) use (&$values, &$prepare) {
        if (null === $root && \is_int($key) && \is_array($item)) {
            if (1 !== \count($item)) {
                throw new InvalidArgumentException(\sprintf('Form field values with integer keys can only have one array element, the key being the field name and the value being the field value, %d provided.', \count($item)));
            }
            $key = key($item);
            $item = $item[$key];
        }
        $fieldName = null !== $root ? \sprintf('%s[%s]', $root, $key) : $key;
        if (\is_array($item)) {
            array_walk($item, $prepare, $fieldName);
            return;
        }
        if (!\is_string($item) && !$item instanceof TextPart) {
            throw new InvalidArgumentException(\sprintf('The value of the form field "%s" can only be a string, an array, or an instance of TextPart, "%s" given.', $fieldName, get_debug_type($item)));
        }
        $values[] = $this->preparePart($fieldName, $item);
    };
    array_walk($fields, $prepare);
    return $values;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal