isProgrammed example

$form = $this->doBuildForm($form_id$form$form_state);

    // Only process the input if we have a correct form submission.     if ($form_state->isProcessingInput()) {
      // Form values for programmed form submissions typically do not include a       // value for the submit button. But without a triggering element, a       // potentially existing #limit_validation_errors property on the primary       // submit button is not taken account. Therefore, check whether there is       // exactly one submit button in the form, and if so, automatically use it       // as triggering_element.       $buttons = $form_state->getButtons();
      if ($form_state->isProgrammed() && !$form_state->getTriggeringElement() && count($buttons) == 1) {
        $form_state->setTriggeringElement(reset($buttons));
      }
      $this->formValidator->validateForm($form_id$form$form_state);

      // If there are no errors and the form is not rebuilding, submit the form.       if (!$form_state->isRebuilding() && !FormState::hasAnyErrors()) {
        $submit_response = $this->formSubmitter->doSubmitForm($form$form_state);
        // If this form was cached, delete it from the cache after submission.         if ($form_state->isCached()) {
          $this->deleteCache($form['#build_id']);
        }
        
'#default_value' => $item->_weight ?: $delta,
            '#weight' => 100,
          ];
        }

        $elements[$delta] = $element;
        $delta++;
      }
    }

    $empty_single_allowed = ($cardinality == 1 && $delta == 0);
    $empty_multiple_allowed = ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED || $delta < $cardinality) && !$form_state->isProgrammed();

    // Add one more empty row for new uploads except when this is a programmed     // multiple form as it is not necessary.     if ($empty_single_allowed || $empty_multiple_allowed) {
      // Create a new empty item.       $items->appendItem();
      $element = [
        '#title' => $title,
        '#description' => $description,
      ];
      $element = $this->formSingleElement($items$delta$element$form$form_state);
      

  public function setProgrammed($programmed = TRUE) {
    $this->decoratedFormState->setProgrammed($programmed);

    return $this;
  }

  /** * {@inheritdoc} */
  public function isProgrammed() {
    return $this->decoratedFormState->isProgrammed();
  }

  /** * {@inheritdoc} */
  public function setProgrammedBypassAccessCheck($programmed_bypass_access_check = TRUE) {
    $this->decoratedFormState->setProgrammedBypassAccessCheck($programmed_bypass_access_check);

    return $this;
  }

  
'#theme' => 'field_multiple_value_form',
        '#field_name' => $field_name,
        '#cardinality' => $cardinality,
        '#cardinality_multiple' => $this->fieldDefinition->getFieldStorageDefinition()->isMultiple(),
        '#required' => $this->fieldDefinition->isRequired(),
        '#title' => $title,
        '#description' => $description,
        '#max_delta' => $max,
      ];

      // Add 'add more' button, if not working with a programmed form.       if ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && !$form_state->isProgrammed()) {
        $id_prefix = implode('-', array_merge($parents[$field_name]));
        $wrapper_id = Html::getUniqueId($id_prefix . '-add-more-wrapper');
        $elements['#prefix'] = '<div id="' . $wrapper_id . '">';
        $elements['#suffix'] = '</div>';

        $elements['add_more'] = [
          '#type' => 'submit',
          '#name' => strtr($id_prefix, '-', '_') . '_add_more',
          '#value' => t('Add another item'),
          '#attributes' => ['class' => ['field-add-more-submit']],
          '#limit_validation_errors' => [array_merge($parents[$field_name])],
          

    return FALSE;
  }

  /** * {@inheritdoc} */
  public function getCacheableArray() {
    return [
      'build_info' => $this->getBuildInfo(),
      'response' => $this->getResponse(),
      'programmed' => $this->isProgrammed(),
      'programmed_bypass_access_check' => $this->isBypassingProgrammedAccessChecks(),
      'process_input' => $this->isProcessingInput(),
      'has_file_element' => $this->hasFileElement(),
      'storage' => $this->getStorage(),
      // Use the properties directly, since self::isCached() combines them and       // cannot be relied upon.       'cache' => $this->cache,
      'no_cache' => $this->no_cache,
    ];
  }

  
// Execute form submit handlers.     $this->executeSubmitHandlers($form$form_state);

    // If batches were set in the submit handlers, we process them now,     // possibly ending execution. We make sure we do not react to the batch     // that is already being processed (if a batch operation performs a     // \Drupal\Core\Form\FormBuilderInterface::submitForm).     if ($batch = &$this->batchGet() && !isset($batch['current_set'])) {
      // Store $form_state information in the batch definition.       $batch['form_state'] = $form_state;

      $batch['progressive'] = !$form_state->isProgrammed();
      $response = batch_process();
      // If the batch has been completed and _batch_finished() called then       // $batch will be NULL.       if ($batch && $batch['progressive']) {
        return $response;
      }

      // Execution continues only for programmatic forms.       // For 'regular' forms, we get redirected to the batch processing       // page. Form redirection will be handled in _batch_finished(),       // after the batch is processed.
->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setProgrammed($programmed));
  }

  /** * @covers ::isProgrammed * * @dataProvider providerSingleBooleanArgument */
  public function testIsProgrammed($programmed) {
    $this->decoratedFormState->isProgrammed()
      ->willReturn($programmed)
      ->shouldBeCalled();

    $this->assertSame($programmed$this->formStateDecoratorBase->isProgrammed());
  }

  /** * @covers ::setProgrammedBypassAccessCheck * * @dataProvider providerSingleBooleanArgument */
  
Home | Imprint | This part of the site doesn't use cookies.