getCacheableArray example

/** * {@inheritdoc} */
  public function loadInclude($module$type$name = NULL) {
    return $this->decoratedFormState->loadInclude($module$type$name);
  }

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

  /** * {@inheritdoc} */
  public function setCompleteForm(array &$complete_form) {
    $this->decoratedFormState->setCompleteForm($complete_form);

    return $this;
  }

  
      // during self::retrieveForm()/self::prepareForm(), but form processing       // should not depend on whether the form is cached or not, so $form_state       // is adjusted to match what it would be after a       // self::setCache()/self::getCache() sequence. These exceptions are       // allowed to survive here:       // - always_process: Does not make sense in conjunction with form caching       // in the first place, since passing form_build_id as a GET parameter is       // not desired.       // - temporary: Any assigned data is expected to survives within the same       // page request.       if ($check_cache) {
        $cache_form_state = $form_state->getCacheableArray();
        $cache_form_state['always_process'] = $form_state->getAlwaysProcess();
        $cache_form_state['temporary'] = $form_state->getTemporary();
        $form_state = $form_state_before_retrieval;
        $form_state->setFormState($cache_form_state);
      }
    }

    // If this form is an AJAX request, disable all form redirects.     if ($ajax_form_request = $request->query->has(static::AJAX_FORM_REQUEST)) {
      $form_state->disableRedirect();
    }

    

  }

  /** * @covers ::getCacheableArray */
  public function testGetCacheableArray() {
    $cacheable_array = [
      'foo' => 'bar',
    ];

    $this->decoratedFormState->getCacheableArray()
      ->willReturn($cacheable_array)
      ->shouldBeCalled();

    $this->assertSame($cacheable_array$this->formStateDecoratorBase->getCacheableArray());
  }

  /** * @covers ::setCompleteForm */
  public function testSetCompleteForm() {
    $complete_form = [
      
public function testSetCacheWithForm() {
    $form_build_id = 'the_form_build_id';
    $form = [
      '#form_id' => 'the_form_id',
    ];
    $form_state = new FormState();

    $this->formCacheStore->expects($this->once())
      ->method('setWithExpire')
      ->with($form_build_id$form$this->isType('int'));

    $form_state_data = $form_state->getCacheableArray();
    $this->formStateCacheStore->expects($this->once())
      ->method('setWithExpire')
      ->with($form_build_id$form_state_data$this->isType('int'));

    $this->formCache->setCache($form_build_id$form$form_state);
  }

  /** * @covers ::setCache */
  public function testSetCacheWithoutForm() {
    


    // Cache form structure.     if (isset($form)) {
      if ($this->currentUser->isAuthenticated()) {
        $form['#cache_token'] = $this->csrfToken->get();
      }
      unset($form['#build_id_old']);
      $this->keyValueExpirableFactory->get('form')->setWithExpire($form_build_id$form$expire);
    }

    if ($data = $form_state->getCacheableArray()) {
      $this->keyValueExpirableFactory->get('form_state')->setWithExpire($form_build_id$data$expire);
    }
  }

  /** * {@inheritdoc} */
  public function deleteCache($form_build_id) {
    $this->keyValueExpirableFactory->get('form')->delete($form_build_id);
    $this->keyValueExpirableFactory->get('form_state')->delete($form_build_id);
  }

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