本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::getStorage方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::getStorage方法的具体用法?PHP FormStateInterface::getStorage怎么用?PHP FormStateInterface::getStorage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::getStorage方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildChildFormState
/**
* Build all necessary things for child form (form state, etc.).
*
* @param \Drupal\Core\Entity\EntityFormInterface $controller
* Entity form controller for child form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Parent form state object.
* @param \Drupal\Core\Entity\EntityInterface $entity
* Entity object.
* @param string $operation
* Operation that is to be performed in inline form.
* @param array $parents
* Entity form #parents.
*
* @return \Drupal\Core\Form\FormStateInterface
* Child form state object.
*/
public static function buildChildFormState(EntityFormInterface $controller, FormStateInterface $form_state, EntityInterface $entity, $operation, $parents) {
$child_form_state = new FormState();
$child_form_state->addBuildInfo('callback_object', $controller);
$child_form_state->addBuildInfo('base_form_id', $controller->getBaseFormID());
$child_form_state->addBuildInfo('form_id', $controller->getFormID());
$child_form_state->addBuildInfo('args', array());
// Copy values to child form.
$child_form_state->setCompleteForm($form_state->getCompleteForm());
$child_form_state->setUserInput($form_state->getUserInput());
// Filter out all submitted values that are not directly relevant for this
// IEF. Otherwise they might mess things up.
$form_state_values = $form_state->getValues();
$form_state_values = static::extractArraySequence($form_state_values, $parents);
$child_form_state->setValues($form_state_values);
$child_form_state->setStorage($form_state->getStorage());
$value = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load($entity->getEntityTypeId() . '.' . $entity->bundle() . '.' . $operation);
$child_form_state->set('form_display', $value);
// Since some of the submit handlers are run, redirects need to be disabled.
$child_form_state->disableRedirect();
// When a form is rebuilt after Ajax processing, its #build_id and #action
// should not change.
// @see drupal_rebuild_form()
$rebuild_info = $child_form_state->getRebuildInfo();
$rebuild_info['copy']['#build_id'] = TRUE;
$rebuild_info['copy']['#action'] = TRUE;
$child_form_state->setRebuildInfo($rebuild_info);
$child_form_state->set('inline_entity_form', $form_state->get('inline_entity_form'));
$child_form_state->set('langcode', $entity->language()->getId());
$child_form_state->set('field', $form_state->get('field'));
$child_form_state->setTriggeringElement($form_state->getTriggeringElement());
$child_form_state->setSubmitHandlers($form_state->getSubmitHandlers());
return $child_form_state;
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
if ($form_state->isRebuilding()) {
$form_state->setUserInput(array());
}
// Initialize
$storage = $form_state->getStorage();
if (empty($storage)) {
$user_input = $form_state->getUserInput();
if (empty($user_input)) {
$_SESSION['constructions'] = 0;
}
// Put the initial thing into the storage
$storage = ['thing' => ['title' => 'none', 'value' => '']];
$form_state->setStorage($storage);
}
// Count how often the form is constructed.
$_SESSION['constructions']++;
drupal_set_message("Form constructions: " . $_SESSION['constructions']);
$form['title'] = array('#type' => 'textfield', '#title' => 'Title', '#default_value' => $storage['thing']['title'], '#required' => TRUE);
$form['value'] = array('#type' => 'textfield', '#title' => 'Value', '#default_value' => $storage['thing']['value'], '#element_validate' => array('::elementValidateValueCached'));
$form['continue_button'] = array('#type' => 'button', '#value' => 'Reset');
$form['continue_submit'] = array('#type' => 'submit', '#value' => 'Continue submit', '#submit' => array('::continueSubmitForm'));
$form['submit'] = array('#type' => 'submit', '#value' => 'Save');
if (\Drupal::request()->get('cache')) {
// Manually activate caching, so we can test that the storage keeps working
// when it's enabled.
$form_state->setCached();
}
if ($this->getRequest()->get('immutable')) {
$form_state->addBuildInfo('immutable', TRUE);
}
return $form;
}
示例3: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
if ($form_state->isRebuilding()) {
$form_state->setUserInput(array());
}
// Initialize
$storage = $form_state->getStorage();
if (empty($storage)) {
$user_input = $form_state->getUserInput();
if (empty($user_input)) {
$_SESSION['constructions'] = 0;
}
// Put the initial thing into the storage
$storage = ['thing' => ['title' => 'none', 'value' => '']];
$form_state->setStorage($storage);
}
// Count how often the form is constructed.
$_SESSION['constructions']++;
drupal_set_message("Form constructions: " . $_SESSION['constructions']);
$form['title'] = array('#type' => 'textfield', '#title' => 'Title', '#default_value' => $storage['thing']['title'], '#required' => TRUE);
$form['value'] = array('#type' => 'textfield', '#title' => 'Value', '#default_value' => $storage['thing']['value'], '#element_validate' => array('::elementValidateValueCached'));
$form['continue_button'] = array('#type' => 'button', '#value' => 'Reset');
$form['continue_submit'] = array('#type' => 'submit', '#value' => 'Continue submit', '#submit' => array('::continueSubmitForm'));
$form['submit'] = array('#type' => 'submit', '#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()->isMethodSafe()) {
$form_state->setRequestMethod('FAKE');
$form_state->setCached();
}
}
return $form;
}
示例4: getForm
/**
* {@inheritdoc}
*/
public function getForm(array &$original_form, FormStateInterface $form_state)
{
$form = [];
// TODO - do we need better error handling for view and view_display (in case
// either of those is nonexistent or display not of correct type)?
$storage =& $form_state->getStorage();
if (empty($storage['selection_display_view']) || $form_state->isRebuilding()) {
$storage['selection_display_view'] = $this->entityManager->getStorage('view')->load($this->configuration['view'])->getExecutable();
}
// TODO - if there are entities that are selected multiple times this displays
// them only once. Reason for that is how SQL and Views work and we probably
// can't do much about it.
if (!empty($this->selectedEntities)) {
$ids = array_map(function (EntityInterface $item) {
return $item->id();
}, $this->selectedEntities);
$storage['selection_display_view']->setArguments([implode(',', $ids)]);
}
$form['view'] = $storage['selection_display_view']->executeDisplay($this->configuration['view_display']);
$form['use_selected'] = array('#type' => 'submit', '#value' => t('Use selection'), '#name' => 'use_selected');
return $form;
}
示例5: automaticStartSubmit
/**
* @param $form_state
*/
protected function automaticStartSubmit(FormStateInterface &$form_state)
{
$config = $this->config('acquia_connector.settings');
$storage = $form_state->getStorage();
if (empty($storage['response']['subscription'])) {
drupal_set_message($this->t('No subscriptions were found for your account.'), 'error');
} elseif (count($storage['response']['subscription']) > 1) {
// Multistep form for choosing from available subscriptions.
$storage['choose'] = TRUE;
// Force rebuild with next step.
$form_state->setRebuild(TRUE);
$form_state->setStorage($storage);
} else {
// One subscription so set id/key pair.
$sub = $storage['response']['subscription'][0];
$config->set('key', $sub['key'])->set('identifier', $sub['identifier'])->set('subscription_name', $sub['name'])->save();
}
}
示例6: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$config = $this->config('honeypot.settings');
$storage = $form_state->getStorage();
// Save all the Honeypot configuration items from $form_state.
foreach ($form_state->getValues() as $key => $value) {
if (in_array($key, $storage['keys'])) {
$config->set($key, $value);
}
}
// Save the honeypot forms from $form_state into a 'form_settings' array.
$config->set('form_settings', $form_state->getValue('form_settings'));
$config->save();
// Clear the honeypot protected forms cache.
\Drupal::cache()->delete('honeypot_protected_forms');
// Tell the user the settings have been saved.
drupal_set_message(t('The configuration options have been saved.'));
}
示例7: setWidgetState
/**
* {@inheritdoc}
*/
public static function setWidgetState(array $parents, $field_name, FormStateInterface $form_state, array $field_state)
{
NestedArray::setValue($form_state->getStorage(), static::getWidgetStateParents($parents, $field_name), $field_state);
}
示例8: setModalState
/**
* {@inheritdoc}
*/
public static function setModalState(FormStateInterface $form_state, array $field_state)
{
NestedArray::setValue($form_state->getStorage(), ['search_results'], $field_state);
}
示例9: submitConfirmForm
/**
* Submission handler for the confirmation form.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitConfirmForm(array &$form, FormStateInterface $form_state)
{
$storage = $form_state->getStorage();
$migrations = $storage['migrations'];
$config['source_base_path'] = $storage['source_base_path'];
$batch = ['title' => $this->t('Running upgrade'), 'progress_message' => '', 'operations' => [[[MigrateUpgradeRunBatch::class, 'run'], [array_keys($migrations), 'import', $config]]], 'finished' => [MigrateUpgradeRunBatch::class, 'finished']];
batch_set($batch);
$form_state->setRedirect('<front>');
$this->state->set('migrate_drupal_ui.performed', REQUEST_TIME);
}
示例10: submitConfirmForm
/**
* Submission handler for the confirmation form.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitConfirmForm(array &$form, FormStateInterface $form_state)
{
$storage = $form_state->getStorage();
if (isset($storage['upgrade_option']) && $storage['upgrade_option'] == static::MIGRATE_UPGRADE_ROLLBACK) {
$query = $this->entityStorage->getQuery();
$names = $query->execute();
// Order the migrations according to their dependencies.
/** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */
$migrations = $this->entityStorage->loadMultiple($names);
// Assume we want all those tagged 'Drupal %'.
foreach ($migrations as $migration_id => $migration) {
$keep = FALSE;
$tags = $migration->get('migration_tags');
foreach ($tags as $tag) {
if (strpos($tag, 'Drupal ') === 0) {
$keep = TRUE;
break;
}
}
if (!$keep) {
unset($migrations[$migration_id]);
}
}
// Roll back in reverse order.
$migrations = array_reverse($migrations);
$batch = ['title' => $this->t('Rolling back upgrade'), 'progress_message' => '', 'operations' => [[[MigrateUpgradeRunBatch::class, 'run'], [array_keys($migrations), 'rollback']]], 'finished' => [MigrateUpgradeRunBatch::class, 'finished']];
batch_set($batch);
$form_state->setRedirect('migrate_upgrade.upgrade');
$this->state->delete('migrate_upgrade.performed');
} else {
$migration_template = $storage['migration_template'];
$migration_ids = $this->createMigrations($migration_template);
$batch = ['title' => $this->t('Running upgrade'), 'progress_message' => '', 'operations' => [[[MigrateUpgradeRunBatch::class, 'run'], [$migration_ids, 'import']]], 'finished' => [MigrateUpgradeRunBatch::class, 'finished']];
batch_set($batch);
$form_state->setRedirect('<front>');
$this->state->set('migrate_upgrade.performed', REQUEST_TIME);
}
}
示例11: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$account = \Drupal::currentUser();
$form = ['#attached' => ['library' => ['webform/webform']]];
$form_state->loadInclude('webform', 'inc', 'includes/webform.components');
$form_state->loadInclude('webform', 'inc', 'includes/webform.submissions');
// For ajax requests, $form_state->getValue('details') is missing. Restore
// from storage, if available, for multi-page forms.
if (empty($form_state->getValue('details')) && !empty($form_state->getValue(['storage', 'details']))) {
$form_state->setValue('details', $form_state->getValue(['storage', 'details']));
}
$node = $this->node;
$submission = $this->node;
$resume_draft = $this->resume_draft;
$filter = $this->filter;
// If in a multi-step form, a submission ID may be specified in form state.
// Load this submission. This allows anonymous users to use auto-save.
if (empty($submission) && !empty($form_state->getValue(['details', 'sid']))) {
$submission = webform_get_submission($node->id(), $form_state->getValue(['details', 'sid']));
}
$finished = isset($submission->is_draft) ? !$submission->is_draft : 0;
$submit_button_text = $finished ? $this->t('Save') : (empty($node->webform['submit_text']) ? $this->t('Submit') : $node->webform['submit_text']);
// Bind arguments to $form to make them available in theming and form_alter.
$form['#node'] = $node;
$form['#submission'] = $submission;
$form['#filter'] = $filter;
// Add a theme function for this form.
$form['#theme'] = ['webform_form_' . $node->id(), 'webform_form'];
// Add a CSS class for all client forms.
$form['#attributes']['class'][] = 'webform-client-form';
$form['#attributes']['class'][] = 'webform-client-form-' . $node->id();
// Set the encoding type (necessary for file uploads).
$form['#attributes']['enctype'] = 'multipart/form-data';
// Sometimes when displaying a webform as a teaser or block, a custom action
// property is set to direct the user to the node page.
if (!empty($node->webform['action'])) {
$form['#action'] = $node->webform['action'];
}
// @todo Convert these to methods.
$form['#submit'] = ['webform_client_form_pages', 'webform_client_form_submit'];
$form['#validate'] = ['webform_client_form_validate'];
// Add includes for used component types and pre/post validation handlers
$form['#process'] = ['webform_client_form_process'];
if (is_array($node->webform['components']) && !empty($node->webform['components'])) {
// Prepare a new form array.
$form['submitted'] = ['#tree' => TRUE];
$form['details'] = ['#tree' => TRUE];
// Put the components into a tree structure.
if (!isset($form_state->getStorage()['component_tree'])) {
$form_state->set(['webform', 'component_tree'], []);
$form_state->set(['webform', 'page_count'], 1);
$form_state->set(['webform', 'page_num'], 1);
_webform_components_tree_build($node->webform['components'], $form_state->get(['webform', 'component_tree']), 0, $form_state->get(['webform', 'page_count']));
// If preview is enabled, increase the page count by one.
if ($node->webform['preview']) {
$form_state->set(['webform', 'page_count'], $form_state->get(['webform', 'page_count']) + 1);
}
$form_state->set(['webform', 'preview'], $node->webform['preview']);
// If this is the first time this draft has been restore and presented
// to the user, let them know that they are looking at a draft, rather
// than a new form. This applies to the node view page, but not to a
// submission edit page (where they presumably know what submission they
// are editing).
if ($resume_draft && empty($form_state->getUserInput())) {
drupal_set_message($this->t('A partially-completed form was found. Please complete the remaining portions.'));
}
} else {
$form_state->set(['webform', 'component_tree'], $form_state->getStorage()['component_tree']);
$form_state->set(['webform', 'page_count'], $form_state->getStorage()['page_count']);
$form_state->set(['webform', 'page_num'], $form_state->getStorage()['page_num']);
$form_state->set(['webform', 'preview'], $form_state->getStorage()['preview']);
}
// Set the input values based on whether we're editing an existing
// submission or not.
$input_values = isset($submission->data) ? $submission->data : [];
// Form state storage override any default submission information. Convert
// the value structure to always be an array, matching $submission->data.
if (isset($form_state->getStorage()['submitted'])) {
foreach ($form_state->getStorage()['submitted'] as $cid => $data) {
$input_values[$cid] = is_array($data) ? $data : [$data];
}
}
// Form state values override any default submission information. Convert
// the value structure to always be an array, matching $submission->data.
if ($form_state->getValue('submitted')) {
foreach ($form_state->getValue('submitted') as $cid => $data) {
$input_values[$cid] = is_array($data) ? $data : [$data];
}
}
// Generate conditional topological order & report any errors.
$sorter = webform_get_conditional_sorter($node);
$sorter->reportErrors();
// Execute the conditionals on the current input values
$input_values = $sorter->executeConditionals($input_values);
// Allow values from other pages to be sent to browser for conditionals.
$form['#conditional_values'] = $input_values;
// Allow components access to most up-to-date values.
//.........这里部分代码省略.........
示例12: buildChildFormState
/**
* Build all necessary things for child form (form state, etc.).
*
* @param \Drupal\Core\Entity\EntityFormInterface $controller
* Entity form controller for child form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Parent form state object.
* @param \Drupal\Core\Entity\EntityInterface $entity
* Entity object.
* @param string $operation
* Operation that is to be performed in inline form.
*
* @return \Drupal\Core\Form\FormStateInterface
* Child form state object.
*/
public static function buildChildFormState(EntityFormInterface $controller, FormStateInterface $form_state, EntityInterface $entity, $operation)
{
$child_form_state = new FormState();
$child_form_state->addBuildInfo('callback_object', $controller);
$child_form_state->addBuildInfo('base_form_id', $controller->getBaseFormID());
$child_form_state->addBuildInfo('form_id', $controller->getFormID());
$child_form_state->addBuildInfo('args', array());
// Copy values to child form.
$child_form_state->setUserInput($form_state->getUserInput());
$child_form_state->setValues($form_state->getValues());
$child_form_state->setStorage($form_state->getStorage());
$child_form_state->set('form_display', entity_get_form_display($entity->getEntityTypeId(), $entity->bundle(), $operation));
// Since some of the submit handlers are run, redirects need to be disabled.
$child_form_state->disableRedirect();
// When a form is rebuilt after Ajax processing, its #build_id and #action
// should not change.
// @see drupal_rebuild_form()
$rebuild_info = $child_form_state->getRebuildInfo();
$rebuild_info['copy']['#build_id'] = TRUE;
$rebuild_info['copy']['#action'] = TRUE;
$child_form_state->setRebuildInfo($rebuild_info);
$child_form_state->set('inline_entity_form', $form_state->get('inline_entity_form'));
$child_form_state->set('langcode', $entity->language()->getId());
$child_form_state->set('field', $form_state->get('field'));
$child_form_state->setTriggeringElement($form_state->getTriggeringElement());
$child_form_state->setSubmitHandlers($form_state->getSubmitHandlers());
return $child_form_state;
}
示例13: moveFormStateStorage
/**
* Moves storage variables from one form state to another.
*
* @param \Drupal\Core\Form\FormStateInterface $from
* The form state object to move from.
* @param \Drupal\Core\Form\FormStateInterface $to
* The form state object to move to.
*/
protected function moveFormStateStorage(FormStateInterface $from, FormStateInterface $to)
{
foreach ($from->getStorage() as $index => $value) {
$to->set($index, $value);
}
}
示例14:
/**
* {@inheritdoc}
*/
public function &getStorage()
{
return $this->decoratedFormState->getStorage();
}