{@inheritdoc}

If you need more than one form in your SKU Type, separate out the forms
using form arguments. By default we fetch the SKU from the form state and
render the addToCartForm.
961321
public function buildForm(array $form, FormStateInterface $form_state) {
    $build_info = $form_state->getBuildInfo();

    if (empty($build_info['args'])) {
      return $this->addToCartForm($form, $form_state);
    }

    $sku = $build_info['args'][0];

    if (get_class($sku) == 'Drupal\acm_sku\Entity\SKU') {
      return $this->addToCartForm($form, $form_state, $build_info['args'][0]);
    }

    return $this->addToCartForm($form, $form_state);
  }
1221938
function traitEntityAddHtml_formBuild() {
        $this->traitEntity_formBuild();
        $this->form->putTbSubmit($this->traitEntityAdd_btnText())
                   ->addClass('btn btn-' . $this->traitEntityAdd_btnClass());
    }
602263
public function render(FormInterface $form, $isHorizontal = false, $labelColumns = 2)
    {
        $this->isHorizontal = (bool) $isHorizontal;
        $this->labelColumns = (int) $labelColumns;

        $this->setHorizontal($form, $this->isHorizontal);

        if (method_exists($form, 'prepare')) {
            $form->prepare();
        }

        $formContent = '';

        $buttons = [];

        foreach ($form as $element) {
            if ($element instanceof Button || $element instanceof Submit) {
                $buttons[] = $element;
                continue;
            } elseif ($element instanceof FieldsetInterface) {
                $formContent .= $this->view->plugin('losFormCollection')->render($element);
            } else {
                $formContent .= $this->view->plugin('losFormRow')->render(
                    $element,
                    $this->isHorizontal,
                    $this->labelColumns
                );
            }
        }

        if (count($buttons) > 0) {
            $formContent .= $this->view->plugin('losFormRow')->renderButtons(
                $buttons,
                $this->isHorizontal,
                $this->labelColumns
            );
        }

        return $this->openTag($form).$formContent.$this->closeTag();
    }
1302358
public function importAction()
    {
        /* @var $form \Zork\Form\Form */
        $request        = $this->getRequest();
        $serviceLocator = $this->getServiceLocator();
        $returnUri      = $request->getQuery( 'returnUri' );
        $return         = $this->getValidReturnUri( $returnUri );
        $form           = $serviceLocator->get( 'Form' )
                                         ->get( 'Grid\Customize\Import' );

        if ( $request->isPost() )
        {
            $form->setData( $data = ArrayUtils::merge(
                $request->getPost()
                        ->toArray(),
                $request->getFiles()
                        ->toArray()
            ) );

            if ( ! empty( $data['returnUri'] ) )
            {
                $return = $this->getValidReturnUri(
                    $data['returnUri'],
                    $return
                );
            }

            if ( $form->isValid() )
            {
                $data       = $form->getData();
                $file       = $data['file']['tmp_name'];
                $name       = $data['file']['name'];
                $translator = $serviceLocator->get( 'translator' );
                $result     = $serviceLocator->get( 'Grid\Customize\Model\Importer' )
                                             ->import( $file, $name );

                if ( $result->isSuccess() )
                {
                    $this->messenger()
                         ->add(
                             sprintf(
                                 $translator->translate( 'customize.import.success.link.%s' ),
                                 $this->url()
                                      ->fromRoute( 'Grid\Paragraph\Render\Paragraph', array(
                                          'locale'        => (string) $this->locale(),
                                          'paragraphId'   => $result->getCreatedParagraphId(),
                                      ) )
                             ),
                             false,
                             Message::LEVEL_INFO
                         );
                }
                else
                {
                    $code = $result->getCode();

                    if ( ! isset( static::$importErrorMessages[$code] ) )
                    {
                        $code = ImportResult::UNKNOWN_ERROR;
                    }

                    $this->messenger()
                         ->add(
                             sprintf(
                                 $translator->translate( 'customize.import.failed.message.%s.%s' ),
                                 $translator->translate( static::$importErrorMessages[$code] ),
                                 $result->getErrorMessage()
                             ),
                             false,
                             Message::LEVEL_ERROR
                         );
                }

                if ( $return )
                {
                    return $this->redirect()
                                ->toUrl( $return );
                }
                else if ( $result->isSuccess() )
                {
                    return $this->redirect()
                                ->toRoute( 'Grid\Customize\CssAdmin\List', array(
                                    'locale' => (string) $this->locale(),
                                ) );
                }
            }
        }
        else if ( $return )
        {
            $form->get( 'returnUri' )
                 ->setValue( $return );
        }

        $form->setCancel(
            $return ? $return
                    : $this->url()
                           ->fromRoute( 'Grid\Customize\CssAdmin\List', array(
                               'locale' => (string) $this->locale(),
                           ) )
        );

        return array(
            'form' => $form,
        );
    }
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;
  }
