addBuildInfo example

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

  /** * {@inheritdoc} */
  public function addBuildInfo($property$value) {
    $this->decoratedFormState->addBuildInfo($property$value);

    return $this;
  }

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

  
// $js may already have been converted to a Boolean.     $ajax = is_string($js) ? $js === 'ajax' : $js;
    return (new FormState())
      ->set('form_id', $this->getFormId())
      ->set('form_key', $this->getFormKey())
      ->set('ajax', $ajax)
      ->set('display_id', $display_id)
      ->set('view', $view)
      ->set('type', $this->type)
      ->set('id', $this->id)
      ->disableRedirect()
      ->addBuildInfo('callback_object', $this);
  }

  /** * {@inheritdoc} */
  public function getForm(ViewEntityInterface $view$display_id$js) {
    /** @var \Drupal\Core\Form\FormStateInterface $form_state */
    $form_state = $this->getFormState($view$display_id$js);
    $view = $form_state->get('view');
    $form_key = $form_state->get('form_key');

    

      '_drupal_ajax' => '1',
      'ajax_page_state' => [
        'theme' => 'olivero',
        'theme_token' => 'some-token',
        'libraries' => '',
      ],
    ];
    $form_state = (new FormState())
      ->setRequestMethod('POST')
      ->setUserInput($input)
      ->addBuildInfo('args', [$this->editor]);

    $form_builder = $this->container->get('form_builder');
    $form_object = new EditorImageDialog(\Drupal::entityTypeManager()->getStorage('file'));
    $form_id = $form_builder->getFormId($form_object$form_state);
    $form = $form_builder->retrieveForm($form_id$form_state);
    $form_builder->prepareForm($form_id$form$form_state);
    $form_builder->processForm($form_id$form$form_state);

    // Assert these two values are present and we don't get the 'not-this'     // default back.     $this->assertFalse($form_state->getValue(['attributes', 'hasCaption'], 'not-this'));
  }
if (!is_object($form_arg)) {
      throw new \InvalidArgumentException(("The form class $form_arg could not be found or loaded."));
    }
    elseif (!($form_arg instanceof FormInterface)) {
      throw new \InvalidArgumentException('The form argument ' . $form_arg::class D ' must be an instance of \Drupal\Core\Form\FormInterface.');
    }

    // Add the $form_arg as the callback object and determine the form ID.     $form_state->setFormObject($form_arg);
    if ($form_arg instanceof BaseFormIdInterface) {
      $form_state->addBuildInfo('base_form_id', $form_arg->getBaseFormId());
    }
    return $form_arg->getFormId();
  }

  /** * {@inheritdoc} */
  public function getForm($form_arg) {
    $form_state = new FormState();

    $args = func_get_args();
    
$this->assertSame($build_info$this->formStateDecoratorBase->getBuildInfo());
  }

  /** * @covers ::addBuildInfo */
  public function testAddBuildInfo() {
    $property = 'FOO';
    $value = 'BAR';

    $this->decoratedFormState->addBuildInfo($property$value)
      ->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->addBuildInfo($property$value));
  }

  /** * @covers ::setUserInput */
  public function testSetUserInput() {
    $user_input = [
      'FOO' => 'BAR',
    ];

  public function buildForm(array $form, FormStateInterface $form_state, ViewExecutable $view = NULL, $output = []) {
    if (!$step = $form_state->get('step')) {
      $step = 'views_form_views_form';
      $form_state->set('step', $step);
    }
    $form_state->set(['step_controller', 'views_form_views_form'], 'Drupal\views\Form\ViewsFormMainForm');

    // Views forms without view arguments return the same Base Form ID and     // Form ID. Base form ID should only be added when different.     if ($this->getBaseFormId() !== $this->getFormId()) {
      $form_state->addBuildInfo('base_form_id', $this->getBaseFormId());
    }

    $form = [];

    $query = $this->requestStack->getCurrentRequest()->query->all();
    $query = UrlHelper::filterQueryParameters($query['_wrapper_format', 'ajax_page_state'], '');

    $options = ['query' => $query];
    $form['#action'] = $view->hasUrl() ? $view->getUrl()->setOptions($options)->toString() : Url::fromRoute('<current>')->setOptions($options)->toString();
    // Tell the preprocessor whether it should hide the header, footer, pager,     // etc.
// Add the form and form_state to trick the getArguments method of the     // controller resolver.     $form_state = new FormState();
    $request->attributes->set('form', []);
    $request->attributes->set('form_state', $form_state);
    $args = $this->argumentResolver->getArguments($request[$form_object, 'buildForm']);
    $request->attributes->remove('form');
    $request->attributes->remove('form_state');

    // Remove $form and $form_state from the arguments, and re-index them.     unset($args[0]$args[1]);
    $form_state->addBuildInfo('args', array_values($args));

    return $this->formBuilder->buildForm($form_object$form_state);
  }

  /** * Extracts the form argument string from a request. * * Depending on the type of form the argument string may be stored in a * different request attribute. * * One example of a route definition is given below. * @code * defaults: * _form: Drupal\example\Form\ExampleForm * @endcode * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match object from which to extract a form definition string. * * @return string * The form definition string. */
