本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::getValue方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::getValue方法的具体用法?PHP FormStateInterface::getValue怎么用?PHP FormStateInterface::getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateName
/**
* Form element validation handler for 'name' in form_test_validate_form().
*/
public function validateName(&$element, FormStateInterface $form_state)
{
$triggered = FALSE;
if ($form_state->getValue('name') == 'element_validate') {
// Alter the form element.
$element['#value'] = '#value changed by #element_validate';
// Alter the submitted value in $form_state.
$form_state->setValueForElement($element, 'value changed by setValueForElement() in #element_validate');
$triggered = TRUE;
}
if ($form_state->getValue('name') == 'element_validate_access') {
$form_state->set('form_test_name', $form_state->getValue('name'));
// Alter the form element.
$element['#access'] = FALSE;
$triggered = TRUE;
} elseif ($form_state->has('form_test_name')) {
// To simplify this test, just take over the element's value into $form_state.
$form_state->setValueForElement($element, $form_state->get('form_test_name'));
$triggered = TRUE;
}
if ($triggered) {
// Output the element's value from $form_state.
drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state->getValue('name'))));
// Trigger a form validation error to see our changes.
$form_state->setErrorByName('');
}
}
示例2: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
// Validate video URL.
if (!UrlHelper::isValid($form_state->getValue('video'), TRUE)) {
$form_state->setErrorByName('video', $this->t("The video url '%url' is invalid.", array('%url' => $form_state->getValue('video'))));
}
}
示例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');
}
}
示例4: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(OrderInterface $order, array &$form, FormStateInterface $form_state)
{
if (!$form_state->isValueEmpty('admin_comment')) {
$uid = \Drupal::currentUser()->id();
uc_order_comment_save($form_state->getValue('order_id'), $uid, $form_state->getValue('admin_comment'));
}
}
示例5: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$html_raw = $this->curl_get($form_state->getValue('url'));
$pattern = '/<div\\s*?class="k-grid-content">.*?<tbody[^>]*>(.*?)<\\/tbody>/msi';
if (!preg_match($pattern, $html_raw, $matches)) {
return;
}
$pattern = '/<a\\s*href="\\/codigo-postal-([^"]*)">/msi';
if (!preg_match_all($pattern, $matches[1], $zipcodes_raw)) {
return;
}
$zipcodes = array();
foreach ($zipcodes_raw[1] as $zipcode_raw) {
$zipcodes[$zipcode_raw] = $zipcode_raw;
}
ksort($zipcodes);
// Build Pairs
$state = $form_state->getValue('state');
$city = $form_state->getValue('city');
$zipcodesb = $zipcodes;
$zipcodes_count = 0;
foreach ($zipcodes as $zipcode_start) {
foreach ($zipcodesb as $zipcode_end) {
// Validate we don't already have it.
if (\Drupal\zipcoderate\Controller\ZipCodeRateController::getRateNode(63175, 63175, false)) {
continue;
}
$zipcodes_count++;
$node = \Drupal\node\Entity\Node::create(['title' => "{$city} {$state} - [{$zipcode_start} - {$zipcode_end}]", 'type' => 'rate', 'field_zipcode_start' => $zipcode_start, 'field_zipcode_end' => $zipcode_end, 'field_state' => $state, 'field_city' => $city]);
$node->save();
}
}
drupal_set_message(t('@zipcodes_count ZipCodes were Imported', array('@zipcodes_count' => $zipcodes_count)), 'status');
}
示例6: checkboxCallback
/**
* Ajax callback triggered by checkbox.
*/
function checkboxCallback($form, FormStateInterface $form_state)
{
$response = new AjaxResponse();
$response->addCommand(new HtmlCommand('#ajax_checkbox_value', (int) $form_state->getValue('checkbox')));
$response->addCommand(new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state->getValue('checkbox')));
return $response;
}
示例7: 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');
}
示例8: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$paypal_config = $this->config('uc_paypal.settings');
$session = \Drupal::service('session');
$order = Order::load($session->get('cart_order'));
if (!$form_state->isValueEmpty('shippable')) {
$quote_option = explode('---', $form_state->getValue(['quotes', 'quote_option']));
$order->quote['method'] = $quote_option[0];
$order->quote['accessorials'] = $quote_option[1];
$method = ShippingQuoteMethod::load($quote_option[0]);
$label = $method['quote']['accessorials'][$quote_option[1]];
// $label = $method->label();
$quote_option = $form_state->getValue(['quotes', 'quote_option']);
$order->quote['rate'] = $form_state->getValue(['quotes', $quote_option, 'rate']);
$result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", [':id' => $order->id(), ':type' => 'shipping']);
if ($lid = $result->fetchField()) {
uc_order_update_line_item($lid, $label, $order->quote['rate']);
} else {
uc_order_line_item_add($order->id(), 'shipping', $label, $order->quote['rate']);
}
}
if ($paypal_config->get('ec_review_company')) {
$order->delivery_company = $form_state->getValue('delivery_company');
}
if ($paypal_config->get('ec_review_phone')) {
$order->delivery_phone = $form_state->getValue('delivery_phone');
}
if ($paypal_config->get('ec_review_comment')) {
db_delete('uc_order_comments')->condition('order_id', $order->id())->execute();
uc_order_comment_save($order->id(), 0, $form_state->getValue('order_comments'), 'order');
}
$order->save();
$form_state->setRedirect('uc_paypal.ec_submit');
}
示例9: validateForm
public function validateForm(array &$form, FormStateInterface $form_state)
{
if ($form_state->getValue('cosign_allow_anons_on_https') == 0 && $form_state->getValue('cosign_allow_cosign_anons') == 1) {
$form_state->setErrorByName('cosign_allow_anons_on_https', $this->t("Cosign users cannot browse anonymously if Anonymous users can't. Set Allow Anonymous Users to browse over https to Yes. OR"));
$form_state->setErrorByName('cosign_allow_cosign_anons', $this->t("Cosign users cannot browse anonymously if Anonymous users can't. Set Allow Cosign Users to browse anonymously to No."));
}
}
示例10: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
module_load_include('inc', 'sociallogin');
$data = get_authentication($form_state->getValue('api_key'), $form_state->getValue('api_secret'));
if (isset($data['status']) && $data['status'] != 'status') {
drupal_set_message($data['message'], $data['status']);
return FALSE;
}
parent::SubmitForm($form, $form_state);
$this->config('sociallogin.settings')->set('sso_site_name', $form_state->getValue('sso_site_name'))->set('api_key', $form_state->getValue('api_key'))->set('api_secret', $form_state->getValue('api_secret'))->set('username_option', $form_state->getValue('username_option'))->set('login_redirection', $form_state->getValue('login_redirection'))->set('register_redirection', $form_state->getValue('register_redirection'))->set('custom_login_url', $form_state->getValue('custom_login_url'))->set('custom_register_url', $form_state->getValue('custom_register_url'))->set('enable_linking', $form_state->getValue('enable_linking'))->set('linking_text', $form_state->getValue('linking_text'))->save();
if (count(\Drupal::moduleHandler()->getImplementations('add_extra_sociallogin_config_settings')) > 0) {
// Call all modules that implement the hook, and let them make changes to $variables.
$config_data = \Drupal::moduleHandler()->invokeAll('add_extra_sociallogin_config_settings');
}
if (isset($config_data) && is_array($config_data)) {
foreach ($config_data as $key => $value) {
$this->config('sociallogin.settings')->set($value, $form_state->getValue($value))->save();
}
}
drupal_set_message(t('Social Login settings have been saved.'), 'status');
//Clear page cache
foreach (Cache::getBins() as $service_id => $cache_backend) {
if ($service_id == 'dynamic_page_cache') {
$cache_backend->deleteAll();
}
}
}
示例11: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
drupal_set_message('Settings saved');
$this->configFactory()->getEditable('itk_instagram_hashtag.settings')->set('itk_instagram_hashtag.client_id', $form_state->getValue('client_id'))->set('itk_instagram_hashtag.resolution', $form_state->getValue('resolution'))->set('itk_instagram_hashtag.sort_by', $form_state->getValue('sort_by'))->set('itk_instagram_hashtag.limit', $form_state->getValue('limit'))->set('itk_instagram_hashtag.enable_caption', $form_state->getValue('enable_caption'))->save();
// Make sure the new settings are available to the js.
\Drupal::cache('render')->deleteAll();
}
示例12: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
global $config_directories, $install_state;
$sync_directory = $form_state->getValue('sync_directory');
if ($sync_directory != config_get_config_directory(CONFIG_SYNC_DIRECTORY)) {
$settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) array('value' => $sync_directory, 'required' => TRUE);
drupal_rewrite_settings($settings);
$config_directories[CONFIG_SYNC_DIRECTORY] = $sync_directory;
}
if ($path = $form_state->getValue('import_tarball')) {
// Ensure that we have an empty directory if we're going.
$sync = new FileStorage($sync_directory);
$sync->deleteAll();
try {
$archiver = new ArchiveTar($path, 'gz');
$files = array();
foreach ($archiver->listContent() as $file) {
$files[] = $file['filename'];
}
$archiver->extractList($files, config_get_config_directory(CONFIG_SYNC_DIRECTORY));
drupal_set_message($this->t('Your configuration files were successfully uploaded, ready for import.'));
} catch (\Exception $e) {
drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())), 'error');
}
drupal_unlink($path);
}
// Change the langcode to the site default langcode provided by the
// configuration.
$config_storage = new FileStorage(config_get_config_directory(CONFIG_SYNC_DIRECTORY));
$install_state['parameters']['langcode'] = $config_storage->read('system.site')['langcode'];
}
示例13: blockSubmit
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state)
{
$this->configuration['registration_link'] = $form_state->getValue('registration_link');
$this->configuration['registration_link_text'] = $form_state->getValue('registration_link_text');
$this->configuration['sponsorship_link'] = $form_state->getValue('sponsorship_link');
$this->configuration['sponsorship_link_text'] = $form_state->getValue('sponsorship_link_text');
}
示例14: blockSubmit
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state)
{
$this->setConfigurationValue('location_forecast', $form_state->getValue(['location', 'location_forecast']));
$this->setConfigurationValue('forecast_fields', $form_state->getValue(['forecast_fields']));
$this->setConfigurationValue('number_of_days', $form_state->getValue(['number_of_days']));
$this->setConfigurationValue('icon_set', $form_state->getValue(['icon_set']));
}
示例15: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$settings = array('standard' => $form_state->getValue('standard'), 'types' => $form_state->getValue('types'));
$this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save();
$this->setRedirect($form_state);
drupal_set_message($this->t('Package assignment configuration saved.'));
}