1194851
public function addAction()
    {
        $this->registerBreadcrubms()->addItem($this->get("translator")->trans("Add"));

        $entity = $this->getNewEntity();
        $form = $this->createCreateForm($entity);

        return [
            'entity' => $entity,
            'form' => $form->createView(),
        ];
    }
243124
private function updateCart(FormStateInterface $form_state) {
    try {
      $cart = $this->cartStorage->updateCart();
      $response_message = $cart->get('response_message');
      // We will have type of message like error or success. key '0' contains
      // the response message string while key '1' contains the response
      // message context/type like success or coupon.
      if (!empty($response_message[1])) {
        // If its success.
        if ($response_message[1] == 'success') {
          $this->successMessage = $response_message[0];
        }
        elseif ($response_message[1] == 'error_coupon') {
          // Set the error and require rebuild.
          $form_state->setErrorByName('coupon', $response_message[0]);
          $form_state->setRebuild(TRUE);

          // Remove the coupon and update the cart.
          $this->cartStorage->setCoupon('');
          $this->updateCart($form_state);
        }
      }
    }
    catch (\Exception $e) {
      if (acm_is_exception_api_down_exception($e)) {
        $this->messenger()->addError($e->getMessage());
        $form_state->setErrorByName('custom', $e->getMessage());
        $form_state->setRebuild(TRUE);
      }

      // Dispatch event so action can be taken.
      $dispatcher = \Drupal::service('event_dispatcher');
      $event = new UpdateCartErrorEvent($e);
      $dispatcher->dispatch(UpdateCartErrorEvent::SUBMIT, $event);
      $this->messenger()->addError($e->getMessage());
    }
  }
654394
public function updateEditForm($form)
    {
        if ($doadd = Config::inst()->get('ModelAdmin', 'addbetterimporters')) {
            $modelclass = $this->owner->modelClass;
            $grid = $form->Fields()->fieldByName($modelclass);
            $config =  $grid->getConfig();

            //don't proceed if there is already an importer
            if ($config->getComponentByType("GridFieldImporter")) {
                return;
            }
            //don't proceed if can't create
            if (!singleton($modelclass)->canCreate(Member::currentUser())) {
                return;
            }
            //allow config to avoid adding when there are existing importers
            $importerClasses = $this->owner->stat('model_importers');
            if (
                $doadd === "scaffolded" &&
                !is_null($importerClasses) &&
                isset($importerClasses[$modelclass])
            ) {
                return;
            }
            
            //add the component
            $config->addComponent(new GridFieldImporter('before'));
        }
    }
287373
public function AddPackageForm() {
        $sng=singleton('SnippetPackage');
        
        $fields=new FieldList(
                            new TabSet('Root',
                                    new Tab('Main', _t('PackageSelectionField.MAIN', '_Main'),
                                            new TextField('Title', _t('PackageSelectionField.TITLE', '_Title'), null, 300)
                                        )
                                )
                        );
        
        $actions=new FieldList(
                                FormAction::create('doAddPackage', _t('PackageSelectionField.CREATE', '_Create'))
                                                    ->addExtraClass('ss-ui-action-constructive')
                                                    ->setAttribute('data-icon', 'accept')
                                                    ->setUseButtonTag(true)
                            );
        
        $validator=new RequiredFields(
                                    'Title'
                                );
        
        return Form::create($this, 'AddPackageForm', $fields, $actions, $validator)
                            ->addExtraClass('member-profile-form')
                            ->setFormAction($this->Link('AddPackageForm'));
    }
72417
public function addItem($id, $name = null, $type = null, $qty = 1, Money $price = null, $uri = null, array $options = [])
    {
        $cartItem = CartItem::fromAttributes($id, $name, $type, $price, $uri, $options);

        return $this->addItemToCart($cartItem, $qty);
    }
276543
def doSendRefundForms(self, item_id, buyer_id, reason, quantity_sold):
        """"""
        # TODO: deprecated
        return self.__ask__('doSendRefundForms',
                            sendRefundFormsDataArr={
                                'item': {
                                    'itemId': item_id, 'buyerId': buyer_id,
                                    'refundReason': reason, 'itemQuantitySold': quantity_sold
                                }
                            })['sendRefundFormsResultsArr']
