@param FormInterface $form
@param array         $schema

@return array
328866
protected function addAttr(FormInterface $form, array $schema)
    {
        if ($attr = $form->getConfig()->getOption('attr')) {
            $schema['attr'] = $attr;
        }

        return $schema;
    }
46875
private function getErrorResponse(FormInterface $form)
    {
        $errors = $form->getErrors();
        $errorCollection = [];

        foreach ($errors as $error) {
            $errorCollection[] = $error->getMessage();
        }

        return new JsonResponse([
            'messages' => $errorCollection,
        ], 400);
    }
1304073
protected function workout(FormInterface $form)
    {
        foreach (self::$workers as $worker) {
            call_user_func_array(
                [$worker, 'execute'],
                [$form, $this->parsedData]
            );
        }
    }
932832
private function generateMapping (FormInterface $form, string $translationDomain) : array
    {
        $allErrors = [];
        $formName = $form->getName();
        $fieldPrefix = !empty($formName) ? "{$formName}_" : "";

        $this->addChildErrors($form, $fieldPrefix, $translationDomain, $allErrors);

        if ($form->getErrors()->count() > 0)
        {
            foreach ($form->getErrors() as $topLevelError)
            {
                $allErrors["__global"][] = $this->translator->trans($topLevelError->getMessage(), [], $translationDomain);
            }
        }

        return $allErrors;
    }
455086
protected function addFieldsToSchema(array $schema, string $module): array
    {
        if (isset($schema['definitions']['fieldName'])) {
            $fields = Utility::getRealModuleFields($module, false);
            if (!empty($fields)) {
                $schema['definitions']['fieldName']['enum'] = $fields;
            }
        }

        return $schema;
    }
625981
protected function _getRecords(array $records, TableSchema $schema)
    {
        $fields = $values = $types = [];
        $columns = $schema->columns();
        foreach ($records as $record) {
            $fields = array_merge($fields, array_intersect(array_keys($record), $columns));
        }
        $fields = array_values(array_unique($fields));
        foreach ($fields as $field) {
            $types[$field] = $schema->column($field)['type'];
        }
        $default = array_fill_keys($fields, null);
        foreach ($records as $record) {
            $values[] = array_merge($default, $record);
        }

        return [$fields, $values, $types];
    }
1277479
public function buildForm(array $form, FormStateInterface $form_state) {
    $form['#attributes']['class'][] = 'card card__block form--default form-wrapper form-group';

    if (empty($nid)) {
      $node = \Drupal::routeMatch()->getParameter('node');
      if ($node instanceof NodeInterface) {
        // You can get nid and anything else you need from the node object.
        $nid = $node->id();
      }
      elseif (!is_object($node)) {
        $nid = $node;
      }
    }

    // Load the current Event enrollments so we can check duplicates.
    $storage = \Drupal::entityTypeManager()->getStorage('event_enrollment');
    $enrollments = $storage->loadByProperties(['field_event' => $nid]);

    $enrollmentIds = [];
    foreach ($enrollments as $enrollment) {
      $enrollmentIds[] = $enrollment->getAccount();
    }

    $form['name'] = [
      '#type' => 'social_enrollment_entity_autocomplete',
      '#selection_handler' => 'social',
      '#selection_settings' => [
        'skip_entity' => $enrollmentIds,
      ],
      '#target_type' => 'user',
      '#tags' => TRUE,
      '#description' => $this->t('To add multiple members, separate each member with a comma ( , ).'),
      '#title' => $this->t('Select members to add'),
    ];

    $form['actions']['cancel'] = [
      '#type' => 'link',
      '#title' => t('Cancel'),
      '#url' => Url::fromRoute('view.event_manage_enrollments.page_manage_enrollments', ['node' => $nid]),
    ];

    $form['actions']['submit'] = [
      '#prefix' => '<div class="form-actions">',
      '#suffix' => '</div>',
      '#type' => 'submit',
      '#value' => $this->t('Save'),
      '#button_type' => 'primary',
    ];

    $form['#cache']['contexts'][] = 'user';

    return $form;
  }
654429
public function createOrUpdate(FormInterface $form)
    {
        /** @var CreateUpdateActionHandler $viewHandler */
        $viewHandler = $this->actionHandlers[CreateUpdateActionHandler::class];
        $viewHandler->setView($this->view);
        $viewHandler->setRequest($this->request);
        $viewHandler->setForm($form);

        return $this->getResponse($viewHandler->getView($this->driver));
    }
1229326
public function transform(FormInterface $form)
    {
        return new ConfirmationQuestion($this->questionFrom($form), $this->defaultValueFrom($form));
    }
