本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::getUserInput方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::getUserInput方法的具体用法?PHP FormStateInterface::getUserInput怎么用?PHP FormStateInterface::getUserInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::getUserInput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$view = $this->entity;
$form['#prefix'] = '<div id="views-preview-wrapper" class="views-admin clearfix">';
$form['#suffix'] = '</div>';
$form['#id'] = 'views-ui-preview-form';
$form_state->disableCache();
$form['controls']['#attributes'] = array('class' => array('clearfix'));
$form['controls']['title'] = array('#prefix' => '<h2 class="view-preview-form__title">', '#markup' => $this->t('Preview'), '#suffix' => '</h2>');
// Add a checkbox controlling whether or not this display auto-previews.
$form['controls']['live_preview'] = array('#type' => 'checkbox', '#id' => 'edit-displays-live-preview', '#title' => $this->t('Auto preview'), '#default_value' => \Drupal::config('views.settings')->get('ui.always_live_preview'));
// Add the arguments textfield
$form['controls']['view_args'] = array('#type' => 'textfield', '#title' => $this->t('Preview with contextual filters:'), '#description' => $this->t('Separate contextual filter values with a "/". For example, %example.', array('%example' => '40/12/10')), '#id' => 'preview-args');
$args = array();
if (!$form_state->isValueEmpty('view_args')) {
$args = explode('/', $form_state->getValue('view_args'));
}
$user_input = $form_state->getUserInput();
if ($form_state->get('show_preview') || !empty($user_input['js'])) {
$form['preview'] = array('#weight' => 110, '#theme_wrappers' => array('container'), '#attributes' => array('id' => 'views-live-preview'), 'preview' => $view->renderPreview($this->displayID, $args));
}
$uri = $view->urlInfo('preview-form');
$uri->setRouteParameter('display_id', $this->displayID);
$form['#action'] = $uri->toString();
return $form;
}
示例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: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
global $base_url;
// Test discovery does not run upon form submission.
simpletest_classloader_register();
// This form accepts arbitrary user input for 'tests'.
// An invalid value will cause the $class_name lookup below to die with a
// fatal error. Regular user access mechanisms to this form are intact.
// The only validation effectively being skipped is the validation of
// available checkboxes vs. submitted checkboxes.
// @todo Refactor Form API to allow to POST values without constructing the
// entire form more easily, BUT retaining routing access security and
// retaining Form API CSRF #token security validation, and without having
// to rely on form caching.
$user_input = $form_state->getUserInput();
if ($form_state->isValueEmpty('tests') && !empty($user_input['tests'])) {
$form_state->setValue('tests', $user_input['tests']);
}
$tests_list = array();
foreach ($form_state->getValue('tests') as $class_name => $value) {
if ($value === $class_name) {
if (is_subclass_of($class_name, 'PHPUnit_Framework_TestCase')) {
$test_type = 'phpunit';
} else {
$test_type = 'simpletest';
}
$tests_list[$test_type][] = $class_name;
}
}
if (!empty($tests_list)) {
putenv('SIMPLETEST_BASE_URL=' . $base_url);
$test_id = simpletest_run_tests($tests_list, 'drupal');
$form_state->setRedirect('simpletest.result_form', array('test_id' => $test_id));
}
}
示例4: valueCallback
/**
* {@inheritdoc}
*/
public static function valueCallback(&$element, $input, FormStateInterface $form_state)
{
if ($input !== FALSE) {
if (!empty($input)) {
// If we're dealing with Mozilla or Opera, we're lucky. It will
// return a proper value, and we can get on with things.
return $element['#return_value'];
} else {
// Unfortunately, in IE we never get back a proper value for THIS
// form element. Instead, we get back two split values: one for the
// X and one for the Y coordinates on which the user clicked the
// button. We'll find this element in the #post data, and search
// in the same spot for its name, with '_x'.
$input = $form_state->getUserInput();
foreach (explode('[', $element['#name']) as $element_name) {
// chop off the ] that may exist.
if (substr($element_name, -1) == ']') {
$element_name = substr($element_name, 0, -1);
}
if (!isset($input[$element_name])) {
if (isset($input[$element_name . '_x'])) {
return $element['#return_value'];
}
return NULL;
}
$input = $input[$element_name];
}
return $element['#return_value'];
}
}
}
示例5: submitForm
public function submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state)
{
// Check to make sure that the file was uploaded to the server properly
$userInputValues = $form_state->getUserInput();
$uri = db_select('file_managed', 'f')->condition('f.fid', $userInputValues['import']['fids'], '=')->fields('f', array('uri'))->execute()->fetchField();
if (!empty($uri)) {
if (file_exists(\Drupal::service("file_system")->realpath($uri))) {
// Open the csv
$handle = fopen(\Drupal::service("file_system")->realpath($uri), "r");
// Go through each row in the csv and run a function on it. In this case we are parsing by '|' (pipe) characters.
// If you want commas are any other character, replace the pipe with it.
while (($data = fgetcsv($handle, 0, ',', '"')) !== FALSE) {
$operations[] = ['csvimport_import_batch_processing', [$data]];
}
// Once everything is gathered and ready to be processed... well... process it!
$batch = ['title' => t('Importing CSV...'), 'operations' => $operations, 'finished' => $this->csvimport_import_finished(), 'error_message' => t('The installation has encountered an error.'), 'progress_message' => t('Imported @current of @total products.')];
batch_set($batch);
fclose($handle);
} else {
drupal_set_message(t('Not able to find file path.'), 'error');
}
} else {
drupal_set_message(t('There was an error uploading your file. Please contact a System administator.'), 'error');
}
}
示例6: clearFormValues
/**
* Clear values from upload form element.
*
* @param array $element
* Upload form element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state object.
*/
protected function clearFormValues(array &$element, FormStateInterface $form_state)
{
// We propagated entities to the other parts of the system. We can now remove
// them from our values.
$form_state->setValueForElement($element['upload']['fids'], '');
NestedArray::setValue($form_state->getUserInput(), $element['upload']['fids']['#parents'], '');
}
示例7: ajaxSubmit
public function ajaxSubmit(array &$form, FormStateInterface $form_state)
{
//---------------------------------------------------------------
// get the own attributes values of the swap
//---------------------------------------------------------------
//get all the swaps plugins
$manager = \Drupal::service('plugin.manager.swaps');
$swaps = $manager->getDefinitions();
$swap = $swaps['column'];
$input = $form_state->getUserInput();
$settings = array();
$settings['size'] = $input['swaps_column_size'];
$settings['number'] = $input['swaps_column_number'];
//---------------------------------------------------------------
// get the default attributes values of the swap (required for visual help)
//---------------------------------------------------------------
$settings['swapId'] = $swap['id'];
$settings['swapName'] = $swap['name'];
$settings['container'] = $swap['container'];
SwapDefaultAttributes::getDefaultFormElementsValues($settings, $input);
//---------------------------------------------------------------
// create the ajax response
//---------------------------------------------------------------
$visualSettings = array('visualContentLayout' => array('attributes' => $settings));
$response = new AjaxResponse();
$response->addCommand(new CloseModalDialogCommand());
$response->addCommand(new SettingsCommand($visualSettings, FALSE));
return $response;
}
示例8: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['one'] = array('#type' => 'textfield', '#title' => 'One', '#required' => TRUE);
$form['two'] = array('#type' => 'textfield', '#title' => 'Two', '#required' => TRUE);
$form['actions'] = array('#type' => 'actions');
$user_input = $form_state->getUserInput();
$form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Save', '#limit_validation_errors' => array(array($user_input['section'])), '#submit' => array(array($this, 'submitForm')));
return $form;
}
示例9: valueForm
protected function valueForm(&$form, FormStateInterface $form_state)
{
$users = $this->value ? User::loadMultiple($this->value) : array();
$default_value = EntityAutocomplete::getEntityLabels($users);
$form['value'] = array('#type' => 'entity_autocomplete', '#title' => $this->t('Usernames'), '#description' => $this->t('Enter a comma separated list of user names.'), '#target_type' => 'user', '#tags' => TRUE, '#default_value' => $default_value, '#process_default_value' => FALSE);
$user_input = $form_state->getUserInput();
if ($form_state->get('exposed') && !isset($user_input[$this->options['expose']['identifier']])) {
$user_input[$this->options['expose']['identifier']] = $default_value;
$form_state->setUserInput($user_input);
}
}
示例10: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$conf_path = './' . conf_path(FALSE);
$settings_file = $conf_path . '/settings.php';
$form['#title'] = $this->t('Database configuration');
$drivers = drupal_get_database_types();
$drivers_keys = array_keys($drivers);
// Unless there is input for this form (for a non-interactive installation,
// input originates from the $settings array passed into install_drupal()),
// check whether database connection settings have been prepared in
// settings.php already.
// Note: The installer even executes this form if there is a valid database
// connection already, since the submit handler of this form is responsible
// for writing all $settings to settings.php (not limited to $databases).
$input =& $form_state->getUserInput();
if (!isset($input['driver']) && ($database = Database::getConnectionInfo())) {
$input['driver'] = $database['default']['driver'];
$input[$database['default']['driver']] = $database['default'];
}
if (isset($input['driver'])) {
$default_driver = $input['driver'];
// In case of database connection info from settings.php, as well as for a
// programmed form submission (non-interactive installer), the table prefix
// information is usually normalized into an array already, but the form
// element only allows to configure one default prefix for all tables.
$prefix =& $input[$default_driver]['prefix'];
if (isset($prefix) && is_array($prefix)) {
$prefix = $prefix['default'];
}
$default_options = $input[$default_driver];
} else {
$default_driver = current($drivers_keys);
$default_options = array();
}
$form['driver'] = array('#type' => 'radios', '#title' => $this->t('Database type'), '#required' => TRUE, '#default_value' => $default_driver);
if (count($drivers) == 1) {
$form['driver']['#disabled'] = TRUE;
}
// Add driver specific configuration options.
foreach ($drivers as $key => $driver) {
$form['driver']['#options'][$key] = $driver->name();
$form['settings'][$key] = $driver->getFormOptions($default_options);
$form['settings'][$key]['#prefix'] = '<h2 class="js-hide">' . $this->t('@driver_name settings', array('@driver_name' => $driver->name())) . '</h2>';
$form['settings'][$key]['#type'] = 'container';
$form['settings'][$key]['#tree'] = TRUE;
$form['settings'][$key]['advanced_options']['#parents'] = array($key);
$form['settings'][$key]['#states'] = array('visible' => array(':input[name=driver]' => array('value' => $key)));
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['save'] = array('#type' => 'submit', '#value' => $this->t('Save and continue'), '#button_type' => 'primary', '#limit_validation_errors' => array(array('driver'), array($default_driver)), '#submit' => array('::submitForm'));
$form['errors'] = array();
$form['settings_file'] = array('#type' => 'value', '#value' => $settings_file);
return $form;
}
示例11: buildForm
/**
* {@inheritdoc}
*
* @param \Drupal\filter\Entity\FilterFormat $filter_format
* The filter format for which this dialog corresponds.
*/
public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL)
{
// This form is special, in that the default values do not come from the
// server side, but from the client side, from a text editor. We must cache
// this data in form state, because when the form is rebuilt, we will be
// receiving values from the form, instead of the values from the text
// editor. If we don't cache it, this data will be lost.
if (isset($form_state->getUserInput()['editor_object'])) {
// By convention, the data that the text editor sends to any dialog is in
// the 'editor_object' key. And the image dialog for text editors expects
// that data to be the attributes for an <img> element.
$file_element = $form_state->getUserInput()['editor_object'];
$form_state->set('file_element', $file_element);
$form_state->setCached(TRUE);
} else {
// Retrieve the image element's attributes from form state.
$file_element = $form_state->get('file_element') ?: [];
}
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'editor/drupal.editor.dialog';
$form['#prefix'] = '<div id="editor-file-dialog-form">';
$form['#suffix'] = '</div>';
// Load dialog settings.
$editor = editor_load($filter_format->id());
$file_upload = $editor->getThirdPartySettings('editor_file');
$max_filesize = min(Bytes::toInt($file_upload['max_size']), file_upload_max_size());
$existing_file = isset($file_element['data-entity-uuid']) ? \Drupal::entityManager()->loadEntityByUuid('file', $file_element['data-entity-uuid']) : NULL;
$fid = $existing_file ? $existing_file->id() : NULL;
$form['fid'] = array('#title' => $this->t('File'), '#type' => 'managed_file', '#upload_location' => $file_upload['scheme'] . '://' . $file_upload['directory'], '#default_value' => $fid ? array($fid) : NULL, '#upload_validators' => array('file_validate_extensions' => !empty($file_upload['extensions']) ? array($file_upload['extensions']) : array('txt'), 'file_validate_size' => array($max_filesize)), '#required' => TRUE);
$form['attributes']['href'] = array('#title' => $this->t('URL'), '#type' => 'textfield', '#default_value' => isset($file_element['href']) ? $file_element['href'] : '', '#maxlength' => 2048, '#required' => TRUE);
if ($file_upload['status']) {
$form['attributes']['href']['#access'] = FALSE;
$form['attributes']['href']['#required'] = FALSE;
} else {
$form['fid']['#access'] = FALSE;
$form['fid']['#required'] = FALSE;
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['save_modal'] = array('#type' => 'submit', '#value' => $this->t('Save'), '#submit' => array(), '#ajax' => array('callback' => '::submitForm', 'event' => 'click'));
return $form;
}
示例12: valueForm
/**
* Provide a simple textfield for equality
*/
protected function valueForm(&$form, FormStateInterface $form_state)
{
$form['value'] = array('#type' => 'textfield', '#title' => $this->t('Value'), '#size' => 30, '#default_value' => $this->value);
if ($exposed = $form_state->get('exposed')) {
$identifier = $this->options['expose']['identifier'];
$user_input = $form_state->getUserInput();
if (!isset($user_input[$identifier])) {
$user_input[$identifier] = $this->value;
$form_state->setUserInput($user_input);
}
}
}
示例13: view
/**
* {@inheritdoc}
*/
public function view(OrderInterface $order, array $form, FormStateInterface $form_state)
{
$contents['#attached']['library'][] = 'uc_payment/uc_payment.styles';
if ($this->configuration['show_preview']) {
$contents['line_items'] = array('#theme' => 'uc_payment_totals', '#order' => $order, '#weight' => -20);
}
// Ensure that the form builder uses #default_value to determine which
// button should be selected after an ajax submission. This is
// necessary because the previously selected value may have become
// unavailable, which would result in an invalid selection.
$input = $form_state->getUserInput();
unset($input['panes']['payment']['payment_method']);
$form_state->setUserInput($input);
$options = array();
$methods = PaymentMethod::loadMultiple();
uasort($methods, 'Drupal\\uc_payment\\Entity\\PaymentMethod::sort');
foreach ($methods as $method) {
// $set = rules_config_load('uc_payment_method_' . $method['id']);
// if ($set && !$set->execute($order)) {
// continue;
// }
if ($method->status()) {
$options[$method->id()] = $method->getDisplayLabel();
}
}
\Drupal::moduleHandler()->alter('uc_payment_method_checkout', $options, $order);
if (!$options) {
$contents['#description'] = $this->t('Checkout cannot be completed without any payment methods enabled. Please contact an administrator to resolve the issue.');
$options[''] = $this->t('No payment methods available');
} elseif (count($options) > 1) {
$contents['#description'] = $this->t('Select a payment method from the following options.');
}
if (!$order->getPaymentMethodId() || !isset($options[$order->getPaymentMethodId()])) {
$order->setPaymentMethodId(key($options));
}
$contents['payment_method'] = array('#type' => 'radios', '#title' => $this->t('Payment method'), '#title_display' => 'invisible', '#options' => $options, '#default_value' => $order->getPaymentMethodId(), '#disabled' => count($options) == 1, '#required' => TRUE, '#ajax' => array('callback' => array($this, 'ajaxRender'), 'wrapper' => 'payment-details', 'progress' => array('type' => 'throbber')));
// If there are no payment methods available, this will be ''.
if ($order->getPaymentMethodId()) {
$plugin = $this->paymentMethodManager->createFromOrder($order);
$definition = $plugin->getPluginDefinition();
$contents['details'] = array('#prefix' => '<div id="payment-details" class="clearfix ' . Html::cleanCssIdentifier('payment-details-' . $definition['id']) . '">', '#markup' => $this->t('Continue with checkout to complete payment.'), '#suffix' => '</div>');
try {
$details = $plugin->cartDetails($order, $form, $form_state);
if ($details) {
unset($contents['details']['#markup']);
$contents['details'] += $details;
}
} catch (PluginException $e) {
}
}
return $contents;
}
示例14: buildForm
/**
* {@inheritdoc}
*
* @param \Drupal\filter\Entity\FilterFormat $filter_format
* The filter format for which this dialog corresponds.
*/
public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL) {
// The default values are set directly from \Drupal::request()->request,
// provided by the editor plugin opening the dialog.
$user_input = $form_state->getUserInput();
$input = isset($user_input['editor_object']) ? $user_input['editor_object'] : [];
/** @var \Drupal\editor\EditorInterface $editor */
$editor = $this->editorStorage->load($filter_format->id());
$linkit_profile_id = $editor->getSettings()['plugins']['linkit']['linkit_profile'];
$this->linkitProfile = $this->linkitProfileStorage->load($linkit_profile_id);
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'editor/drupal.editor.dialog';
$form['#prefix'] = '<div id="linkit-editor-dialog-form">';
$form['#suffix'] = '</div>';
// Everything under the "attributes" key is merged directly into the
// generated link tag's attributes.
$form['attributes']['href'] = [
'#title' => $this->t('Link'),
'#type' => 'linkit',
'#default_value' => isset($input['href']) ? $input['href'] : '',
'#description' => $this->t('Start typing to find content or paste a URL.'),
'#autocomplete_route_name' => 'linkit.autocomplete',
'#autocomplete_route_parameters' => [
'linkit_profile_id' => $linkit_profile_id
],
'#weight' => 0,
];
$this->addAttributes($form, $form_state, $this->linkitProfile->getAttributes());
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['save_modal'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
'#submit' => [],
'#ajax' => [
'callback' => '::submitForm',
'event' => 'click',
],
];
return $form;
}
示例15: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['textfield'] = array('#title' => 'Textfield', '#type' => 'textfield');
$form['checkboxes'] = array('#title' => t('Checkboxes'), '#type' => 'checkboxes', '#options' => array(1 => 'First checkbox', 2 => 'Second checkbox'), '#default_value' => array(1, 2));
$form['field_to_validate'] = array('#type' => 'radios', '#title' => 'Field to validate (in the case of limited validation)', '#description' => 'If the form is submitted by clicking the "Submit with limited validation" button, then validation can be limited based on the value of this radio button.', '#options' => array('all' => 'Validate all fields', 'textfield' => 'Validate the "Textfield" field', 'field_to_validate' => 'Validate the "Field to validate" field'), '#default_value' => 'all');
$form['field_restricted'] = array('#type' => 'textfield', '#title' => 'Textfield (no access)', '#access' => FALSE);
// The main submit button for the form.
$form['submit'] = array('#type' => 'submit', '#value' => 'Submit');
// A secondary submit button that allows validation to be limited based on
// the value of the above radio selector.
$form['submit_limit_validation'] = array('#type' => 'submit', '#value' => 'Submit with limited validation', '#submit' => array('::submitForm'));
$user_input = $form_state->getUserInput();
if (!empty($user_input['field_to_validate']) && $user_input['field_to_validate'] != 'all') {
$form['submit_limit_validation']['#limit_validation_errors'] = array(array($user_input['field_to_validate']));
}
return $form;
}