当前位置: 首页>>代码示例>>PHP>>正文


PHP FormStateInterface::setValue方法代码示例

本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::setValue方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::setValue方法的具体用法?PHP FormStateInterface::setValue怎么用?PHP FormStateInterface::setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Form\FormStateInterface的用法示例。


在下文中一共展示了FormStateInterface::setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: submitOptionsForm

 public function submitOptionsForm(&$form, FormStateInterface $form_state)
 {
     $exposed_form_options = $form_state->getValue('exposed_form_options');
     $form_state->setValue(array('exposed_form_options', 'text_input_required_format'), $exposed_form_options['text_input_required']['format']);
     $form_state->setValue(array('exposed_form_options', 'text_input_required'), $exposed_form_options['text_input_required']['value']);
     parent::submitOptionsForm($form, $form_state);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:7,代码来源:InputRequired.php

示例2: submitOptionsForm

 /**
  * {@inheritdoc}
  */
 public function submitOptionsForm(&$form, FormStateInterface $form_state)
 {
     $content = $form_state->getValue(array('options', 'content'));
     $form_state->setValue(array('options', 'format'), $content['format']);
     $form_state->setValue(array('options', 'content'), $content['value']);
     parent::submitOptionsForm($form, $form_state);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:10,代码来源:Text.php

示例3: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Process the upload and perform validation. Note: we're using the
     // form value for the $replace parameter.
     if (!$form_state->isValueEmpty('file_subdir')) {
         $destination = 'temporary://' . $form_state->getValue('file_subdir');
         file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
     } else {
         $destination = FALSE;
     }
     // Setup validators.
     $validators = array();
     if ($form_state->getValue('is_image_file')) {
         $validators['file_validate_is_image'] = array();
     }
     if ($form_state->getValue('allow_all_extensions')) {
         $validators['file_validate_extensions'] = array();
     } elseif (!$form_state->isValueEmpty('extensions')) {
         $validators['file_validate_extensions'] = array($form_state->getValue('extensions'));
     }
     $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state->getValue('file_test_replace'));
     if ($file) {
         $form_state->setValue('file_test_upload', $file);
         drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri())));
         drupal_set_message(t('File name is @filename.', array('@filename' => $file->getFilename())));
         drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType())));
         drupal_set_message(t('You WIN!'));
     } elseif ($file === FALSE) {
         drupal_set_message(t('Epic upload FAIL!'), 'error');
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:34,代码来源:FileTestForm.php

示例4: save

 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     if (!$form_state->hasValue('context')) {
         $form_state->setValue('context', xmlsitemap_get_current_context());
     }
     if ($form_state->hasValue(['context', 'language'])) {
         $language = $form_state->getValue(['context', 'language']);
         if ($language == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
             $form_state->unsetValue(['context', 'language']);
         }
     }
     $context = $form_state->getValue('context');
     $this->entity->context = $context;
     $this->entity->label = $form_state->getValue('label');
     $this->entity->id = xmlsitemap_sitemap_get_context_hash($context);
     try {
         $status = $this->entity->save();
         if ($status == SAVED_NEW) {
             drupal_set_message($this->t('Saved the %label sitemap.', array('%label' => $this->entity->label())));
         } else {
             if ($status == SAVED_UPDATED) {
                 drupal_set_message($this->t('Updated the %label sitemap.', array('%label' => $this->entity->label())));
             }
         }
     } catch (EntityStorageException $ex) {
         drupal_set_message($this->t('There is another sitemap saved with the same context.'), 'error');
     }
     $form_state->setRedirect('xmlsitemap.admin_search');
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:32,代码来源:XmlSitemapForm.php

示例5: buildForm

 /**
  * Sample UI to update a record.
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Wrap the form in a div.
     $form = array('#prefix' => '<div id="updateform">', '#suffix' => '</div>');
     // Add some explanatory text to the form.
     $form['message'] = array('#markup' => $this->t('Demonstrates a database update operation.'));
     // Query for items to display.
     $entries = \Drupal::service('dbtng.storage')->load();
     // Tell the user if there is nothing to display.
     if (empty($entries)) {
         $form['no_values'] = array('#value' => $this->t('No entries exist in the table dbtng table.'));
         return $form;
     }
     $keyed_entries = array();
     foreach ($entries as $entry) {
         $options[$entry->pid] = t('@pid: @name @surname (@age)', array('@pid' => $entry->pid, '@name' => $entry->name, '@surname' => $entry->surname, '@age' => $entry->age));
         $keyed_entries[$entry->pid] = $entry;
     }
     // Grab the pid.
     $pid = $form_state->getValue('pid');
     // Use the pid to set the default entry for updating.
     $default_entry = !empty($pid) ? $keyed_entries[$pid] : $entries[0];
     // Save the entries into the $form_state. We do this so the AJAX callback
     // doesn't need to repeat the query.
     $form_state->setValue('entries', $keyed_entries);
     $form['pid'] = array('#type' => 'select', '#options' => $options, '#title' => $this->t('Choose entry to update'), '#default_value' => $default_entry->pid, '#ajax' => array('wrapper' => 'updateform', 'callback' => array($this, 'updateCallback')));
     $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Updated first name'), '#size' => 15, '#default_value' => $default_entry->name);
     $form['surname'] = array('#type' => 'textfield', '#title' => $this->t('Updated last name'), '#size' => 15, '#default_value' => $default_entry->surname);
     $form['age'] = array('#type' => 'textfield', '#title' => $this->t('Updated age'), '#size' => 4, '#default_value' => $default_entry->age, '#description' => $this->t('Values greater than 127 will cause an exception'));
     $form['submit'] = array('#type' => 'submit', '#value' => $this->t('Update'));
     return $form;
 }
开发者ID:medion,项目名称:dbtng_example,代码行数:35,代码来源:DBTNGExampleUpdateForm.php

示例6: save

 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $account = $this->entity;
     $account->save();
     $form_state->setValue('uid', $account->id());
     drupal_set_message($this->t('The changes have been saved.'));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:ProfileForm.php

示例7: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $file_upload = $this->getRequest()->files->get('files[import_tarball]', NULL, TRUE);
     $has_upload = FALSE;
     if ($file_upload && $file_upload->isValid()) {
         // The sync directory must be empty if we are doing an upload.
         $form_state->setValue('import_tarball', $file_upload->getRealPath());
         $has_upload = TRUE;
     }
     $sync_directory = $form_state->getValue('sync_directory');
     // If we've customised the sync directory ensure its good to go.
     if ($sync_directory != config_get_config_directory(CONFIG_SYNC_DIRECTORY)) {
         // Ensure it exists and is writeable.
         if (!file_prepare_directory($sync_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
             $form_state->setErrorByName('sync_directory', t('The directory %directory could not be created or could not be made writable. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see the <a href="@handbook_url">online handbook</a>.', array('%directory' => $sync_directory, '@handbook_url' => 'http://drupal.org/server-permissions')));
         }
     }
     // If no tarball ensure we have files.
     if (!$form_state->hasAnyErrors() && !$has_upload) {
         $sync = new FileStorage($sync_directory);
         if (count($sync->listAll()) === 0) {
             $form_state->setErrorByName('sync_directory', t('No file upload provided and the sync directory is empty'));
         }
     }
 }
开发者ID:mkudenko,项目名称:drupal8,代码行数:28,代码来源:SyncConfigureForm.php

示例8: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Get an array of strings with the permissions names.
     $permissions = array_keys(array_filter($form_state->getValue('permissions')));
     $form_state->setValue('permissions', $permissions);
     parent::submitForm($form, $form_state);
 }
开发者ID:mosswoodcreative,项目名称:d8-api-test,代码行数:10,代码来源:AccessTokenResourceForm.php

示例9: testSetValue

 /**
  * @covers ::setValue
  */
 public function testSetValue()
 {
     $key = 'FOO';
     $value = 'BAR';
     $this->decoratedFormState->setValue($key, $value)->shouldBeCalled();
     $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValue($key, $value));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:10,代码来源:FormStateDecoratorBaseTest.php

示例10: validateForm

 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $cors_domains = $form_state->getValue('cors_domains', '');
     if (empty($cors_domains) && $cors_domains != $form['cors_domains']['#default_value']) {
         $form_state->setErrorByName('cors_domains', t('No domains provided.'));
         return;
     }
     $domains = explode("\r\n", $cors_domains);
     $settings = array();
     $errors = null;
     foreach ($domains as $domain) {
         if (empty($domain)) {
             continue;
         }
         $domain = explode("|", $domain, 2);
         if (empty($domain[0]) || empty($domain[1])) {
             $form_state->setErrorByName('cors_domains', t('Contains malformed entry.'));
             $errors = true;
         } else {
             $settings[$domain[0]] = isset($settings[$domain[0]]) ? $settings[$domain[0]] . ' ' : '';
             $settings[$domain[0]] .= trim($domain[1]);
         }
     }
     if ($settings && !$errors) {
         $form_state->setValue('settings', $settings);
     }
 }
