當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。