725905
protected function processAdditionalImages()
    {

        // load the store view code
        $storeViewCode = $this->getValue(ColumnKeys::STORE_VIEW_CODE);
        $attributeSetCode = $this->getValue(ColumnKeys::ATTRIBUTE_SET_CODE);

        // load the parent SKU from the row
        $parentSku = $this->getValue(ColumnKeys::SKU);

        // query whether or not, we've additional images
        if ($additionalImages = $this->getValue(ColumnKeys::ADDITIONAL_IMAGES, null, array($this, 'explode'))) {
            // expand the additional image labels, if available
            $additionalImageLabels = $this->getValue(ColumnKeys::ADDITIONAL_IMAGE_LABELS, array(), array($this, 'explode'));

            // initialize the images with the found values
            foreach ($additionalImages as $key => $additionalImage) {
                // prepare the additional image
                $artefact = $this->newArtefact(
                    array(
                        ColumnKeys::STORE_VIEW_CODE    => $storeViewCode,
                        ColumnKeys::ATTRIBUTE_SET_CODE => $attributeSetCode,
                        ColumnKeys::IMAGE_PARENT_SKU   => $parentSku,
                        ColumnKeys::IMAGE_PATH         => $additionalImage,
                        ColumnKeys::IMAGE_PATH_NEW     => $additionalImage,
                        ColumnKeys::IMAGE_LABEL        => isset($additionalImageLabels[$key]) ?
                                                          $additionalImageLabels[$key] :
                                                          $this->getDefaultImageLabel()
                    ),
                    array(
                        ColumnKeys::STORE_VIEW_CODE    => ColumnKeys::STORE_VIEW_CODE,
                        ColumnKeys::ATTRIBUTE_SET_CODE => ColumnKeys::ATTRIBUTE_SET_CODE,
                        ColumnKeys::IMAGE_PARENT_SKU   => ColumnKeys::SKU,
                        ColumnKeys::IMAGE_PATH         => ColumnKeys::ADDITIONAL_IMAGES,
                        ColumnKeys::IMAGE_PATH_NEW     => ColumnKeys::ADDITIONAL_IMAGES,
                        ColumnKeys::IMAGE_LABEL        => ColumnKeys::ADDITIONAL_IMAGE_LABELS
                    )
                );

                // append the additional image to the artefacts
                $this->artefacts[] = $artefact;
            }
        }
    }
677194
public function getExtraFormTypesOptionsAction(
        $_format,
        $type,
        ExtraFormTypeRegistryInterface $registry,
        FormFactoryInterface $formFactory,
        ExtraFormBuilderInterface $extraFormBuilder
    ) {
        if (!($registry->hasType($type))) {
            throw new NotFoundHttpException(sprintf(
                'The Type `%s` was not found',
                $type
            ));
        }

        $view = View::create()->setFormat($_format);
        $options = $registry->getType($type)->getExtraFormOptions();

        if ('html' === $_format) {
            $form = $extraFormBuilder
                ->build(
                    $options,
                    array(),
                    null,
                    $formFactory->createNamedBuilder(
                        null,
                        'form',
                        null,
                        array('csrf_protection' => false)
                    )
                )
                ->getForm()
            ;

            $view
                ->setData($form->createView())
                ->setTemplate('IDCIExtraFormBundle:Api:form.html.twig')
                ->setTemplateVar('form')
            ;
        } else {
            $view->setData($options);
        }

        return $this->handleView($view);
    }
1319504
public function editItemClass()
    {
        $this->defaultData();

        $clazz = $this->getClass($this->getRequestParameter('id'));

        if($this->hasRequestParameter('property_mode')){
            $this->setSessionAttribute('property_mode', $this->getRequestParameter('property_mode'));
        }

        $myForm = $this->getClassForm($clazz, $this->getClassService()->getRootClass());

        if ($this->hasWriteAccess($clazz->getUri())) {
            if($myForm->isSubmited()){
                if($myForm->isValid()){
                    if($clazz instanceof core_kernel_classes_Resource){
                        $this->setData("selectNode", tao_helpers_Uri::encode($clazz->getUri()));
                    }
                    $this->setData('message', __('Class schema saved'));
                    $this->setData('reload', false);
                }
            }
        } else {
            $myForm->setActions(array());
        }
        $this->setData('formTitle', __('Manage item class schema'));
        $this->setData('myForm', $myForm->render());
        $this->setView('form.tpl', 'tao');
    }
590325
static function registerForm (Form $form)
    {
        if (!in_array($form, self::$forms))
            array_push(self::$forms, $form);
    }
1262076
public function render(FormInterface $form)
    {
        if (method_exists($form, 'prepare')) {
            $form->prepare();
        }

        $formContent = '';

        foreach ($form as $element) {
            if ($element instanceof FieldsetInterface) {
                $formContent.= $this->getView()->bootstrapFormCollection($element);
            } else {
                $formContent.= $this->getView()->bootstrapFormRow($element);
            }
        }

        return $this->openTag($form) . $formContent . $this->closeTag();
    }
323928
public function withProductRequest($sku, $qty = 1, $request = []) : CartBuilder
    {
        $result = clone $this;
        $requestInfo = array_merge(['qty'=> $qty], $request);
        $result->addToCartRequests[$sku][] = new DataObject($requestInfo);
        return $result;
    }