开发者ID:nuxy,项目名称:cors,代码行数:27,代码来源:CorsConfigForm.php

示例11: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Replace all contiguous whitespaces (including tabs and newlines) with a
     // single plain space.
     $form_state->setValue(['date_format'], trim(preg_replace('/\\s+/', ' ', $form_state->getValue(['date_format']))));
     // Validate the letters used in the scheduler date format. All punctuation
     // is accepted, so remove everything except word characters then check that
     // there is nothing else which is not in the list of acceptable date/time
     // letters.
     $no_punctuation = preg_replace('/[^\\w+]/', '', $form_state->getValue(['date_format']));
     if (preg_match_all('/[^' . SCHEDULER_DATE_LETTERS . SCHEDULER_TIME_LETTERS . ']/', $no_punctuation, $extra)) {
         $form_state->setErrorByName('date_format', $this->t('You may only use the letters $date_letters for the date and $time_letters for the time. Remove the extra characters $extra', ['$date_letters' => SCHEDULER_DATE_LETTERS, '$time_letters' => SCHEDULER_TIME_LETTERS, '$extra' => implode(' ', $extra[0])]));
     }
     // If date-only is enabled then check if a valid default time was entered.
     // Leading zeros and seconds can be omitted, eg. 6:30 is considered valid.
     if ($form_state->getValue(['allow_date_only'])) {
         $default_time = date_parse($form_state->getValue(['default_time']));
         if ($default_time['error_count']) {
             $form_state->setErrorByName('default_time', $this->t('The default time should be in the format HH:MM:SS'));
         } else {
             // Insert any possibly omitted leading zeroes.
             $unix_time = mktime($default_time['hour'], $default_time['minute'], $default_time['second']);
             $form_state->setValue(['default_time'], $this->dateFormatter->format($unix_time, 'custom', 'H:i:s'));
         }
     }
     // Check that either the date format has a time part or the date-only option
     // is turned on.
     $time_format = $this->getTimeOnlyFormat($form_state->getValue(['date_format']));
     if ($time_format == '' && !$form_state->getValue(['allow_date_only'])) {
         $form_state->setErrorByName('date_format', $this->t('You must either include a time within the date format or enable the date-only option.'));
     }
 }