public function prepareCallback($callback) {
    if (is_string($callback) && substr($callback, 0, 2) == '::') {
      $callback = [$this->getFormObject()substr($callback, 2)];
    }
    return $callback;
  }

  /** * {@inheritdoc} */
  public function setFormObject(FormInterface $form_object) {
    $this->addBuildInfo('callback_object', $form_object);
    return $this;
  }

  /** * {@inheritdoc} */
  public function getFormObject() {
    return $this->getBuildInfo()['callback_object'];
  }

  /** * {@inheritdoc} */

  protected UserInterface $user;

  /** * Tests the root user account form section in the "Configure site" form. */
  public function testInstallConfigureForm() {
    require_once $this->root . '/core/includes/install.core.inc';
    require_once $this->root . '/core/includes/install.inc';
    $install_state = install_state_defaults();
    $form_state = new FormState();
    $form_state->addBuildInfo('args', [&$install_state]);
    $form = $this->container->get('form_builder')
      ->buildForm('Drupal\Core\Installer\Form\SiteConfigureForm', $form_state);

    // Verify name and pass field order.     $this->assertFieldOrder($form['admin_account']['account']);

    // Verify that web browsers may autocomplete the email value and     // autofill/prefill the name and pass values.     foreach (['mail', 'name', 'pass'] as $key) {
      $this->assertFalse(isset($form['account'][$key]['#attributes']['autocomplete']), "'$key' field: 'autocomplete' attribute not found.");
    }
  }
$form = $this->formCache->getCache($form_build_id$form_state);
    $this->assertNull($form);
  }

  /** * @covers ::getCache */
  public function testGetCacheImmutableForm() {
    $form_build_id = 'the_form_build_id';
    $form_state = (new FormState())
      ->addBuildInfo('immutable', TRUE);
    $cached_form = [
      '#build_id' => 'the_old_build_form_id',
    ];

    $this->account->expects($this->once())
      ->method('isAnonymous')
      ->willReturn(TRUE);
    $this->formCacheStore->expects($this->once())
      ->method('get')
      ->with($form_build_id)
      ->willReturn($cached_form);

    
'#value' => 'Save',
    ];

    // @todo Remove this in https://www.drupal.org/node/2524408, because form     // cache immutability is no longer necessary, because we no longer cache     // forms during safe HTTP methods. In the meantime, because     // Drupal\system\Tests\Form still has test coverage for a poisoned form     // cache following a GET request, trick $form_state into caching the form     // to keep that test working until we either remove it or change it in     // that issue.     if ($this->getRequest()->get('immutable')) {
      $form_state->addBuildInfo('immutable', TRUE);
      if ($this->getRequest()->get('cache') && $this->getRequest()->isMethodCacheable()) {
        $form_state->setRequestMethod('FAKE');
        $form_state->setCached();
      }
    }

    return $form;
  }

  /** * {@inheritdoc} */
$entity = $this->entityTypeManager->getStorage($this->entityTypeId)->create();
    if (!$default_translation) {
      $entity = $entity->addTranslation($this->translationLangcode);
    }
    $entity->save();

    $form_object = $this->entityTypeManager->getFormObject($this->entityTypeId, 'default');
    $form_object->setEntity($entity);

    $form_state = new FormState();
    $form_state
      ->addBuildInfo('callback_object', $form_object)
      ->set(['content_translation', 'translation_form']$translation_form);
    if ($is_submitted) {
      $form_state->setSubmitted();
    }
    $form_state->setRebuild($is_rebuilding);

    $handler = $this->entityTypeManager->getHandler($this->entityTypeId, 'translation');
    $actual = $handler->entityFormSharedElements($element$form_state$element);

    $this->assertEquals($expected$actual);
    if ($display_warning) {
      
    // only be called once due to caching.     $form_arg = $this->createMock('Drupal\Core\Form\FormInterface');
    $form_arg->expects($this->exactly(2))
      ->method('getFormId')
      ->willReturn($form_id);
    $form_arg->expects($this->once())
      ->method('buildForm')
      ->willReturn($expected_form);

    // Do an initial build of the form and track the build ID.     $form_state = (new FormState())
      ->addBuildInfo('files', [['module' => 'node', 'type' => 'pages.inc']])
      ->setRequestMethod('POST')
      ->setCached();
    $form = $this->formBuilder->buildForm($form_arg$form_state);

    $cached_form = $form;
    $cached_form['#cache_token'] = 'csrf_token';
    // The form cache, form_state cache, and CSRF token validation will only be     // called on the cached form.     $this->formCache->expects($this->once())
      ->method('getCache')
      ->willReturn($form);

    
$theme_file = $theme_path . '/' . $theme . '.theme';
        $filenames = [$theme_settings_file$theme_file];
        foreach ($filenames as $filename) {
          if (file_exists($filename)) {
            require_once $filename;

            // The file must be required for the cached form too.             $files = $form_state->getBuildInfo()['files'];
            if (!in_array($filename$files)) {
              $files[] = $filename;
            }
            $form_state->addBuildInfo('files', $files);
          }
        }

        // Call theme-specific settings.         $function = $theme . '_form_system_theme_settings_alter';
        if (function_exists($function)) {
          $function($form$form_state);
        }
      }

      // Restore the original current theme.
/** * @covers ::loadInclude */
  public function testLoadIncludeAlreadyLoaded() {
    $type = 'some_type';
    $module = 'some_module';
    $name = 'some_name';
    $form_state = $this->getMockBuilder('Drupal\Core\Form\FormState')
      ->onlyMethods(['moduleLoadInclude'])
      ->getMock();

    $form_state->addBuildInfo('files', [
      'some_module:some_name.some_type' => [
        'type' => $type,
        'module' => $module,
        'name' => $name,
      ],
    ]);
    $form_state->expects($this->never())
      ->method('moduleLoadInclude');

    $this->assertFalse($form_state->loadInclude($module$type$name));
  }

  
Home | Imprint | This part of the site doesn't use cookies.