本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::setFormState方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::setFormState方法的具体用法?PHP FormStateInterface::setFormState怎么用?PHP FormStateInterface::setFormState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::setFormState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadCachedFormState
/**
* Loads the cached form state.
*
* @param string $form_build_id
* The unique form build ID.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
protected function loadCachedFormState($form_build_id, FormStateInterface $form_state)
{
if ($stored_form_state = $this->keyValueExpirableFactory->get('form_state')->get($form_build_id)) {
// Re-populate $form_state for subsequent rebuilds.
$form_state->setFormState($stored_form_state);
// If the original form is contained in include files, load the files.
// @see \Drupal\Core\Form\FormStateInterface::loadInclude()
$build_info = $form_state->getBuildInfo();
$build_info += ['files' => []];
foreach ($build_info['files'] as $file) {
if (is_array($file)) {
$file += array('type' => 'inc', 'name' => $file['module']);
$this->moduleHandler->loadInclude($file['module'], $file['type'], $file['name']);
} elseif (file_exists($file)) {
require_once $this->root . '/' . $file;
}
}
// Retrieve the list of previously known safe strings and store it for
// this request.
// @todo Ensure we are not storing an excessively large string list
// in: https://www.drupal.org/node/2295823
$build_info += ['safe_strings' => []];
SafeMarkup::setMultiple($build_info['safe_strings']);
unset($build_info['safe_strings']);
$form_state->setBuildInfo($build_info);
}
}
示例2: loadCachedFormState
/**
* Loads the cached form state.
*
* @param string $form_build_id
* The unique form build ID.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
protected function loadCachedFormState($form_build_id, FormStateInterface $form_state)
{
if ($stored_form_state = $this->keyValueExpirableFactory->get('form_state')->get($form_build_id)) {
// Re-populate $form_state for subsequent rebuilds.
$form_state->setFormState($stored_form_state);
// If the original form is contained in include files, load the files.
// @see \Drupal\Core\Form\FormStateInterface::loadInclude()
$build_info = $form_state->getBuildInfo();
$build_info += ['files' => []];
foreach ($build_info['files'] as $file) {
if (is_array($file)) {
$file += array('type' => 'inc', 'name' => $file['module']);
$this->moduleHandler->loadInclude($file['module'], $file['type'], $file['name']);
} elseif (file_exists($file)) {
require_once $this->root . '/' . $file;
}
}
}
}
示例3: setFormState
/**
* {@inheritdoc}
*/
public function setFormState(array $form_state_additions)
{
$this->decoratedFormState->setFormState($form_state_additions);
return $this;
}
示例4: getCache
/**
* {@inheritdoc}
*/
public function getCache($form_build_id, FormStateInterface &$form_state)
{
if ($form = $this->keyValueExpirableFactory->get('form')->get($form_build_id)) {
$user = $this->currentUser();
if (isset($form['#cache_token']) && $this->csrfToken->validate($form['#cache_token']) || !isset($form['#cache_token']) && $user->isAnonymous()) {
if ($stored_form_state = $this->keyValueExpirableFactory->get('form_state')->get($form_build_id)) {
// Re-populate $form_state for subsequent rebuilds.
$form_state->setFormState($stored_form_state);
// If the original form is contained in include files, load the files.
// @see form_load_include()
$form_state['build_info'] += array('files' => array());
foreach ($form_state['build_info']['files'] as $file) {
if (is_array($file)) {
$file += array('type' => 'inc', 'name' => $file['module']);
$this->moduleHandler->loadInclude($file['module'], $file['type'], $file['name']);
} elseif (file_exists($file)) {
require_once DRUPAL_ROOT . '/' . $file;
}
}
// Retrieve the list of previously known safe strings and store it
// for this request.
// @todo Ensure we are not storing an excessively large string list
// in: https://www.drupal.org/node/2295823
$form_state['build_info'] += array('safe_strings' => array());
SafeMarkup::setMultiple($form_state['build_info']['safe_strings']);
unset($form_state['build_info']['safe_strings']);
}
return $form;
}
}
}
示例5: testSetFormState
/**
* @covers ::setFormState
*/
public function testSetFormState()
{
$form_state_additions = ['foo' => 'bar'];
$this->decoratedFormState->setFormState($form_state_additions)->shouldBeCalled();
$this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setFormState($form_state_additions));
}