本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::getTemporaryValue方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::getTemporaryValue方法的具体用法?PHP FormStateInterface::getTemporaryValue怎么用?PHP FormStateInterface::getTemporaryValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::getTemporaryValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildConfigurationForm
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state)
{
$contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
$form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts);
$form['negate'] = array('#type' => 'checkbox', '#title' => $this->t('Negate the condition'), '#default_value' => $this->configuration['negate']);
return $form;
}
示例2: 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('roles', array_filter($form_state->getValue('roles')));
}
示例3: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$cached_values = $form_state->getTemporaryValue('wizard');
/** @var $page \Drupal\ctools_wizard_test\Entity\ExampleConfigEntity */
$config_entity = $cached_values['ctools_wizard_test_config_entity'];
$config_entity->set('two', $form_state->getValue('two'));
}
示例4: finish
/**
* {@inheritdoc}
*/
public function finish(array &$form, FormStateInterface $form_state)
{
$cached_values = $form_state->getTemporaryValue('wizard');
drupal_set_message($this->t('Value One: @one', ['@one' => $cached_values['one']]));
drupal_set_message($this->t('Value Two: @two', ['@two' => $cached_values['two']]));
parent::finish($form, $form_state);
}
示例5: 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);
}
示例6: 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']]));
}
示例7: add
public function add(array &$form, FormStateInterface $form_state)
{
$condition = $form_state->getValue('conditions');
$content = \Drupal::formBuilder()->getForm($this->getConditionClass(), $condition, $this->getTempstoreId(), $this->machine_name);
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
$cached_values = $form_state->getTemporaryValue('wizard');
list(, $route_parameters) = $this->getOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('conditions'));
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
$response = new AjaxResponse();
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Required Context'), $content, array('width' => '700')));
return $response;
}
示例8: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$cached_values = $form_state->getTemporaryValue('wizard');
$this->machine_name = $cached_values['id'];
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$options = [];
foreach ($this->typedDataManager->getDefinitions() as $plugin_id => $definition) {
$options[$plugin_id] = (string) $definition['label'];
}
$form['items'] = array('#type' => 'markup', '#prefix' => '<div id="configured-contexts">', '#suffix' => '</div>', '#theme' => 'table', '#header' => array($this->t('Information'), $this->t('Description'), $this->t('Operations')), '#rows' => $this->renderContexts($cached_values), '#empty' => t('No required contexts have been configured.'));
$form['contexts'] = ['#type' => 'select', '#options' => $options];
$form['add'] = ['#type' => 'submit', '#name' => 'add', '#value' => t('Add required context'), '#ajax' => ['callback' => [$this, 'add'], 'event' => 'click'], '#submit' => ['callback' => [$this, 'submitform']]];
return $form;
}
示例9: finish
/**
* {@inheritdoc}
*/
public function finish(array &$form, FormStateInterface $form_state)
{
$cached_values = $form_state->getTemporaryValue('wizard');
/** @var $entity \Drupal\Core\Entity\EntityInterface */
$entity = $cached_values[$this->getEntityType()];
$entity->set('id', $cached_values['id']);
$entity->set('label', $cached_values['label']);
$status = $entity->save();
$definition = $this->entityManager->getDefinition($this->getEntityType());
if ($status) {
drupal_set_message($this->t('Saved the %label !entity_type.', array('%label' => $entity->label(), '!entity_type' => $definition->getLabel())));
} else {
drupal_set_message($this->t('The %label !entity_type was not saved.', array('%label' => $entity->label(), '!entity_type' => $definition->getLabel())));
}
$form_state->setRedirectUrl($entity->urlInfo('collection'));
parent::finish($form, $form_state);
}
示例10: buildConfigurationForm
/**
* {@inheritdoc}
*
* Creates a generic configuration form for all block types. Individual
* block plugins can add elements to this form by overriding
* BlockBase::blockForm(). Most block plugins should not override this
* method unless they need to alter the generic form elements.
*
* @see \Drupal\Core\Block\BlockBase::blockForm()
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state)
{
$definition = $this->getPluginDefinition();
$form['provider'] = array('#type' => 'value', '#value' => $definition['provider']);
$form['admin_label'] = array('#type' => 'item', '#title' => $this->t('Block description'), '#plain_text' => $definition['admin_label']);
$form['label'] = array('#type' => 'textfield', '#title' => $this->t('Title'), '#maxlength' => 255, '#default_value' => $this->label(), '#required' => TRUE);
$form['label_display'] = array('#type' => 'checkbox', '#title' => $this->t('Display title'), '#default_value' => $this->configuration['label_display'] === BlockInterface::BLOCK_LABEL_VISIBLE, '#return_value' => BlockInterface::BLOCK_LABEL_VISIBLE);
// Add context mapping UI form elements.
$contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
$form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts);
// Add plugin-specific settings for this block type.
$form += $this->blockForm($form, $form_state);
return $form;
}
示例11: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$cached_values = $form_state->getTemporaryValue('wizard');
list($route_name, $route_parameters) = $this->getOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('contexts'));
$form_state->setRedirect($route_name . '.edit', $route_parameters);
}
示例12: buildConfigurationForm
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state)
{
$embed_button = $form_state->getTemporaryValue('embed_button');
$entity_type_id = $this->getConfigurationValue('entity_type');
$form['entity_type'] = array('#type' => 'select', '#title' => $this->t('Entity type'), '#options' => $this->getEntityTypeOptions(), '#default_value' => $entity_type_id, '#description' => $this->t("Entity type for which this button is to enabled."), '#required' => TRUE, '#ajax' => array('callback' => array($form_state->getFormObject(), 'updateTypeSettings'), 'effect' => 'fade'), '#disabled' => !$embed_button->isNew());
if ($entity_type_id) {
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
$form['bundles'] = array('#type' => 'checkboxes', '#title' => $entity_type->getBundleLabel() ?: $this->t('Bundles'), '#options' => $this->getEntityBundleOptions($entity_type), '#default_value' => $this->getConfigurationValue('bundles'), '#description' => $this->t('If none are selected, all are allowed.'));
$form['bundles']['#access'] = !empty($form['bundles']['#options']);
// Allow option to limit Entity Embed Display plugins.
$form['display_plugins'] = array('#type' => 'checkboxes', '#title' => $this->t('Allowed Entity Embed Display plugins'), '#options' => $this->displayPluginManager->getDefinitionOptionsForEntityType($entity_type_id), '#default_value' => $this->getConfigurationValue('display_plugins'), '#description' => $this->t('If none are selected, all are allowed. Note that these are the plugins which are allowed for this entity type, all of these might not be available for the selected entity.'));
$form['display_plugins']['#access'] = !empty($form['display_plugins']['#options']);
/** @var \Drupal\entity_browser\EntityBrowserInterface[] $browsers */
if ($this->entityTypeManager->hasDefinition('entity_browser') && ($browsers = $this->entityTypeManager->getStorage('entity_browser')->loadMultiple())) {
$ids = array_keys($browsers);
$labels = array_map(function ($item) {
/** @var \Drupal\entity_browser\EntityBrowserInterface $item */
return $item->label();
}, $browsers);
$options = ['_none' => $this->t('None (autocomplete)')] + array_combine($ids, $labels);
$form['entity_browser'] = ['#type' => 'select', '#title' => $this->t('Entity browser'), '#description' => $this->t('Entity browser to be used to select entities to be embedded.'), '#options' => $options, '#default_value' => $this->getConfigurationValue('entity_browser')];
$form['entity_browser_settings'] = ['#type' => 'details', '#title' => $this->t('Entity browser settings'), '#open' => TRUE, '#states' => ['invisible' => [':input[name="type_settings[entity_browser]"]' => ['value' => '_none']]]];
$form['entity_browser_settings']['display_review'] = ['#type' => 'checkbox', '#title' => 'Display the entity after selection', '#default_value' => $this->getConfigurationValue('entity_browser_settings')['display_review']];
} else {
$form['entity_browser'] = ['#type' => 'value', '#value' => ''];
}
}
return $form;
}
示例13: hasTemporaryValue
/**
* {@inheritdoc}
*/
public function hasTemporaryValue($key)
{
return $this->mainFormState->getTemporaryValue($key);
}
示例14: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
/** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */
$entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser'];
$entity_browser->setName($form_state->getValue('id'))->setLabel($form_state->getValue('label'))->setDisplay($form_state->getValue('display'))->setWidgetSelector($form_state->getValue('widget_selector'))->setSelectionDisplay($form_state->getValue('selection_display'));
}
示例15: buildVisibilityInterface
/**
* Helper function for building the visibility UI 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.
*
* @return array
* The form array with the visibility UI added in.
*/
protected function buildVisibilityInterface(array $form, FormStateInterface $form_state)
{
$form['visibility_tabs'] = ['#type' => 'vertical_tabs', '#title' => $this->t('Visibility'), '#parents' => ['visibility_tabs'], '#attached' => ['library' => ['block/drupal.block']]];
// @todo Allow list of conditions to be configured in
// https://www.drupal.org/node/2284687.
$visibility = $this->entity->getVisibility();
foreach ($this->manager->getDefinitionsForContexts($form_state->getTemporaryValue('gathered_contexts')) as $condition_id => $definition) {
// Don't display the current theme condition.
if ($condition_id == 'current_theme') {
continue;
}
// Don't display the language condition until we have multiple languages.
if ($condition_id == 'language' && !$this->language->isMultilingual()) {
continue;
}
/** @var \Drupal\Core\Condition\ConditionInterface $condition */
$condition = $this->manager->createInstance($condition_id, isset($visibility[$condition_id]) ? $visibility[$condition_id] : []);
$form_state->set(['conditions', $condition_id], $condition);
$condition_form = $condition->buildConfigurationForm([], $form_state);
$condition_form['#type'] = 'details';
$condition_form['#title'] = $condition->getPluginDefinition()['label'];
$condition_form['#group'] = 'visibility_tabs';
$form[$condition_id] = $condition_form;
}
if (isset($form['node_type'])) {
$form['node_type']['#title'] = $this->t('Content types');
$form['node_type']['bundles']['#title'] = $this->t('Content types');
$form['node_type']['negate']['#type'] = 'value';
$form['node_type']['negate']['#title_display'] = 'invisible';
$form['node_type']['negate']['#value'] = $form['node_type']['negate']['#default_value'];
}
if (isset($form['user_role'])) {
$form['user_role']['#title'] = $this->t('Roles');
unset($form['user_role']['roles']['#description']);
$form['user_role']['negate']['#type'] = 'value';
$form['user_role']['negate']['#value'] = $form['user_role']['negate']['#default_value'];
}
if (isset($form['request_path'])) {
$form['request_path']['#title'] = $this->t('Pages');
$form['request_path']['negate']['#type'] = 'radios';
$form['request_path']['negate']['#default_value'] = (int) $form['request_path']['negate']['#default_value'];
$form['request_path']['negate']['#title_display'] = 'invisible';
$form['request_path']['negate']['#options'] = [$this->t('Show for the listed pages'), $this->t('Hide for the listed pages')];
}
if (isset($form['language'])) {
$form['language']['negate']['#type'] = 'value';
$form['language']['negate']['#value'] = $form['language']['negate']['#default_value'];
}
return $form;
}