155518
public function login(?FormInterface $form = null)
    {
        if (!$form) {
            throw new \RuntimeException('This provider require a form');
        }

        $url = $this->config['login']['url'] ?? null;
        if ($this->router->getRouteCollection()->get($url)) {
            $url = $this->router->generate($url, [], Router::ABSOLUTE_URL);
        }

        $opts = [
            CURLOPT_CONNECTTIMEOUT => 10,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER => true,
            CURLOPT_TIMEOUT => 60,
            CURLOPT_HTTPHEADER => [],
        ];

        $paramsIn = $this->config['login']['parameters_in'] ?? 'form';
        if ('header' === $paramsIn) {
            $opts[CURLOPT_HEADER] = true;
            $headers = [];
            foreach ($form->getData() as $key => $value) {
                $headers[] = sprintf('%s: %s', $key, $value);
            }
            $opts[CURLOPT_HTTPHEADER] = array_merge(["Accept: application/json"], $headers);
        } elseif ('query' === $paramsIn) {
            $url .= '?'.http_build_query($form->getData(), null, '&');
        } else {
            $opts[CURLOPT_POSTFIELDS] = http_build_query($form->getData(), null, '&');
            $opts[CURLOPT_POST] = true;
        }

        $opts[CURLOPT_URL] = $url;

        $ch = curl_init();
        curl_setopt_array($ch, $opts);
        $result = curl_exec($ch);

        // Split the HTTP response into header and body.
        try {
            list($headers, $body) = explode("\r\n\r\n", $result);
            $headers = explode("\r\n", $headers);
        } catch (\ErrorException $exception) {
            throw new AuthenticationFailedException('Authentication Failed');
        }

        // We catch HTTP/1.1 4xx or HTTP/1.1 5xx error response.
        if (strpos($headers[0], 'HTTP/1.1 4') !== false || strpos($headers[0], 'HTTP/1.1 5') !== false) {
            $result = [
                'code' => 0,
                'message' => '',
            ];

            if (preg_match('/^HTTP\/1.1 ([0-9]{3,3}) (.*)$/', $headers[0], $matches)) {
                $result['code'] = $matches[1];
                $result['message'] = $matches[2];
            }

            // In case retrun with WWW-Authenticate replace the description.
            foreach ($headers as $header) {
                if (preg_match("/^WWW-Authenticate:.*error='(.*)'/", $header, $matches)) {
                    $result['message'] = $matches[1];
                }
            }

            throw new AuthenticationFailedException($result['message'] ?: 'Authentication Failed', $result['code'] ?: 401);
        }

        $tokenPath = $this->config['login']['response_token_path'] ?? 'token';
        $token = $body;

        if ($tokenPath) {
            $token = search($tokenPath, @json_decode($body));
        }

        if (!$token) {
            throw new AuthenticationFailedException('Authentication Failed');
        }

        $this->session->set(self::SESSION_PATH, $token);
    }
1085655
public function process(FormInterface $form, Request $request)
    {
        if ($request->isMethod('POST')) {
            $form->submit($request);
            if ($form->isValid()) {
                $this->bannerManager->add($form->getData());

                return true;
            }
        }

        return false;
    }
49008
private function serializeForm(Form $form)
    {
        $result = $children = [];
        $errors = iterator_to_array($form->getErrors());

        foreach ($form as $child) {
            if ($child instanceof Form) {
                $children[$child->getName()] = $this->serializeForm($child);
            }
        }

        if (!empty($errors)) {
            $result['errors'] = $errors;
        }

        if (!empty($children)) {
            $result['children'] = $children;
        }

        return $result;
    }
236280
public function render(FormInterface $form, $renderMode = null)
    {
        if (method_exists($form, 'prepare')) {
            $form->prepare();
        }

        $fieldsetHelper = $this->getFieldsetHelper();
        if (method_exists($fieldsetHelper, 'setForm')) {
            $fieldsetHelper->setForm($form);
        }

        if (null === $renderMode) {
            $renderMode = $form->getOption('render_mode');
        }

        $rollbackRenderMode = null;
        if ($renderMode && $fieldsetHelper instanceof FormCollection) {
            $elementHelper = $this->view->plugin($fieldsetHelper->getDefaultElementHelper());
            if ($elementHelper instanceof FormRow) {
                $rollbackRenderMode = $elementHelper->getRenderMode();
                if ($rollbackRenderMode !== $renderMode) {
                    $elementHelper->setRenderMode($renderMode);
                }
            }
        }

        $formMessagesHelper = $this->getFormMessagesHelper();

        $markup = $this->openTag($form)
            . $formMessagesHelper($form)
            . $fieldsetHelper($form, false, false)
            . $this->closeTag();

        if ($rollbackRenderMode) {
            $elementHelper->setRenderMode($rollbackRenderMode);
        }

        return $markup;
    }
259029
public function includeGroups(FieldTypeInterface $form)
    {
        /** @var FieldTypeInterface|FormInterface $form */
        return $this->collection(
            $form->repository()->getGroups(),
            $form->getResourceTransformerFactory()->make('GroupTransformer')
        );
    }
851147
protected function defaultValueFrom(FormInterface $form)
    {
        $defaultValue = $form->getData();
        if (is_array($defaultValue)) {
            $defaultValue = implode(',', $defaultValue);
        }

        return $defaultValue;
    }
425540
public function getFlattenErrors(FormInterface $form = null, $subForm = false)
    {
        $form    = $form ?: $this->form;
        $flatten = [];

        foreach ($form->getErrors() as $error) {
            if ($subForm) {
                $flatten[] = $error->getMessage();
            } else {
                $path = $error->getCause()->getPropertyPath();

                if (!array_key_exists($path, $flatten)) {
                    $flatten[$path] = [$error->getMessage()];
                    continue;
                }

                $flatten[$path][] = $error->getMessage();
            }
        }

        $subForm = true;
        foreach ($form->all() as $key => $child) {
            $childErrors = $this->getFlattenErrors($child, $subForm);

            if (!empty($childErrors)) {
                $flatten[$key] = $childErrors;
            }
        }

        return $flatten;
    }
794187
public function getRegistryData(FormInterface $form = null, PropertyAccess $conf = null)
    {
        $data = [];

        if (null !== $form) {
            if (!$form->isSubmitted()) {
                throw new RuntimeException('Form must have been submitted');
            }
            $newData = $form->getData();
            $data = $this->filterNullValues($newData);
        }

        $currentConf = $conf ? ($conf->get('registry') ?: []) : [];

        return array_replace_recursive($this->getDefaultData($currentConf), $data);
    }