本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::setTemporaryValue方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::setTemporaryValue方法的具体用法?PHP FormStateInterface::setTemporaryValue怎么用?PHP FormStateInterface::setTemporaryValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::setTemporaryValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$cached_values = $form_state->getTemporaryValue('wizard');
/** @var $policy \Drupal\password_policy\Entity\PasswordPolicy */
$policy = $cached_values['password_policy'];
$policy->set('password_reset', $form_state->getValue('password_reset'));
$form_state->setTemporaryValue('wizard', $cached_values);
}
示例2: stepOneSubmit
/**
* Submission callback for the first step.
*/
public function stepOneSubmit($form, FormStateInterface $form_state)
{
$cached_values = $form_state->getTemporaryValue('wizard');
if ($form_state->getValue('one') == 'magic') {
$cached_values['one'] = 'Abraham';
}
$form_state->setTemporaryValue('wizard', $cached_values);
}
示例3: submitForm
/**
* Form submission handler.
*
* @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 submitForm(array &$form, FormStateInterface $form_state)
{
$keys = array('two');
$cached_values = $form_state->getTemporaryValue('wizard');
foreach ($keys as $key) {
$cached_values[$key] = $form_state->getValue($key);
}
$form_state->setTemporaryValue('wizard', $cached_values);
}
示例4: submitForm
/**
* Form submission handler.
*
* @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 submitForm(array &$form, FormStateInterface $form_state)
{
$keys = array('one');
$cached_values = $form_state->getTemporaryValue('wizard');
foreach ($keys as $key) {
$cached_values[$key] = $form_state->getValue($key);
}
$form_state->setTemporaryValue('wizard', $cached_values);
drupal_set_message($this->t('Dynamic value submitted: @value', ['@value' => $cached_values['dynamic']]));
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $condition = NULL, $tempstore_id = NULL, $machine_name = NULL)
{
$this->tempstore_id = $tempstore_id;
$this->machine_name = $machine_name;
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
if (is_numeric($condition)) {
$id = $condition;
$condition = $this->getConditions($cached_values)[$id];
$instance = $this->manager->createInstance($condition['id'], $condition);
} else {
$instance = $this->manager->createInstance($condition, []);
}
$form_state->setTemporaryValue('gathered_contexts', $this->getContexts($cached_values));
/** @var $instance \Drupal\Core\Condition\ConditionInterface */
$form = $instance->buildConfigurationForm($form, $form_state);
if (isset($id)) {
// Conditionally set this form element so that we can update or add.
$form['id'] = ['#type' => 'value', '#value' => $id];
}
$form['instance'] = ['#type' => 'value', '#value' => $instance];
$form['submit'] = ['#type' => 'submit', '#value' => $this->t('Save'), '#ajax' => ['callback' => [$this, 'ajaxSave']]];
return $form;
}
示例6: populateCachedValues
/**
* {@inheritdoc}
*/
public function populateCachedValues(array &$form, FormStateInterface $form_state)
{
$cached_values = $this->getTempstore()->get($this->getMachineName());
if (!$cached_values) {
$cached_values = $form_state->getTemporaryValue('wizard');
if (!$cached_values) {
$cached_values = $this->initValues();
$form_state->setTemporaryValue('wizard', $cached_values);
}
}
}
示例7: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, BlockVisibilityGroupInterface $block_visibility_group = NULL, $condition_id = NULL, $redirect = NULL) {
$this->block_visibility_group = $block_visibility_group;
$this->condition = $this->prepareCondition($condition_id);
$this->setRedirectValue($form, $redirect);
// Store the gathered contexts in the form state for other objects to use
// during form building.
$form_state->setTemporaryValue('gathered_contexts', $this->contextRepository->getAvailableContexts());
// Allow the condition to add to the form.
$form['condition'] = $this->condition->buildConfigurationForm([], $form_state);
$form['condition']['#tree'] = TRUE;
$form['actions'] = ['#type' => 'actions'];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->submitButtonText(),
'#button_type' => 'primary',
];
return $form;
}
示例8: setTemporaryValue
/**
* {@inheritdoc}
*/
public function setTemporaryValue($key, $value)
{
$this->mainFormState->setTemporaryValue($key, $value);
return $this;
}
示例9: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$entity = $this->entity;
// Store theme settings in $form_state for use below.
if (!($theme = $entity->getTheme())) {
$theme = $this->config('system.theme')->get('default');
}
$form_state->set('block_theme', $theme);
// Store the gathered contexts in the form state for other objects to use
// during form building.
$form_state->setTemporaryValue('gathered_contexts', $this->contextRepository->getAvailableContexts());
$form['#tree'] = TRUE;
$form['settings'] = [];
$subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
$form['settings'] = $this->getPluginForm($entity->getPlugin())->buildConfigurationForm($form['settings'], $subform_state);
$form['visibility'] = $this->buildVisibilityInterface([], $form_state);
// If creating a new block, calculate a safe default machine name.
$form['id'] = array('#type' => 'machine_name', '#maxlength' => 64, '#description' => $this->t('A unique name for this block instance. Must be alpha-numeric and underscore separated.'), '#default_value' => !$entity->isNew() ? $entity->id() : $this->getUniqueMachineName($entity), '#machine_name' => array('exists' => '\\Drupal\\block\\Entity\\Block::load', 'replace_pattern' => '[^a-z0-9_.]+', 'source' => array('settings', 'label')), '#required' => TRUE, '#disabled' => !$entity->isNew());
// Theme settings.
if ($entity->getTheme()) {
$form['theme'] = array('#type' => 'value', '#value' => $theme);
} else {
$theme_options = array();
foreach ($this->themeHandler->listInfo() as $theme_name => $theme_info) {
if (!empty($theme_info->status)) {
$theme_options[$theme_name] = $theme_info->info['name'];
}
}
$form['theme'] = array('#type' => 'select', '#options' => $theme_options, '#title' => t('Theme'), '#default_value' => $theme, '#ajax' => array('callback' => '::themeSwitch', 'wrapper' => 'edit-block-region-wrapper'));
}
// Hidden weight setting.
$weight = $entity->isNew() ? $this->getRequest()->query->get('weight', 0) : $entity->getWeight();
$form['weight'] = array('#type' => 'hidden', '#default_value' => $weight);
// Region settings.
$entity_region = $entity->getRegion();
$region = $entity->isNew() ? $this->getRequest()->query->get('region', $entity_region) : $entity_region;
$form['region'] = array('#type' => 'select', '#title' => $this->t('Region'), '#description' => $this->t('Select the region where this block should be displayed.'), '#default_value' => $region, '#empty_value' => BlockInterface::BLOCK_REGION_NONE, '#options' => system_region_list($theme, REGIONS_VISIBLE), '#prefix' => '<div id="edit-block-region-wrapper">', '#suffix' => '</div>');
$form['#attached']['library'][] = 'block/drupal.block.admin';
return $form;
}
示例10: buildConfigurationForm
/**
*
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$block_visibility_groups = $this->entityStorage->loadMultiple();
$options = ['' => $this->t('No Block Visibility Group')];
foreach ($block_visibility_groups as $type) {
$options[$type->id()] = $type->label();
}
$form['block_visibility_group'] = array(
'#title' => $this->t('Block Visibility Groups'),
'#type' => 'select',
'#options' => $options,
// '#default_value' => $default,.
);
$default = isset($this->configuration['block_visibility_group']) ? $this->configuration['block_visibility_group'] : '';
if (!$default) {
$default = $this->request->query->get('block_visibility_group');
if ($default) {
$form['block_visibility_group']['#disabled'] = TRUE;
$form_state->setTemporaryValue('block_visibility_group_query', $default);
}
}
$form['block_visibility_group']['#default_value'] = $default;
// TODO: Change the autogenerated stub.
$form = parent::buildConfigurationForm($form, $form_state);
$form['negate']['#access'] = FALSE;
return $form;
}
示例11: buildForm
/**
* Form constructor.
*
* @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.
* @param null $block_id
* The id of the block to place.
*
* @return array The form structure.
* The form structure.
*/
public function buildForm(array $form, FormStateInterface $form_state, $block_id = NULL)
{
$this->entityLayout = $this->getEntityLayoutFromRouteMatch();
$this->block = $this->prepareBlock($block_id);
// Some blocks require contexts, set a temporary value with gathered
// contextual values.
$form_state->setTemporaryValue('gathered_contexts', $this->contextRepository->getAvailableContexts());
$form['#tree'] = TRUE;
$form['settings'] = $this->block->buildConfigurationForm([], $form_state);
$form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->t('Save block'), '#button_type' => 'primary'];
return $form;
}
示例12: buildForm
/**
* Form constructor.
*
* @param array $form
* An associative array containing the structure of the form.
* @param FormStateInterface $form_state
* The current state of the form.
* @param MegaMenuInterface $mega_menu
* The mega menu the block should be added to.
* @param string|null $block_id
* The ID of the block to show a configuration form for.
*
* @return array
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, MegaMenuInterface $mega_menu = NULL, $block_id = NULL)
{
$this->megaMenu = $mega_menu;
// Get the query parameters needed.
$form_state->set('link', $request->query->get('link'));
$form_state->set('region', $request->query->get('region'));
$this->block = $this->prepareBlock($form_state->get('link'), $block_id);
// Some blocks require contexts, set a temporary value with gathered
// contextual values.
$form_state->setTemporaryValue('gathered_contexts', $this->contextRepository->getAvailableContexts());
$form['#tree'] = TRUE;
$form['settings'] = $this->block->buildConfigurationForm([], $form_state);
$form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->getSubmitValue(), '#button_type' => 'primary'];
return $form;
}
示例13: testSetTemporaryValue
/**
* @covers ::setTemporaryValue
*
* @dataProvider providerSetTemporaryValue
*
* @param string $key
* @param mixed $value
*/
public function testSetTemporaryValue($key, $value)
{
$this->decoratedFormState->setTemporaryValue($key, $value)->shouldBeCalled();
$this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setTemporaryValue($key, $value));
}
示例14: stepOneSubmit
/**
* Submission callback for the first step.
*/
public function stepOneSubmit($form, FormStateInterface $form_state)
{
// Increment the internal step counter.
$this->step++;
$cached_values = $form_state->getTemporaryValue('wizard');
$parameters = $this->getNextParameters($cached_values);
// This is validated in EmbridgeSearchForm::validateForm().
$result_chosen = $form_state->getUserInput()['result_chosen'];
$asset = EmbridgeAssetEntity::load($result_chosen);
$image_element = ['src' => \Drupal::getContainer()->get('embridge.asset_helper')->getAssetConversionUrl($asset, 'emshare', 'thumb'), 'data-entity-uuid' => $asset->uuid(), 'data-entity-type' => 'embridge_asset_entity', 'alt' => '', 'width' => '', 'height' => ''];
$parameters['image_element'] = $image_element;
$form_state->setTemporaryValue('wizard', $parameters);
$form_state->setRebuild();
}