开发者ID:blakefrederick,项目名称:sas-backend,代码行数:35,代码来源:SchedulerAdminForm.php

示例12: submitConfigurationForm

 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('aircraft_type') === 'helicopters') {
         drupal_set_message($this->t('Helicopters are just rotorcraft.'), 'warning');
         $form_state->setValue('aircraft_type', 'rotorcraft');
     }
     parent::submitConfigurationForm($form, $form_state);
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:11,代码来源:Aircraft.php

示例13: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $plugin_settings = (new FormState())->setValues($form_state->getValue('key_settings'));
     $plugin = $this->manager->createInstance($form_state->getValue('key_provider'), []);
     $plugin->submitConfigurationForm($form, $plugin_settings);
     $form_state->setValue('key_settings', $plugin->getConfiguration());
     parent::submitForm($form, $form_state);
 }
开发者ID:nerdstein,项目名称:key,代码行数:11,代码来源:KeyForm.php

示例14: buildEntity

 /**
  * {@inheritdoc}
  */
 public function buildEntity(array $form, FormStateInterface $form_state)
 {
     // Save period.
     $type = Schedule::getPeriodType($form_state->getValue('period_type'));
     $seconds = Schedule::periodToSeconds(['number' => $form_state->getValue('period_number'), 'type' => $type]);
     $form_state->setValue('period', $seconds);
     return parent::buildEntity($form, $form_state);
 }
开发者ID:r-daneelolivaw,项目名称:chalk,代码行数:11,代码来源:ScheduleForm.php

示例15: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     if ($form_state->hasValue('date')) {
         $userInput = $form_state->getUserInput();
         $userInput['result'] = 'Date Set';
         $form_state->setUserInput($userInput);
     } else {
         $form_state->setValue('date', date('Y-m-d', REQUEST_TIME));
         $form_state->setValue('result', 'date not set');
         $result = 'Date Not Set';
     }
     $form['ajax_wrapper'] = ['#type' => 'container', '#attributes' => ['id' => 'ajax_wrapper']];
     $form['ajax_wrapper']['date'] = ['#type' => 'date', '#title' => $this->t('Date')];
     $form['ajax_wrapper']['submit_button'] = ['#type' => 'submit', '#value' => 'Load', '#ajax' => ['callback' => [$this, 'ajaxFormCallback']]];
     $form['ajax_wrapper']['result'] = ['#type' => 'textfield', '#title' => $this->t('Result'), '#default_value' => $result];
     return $form;
 }
开发者ID:mgrimard,项目名称:drupal8_ajax_form,代码行数:20,代码来源:AjaxForm.php


注:本文中的Drupal\Core\Form\FormStateInterface::setValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。