/**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getTriggeringElement()['#name'] == 'select_id_submit') {
         $form_state->set('default_type', $form_state->getValue('id'));
         $form_state->setRebuild();
     } else {
         parent::submitForm($form, $form_state);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     $taxType = $this->taxTypeImporter->createTaxType($values['tax_type']);
     try {
         $taxType->save();
         drupal_set_message($this->t('Imported the %label tax type.', ['%label' => $taxType->label()]));
         $triggeringElement['#name'] = $form_state->getTriggeringElement();
         if ($triggeringElement['#name'] == 'import_and_new') {
             $form_state->setRebuild();
         } else {
             $form_state->setRedirect('entity.commerce_tax_type.collection');
         }
     } catch (\Exception $e) {
         drupal_set_message($this->t('The %label tax type was not imported.', ['%label' => $taxType->label()]), 'error');
         $this->logger('commerce_tax')->error($e);
         $form_state->setRebuild();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_connection_settings = $form_state->getValue('connection_settings');
     switch ($form_state->getTriggeringElement()['#name']) {
         case 'process_updates':
             // Save the connection settings to the DB.
             $filetransfer_backend = $form_connection_settings['authorize_filetransfer_default'];
             // If the database is available then try to save our settings. We have
             // to make sure it is available since this code could potentially (will
             // likely) be called during the installation process, before the
             // database is set up.
             try {
                 $connection_settings = array();
                 foreach ($form_connection_settings[$filetransfer_backend] as $key => $value) {
                     // We do *not* want to store passwords in the database, unless the
                     // backend explicitly says so via the magic #filetransfer_save form
                     // property. Otherwise, we store everything that's not explicitly
                     // marked with #filetransfer_save set to FALSE.
                     if (!isset($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save'])) {
                         if ($form['connection_settings'][$filetransfer_backend][$key]['#type'] != 'password') {
                             $connection_settings[$key] = $value;
                         }
                     } elseif ($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save']) {
                         $connection_settings[$key] = $value;
                     }
                 }
                 // Set this one as the default authorize method.
                 $this->config('system.authorize')->set('filetransfer_default', $filetransfer_backend);
                 // Save the connection settings minus the password.
                 $this->config('system.authorize')->set('filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings);
                 $filetransfer = $this->getFiletransfer($filetransfer_backend, $form_connection_settings[$filetransfer_backend]);
                 // Now run the operation.
                 $this->runOperation($filetransfer);
             } catch (\Exception $e) {
                 // If there is no database available, we don't care and just skip
                 // this part entirely.
             }
             break;
         case 'enter_connection_settings':
             $form_state->setRebuild();
             break;
         case 'change_connection_type':
             $form_state->setRebuild();
             $form_state->unsetValue(array('connection_settings', 'authorize_filetransfer_default'));
             break;
     }
 }
Example #4
1
 /**
  * Order pane submit callback: Remove a line item from an order.
  */
 public function removeLineItem($form, FormStateInterface $form_state)
 {
     $order =& $form_state->get('order');
     $triggering_element = $form_state->getTriggeringElement();
     $line_item_id = intval($triggering_element['#return_value']);
     uc_order_delete_line_item($line_item_id);
     $order->line_items = $order->getLineItems();
     $form_state->setRebuild();
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     try {
         $entity = $this->entity;
         // Save as a new revision if requested to do so.
         if (!$form_state->isValueEmpty('revision')) {
             $entity->setNewRevision();
         }
         $is_new = $entity->isNew();
         $entity->save();
         if ($is_new) {
             $message = t('%entity_type @id has been created.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()));
         } else {
             $message = t('%entity_type @id has been updated.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()));
         }
         drupal_set_message($message);
         if ($entity->id()) {
             $entity_type = $entity->getEntityTypeId();
             $form_state->setRedirect("entity.{$entity_type}.edit_form", array($entity_type => $entity->id()));
         } else {
             // Error on save.
             drupal_set_message(t('The entity could not be saved.'), 'error');
             $form_state->setRebuild();
         }
     } catch (\Exception $e) {
         \Drupal::state()->set('entity_test.form.save.exception', get_class($e) . ': ' . $e->getMessage());
     }
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $currency_code = $form_state->getValue('currency_code');
     $currency = $this->importer->import($currency_code);
     drupal_set_message($this->t('Imported the %label currency.', ['%label' => $currency->label()]));
     $form_state->setRebuild();
 }
 public function save(array $form, FormStateInterface $form_state) {
   if ($this->entity->getEFormType()->preview_page) {
     $form_state->set('preview_entity', $this->entity);
     $form_state->setRebuild();
   }
   return parent::save($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $currency_codes = $form_state->getValue('currency_codes');
     foreach ($currency_codes as $currency_code) {
         $this->importer->import($currency_code);
     }
     drupal_set_message($this->t('Imported the selected currencies.'));
     $form_state->setRebuild();
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_state->setCached();
     $form_state->setRebuild();
     $database_class = $form_state->get('database_class');
     if ($form_state->get('database') instanceof $database_class) {
         $form_state->set('database_connection_found', TRUE);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('add_files')) {
         $path = drupal_get_path('module', 'system');
         $attached = array('#attached' => array('css' => array($path . '/css/system.admin.css' => array()), 'js' => array(0 => array('type' => 'setting', 'data' => array('ajax_forms_test_lazy_load_form_submit' => 'executed')), $path . '/system.js' => array())));
         drupal_render($attached);
         drupal_process_attached($attached);
     }
     $form_state->setRebuild();
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($this->step < 3) {
         $form_state->setRebuild();
         $this->step++;
     } else {
         parent::submitForm($form, $form_state);
         /*$this->config('multi_step.multi_step_form_config')
             ->set('model', $form_state->getValue('model'))
             ->set('body_style', $form_state->getValue('body_style'))
             ->set('gas_mileage', $form_state->getValue('gas_mileage'))
           ->save();*/
     }
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     batch_test_stack(NULL, TRUE);
     $step = $form_state->get('step');
     switch ($step) {
         case 1:
             batch_set(_batch_test_batch_1());
             break;
         case 2:
             batch_set(_batch_test_batch_2());
             break;
     }
     if ($step < 2) {
         $form_state->set('step', ++$step);
         $form_state->setRebuild();
     }
     $form_state->setRedirect('batch_test.redirect');
 }
 /**
  * Form element submit handler for mollom_test_form().
  */
 function fieldSubmitForm(array &$form, FormStateInterface $form_state)
 {
     // Remove all empty values of the multiple value field.
     $form_state->setValue('field', array_filter($form_state->getValue('field')));
     // Update the storage with submitted values.
     $storage_record = $form_state->getValues();
     // Store the new value and clear out the 'new' field.
     $new_field = $form_state->getValue(array('field', 'new'), '');
     if (!empty($new_field)) {
         $storage_record['field'][] = $form_state->getValue(array('field', 'new'));
         $form_state->setValue(array('field', 'new'), '');
         $storage_record['field']['new'] = '';
         unset($storage_record['field']['add']);
         $input = $form_state->getUserInput();
         $input['field']['new'] = '';
         $form_state->setUserInput($input);
     }
     $form_state->set('mollom_test', $storage_record);
     $form_state->setRebuild(TRUE);
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $workspace = $this->entity;
     $insert = $workspace->isNew();
     $workspace->save();
     $info = ['%info' => $workspace->label()];
     $context = array('@type' => $workspace->bundle(), $info);
     $logger = $this->logger('multiversion');
     if ($insert) {
         $logger->notice('@type: added %info.', $context);
         drupal_set_message($this->t('Workspace %info has been created.', $info));
     } else {
         $logger->notice('@type: updated %info.', $context);
         drupal_set_message($this->t('Workspace %info has been updated.', $info));
     }
     if ($workspace->id()) {
         $form_state->setValue('id', $workspace->id());
         $form_state->set('id', $workspace->id());
         $form_state->setRedirectUrl($workspace->urlInfo('collection'));
     } else {
         drupal_set_message($this->t('The workspace could not be saved.'), 'error');
         $form_state->setRebuild();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $field_collection_item = $this->getEntity();
     if ($field_collection_item->isNew()) {
         $host = $this->entityTypeManager->getStorage($this->getRequest()->get('host_type'))->load($this->getRequest()->get('host_id'));
         $field_collection_item->setHostEntity($host);
         $field_collection_item->save();
         $host->save();
         $messages = drupal_get_messages(NULL, false);
         if (!isset($messages['warning']) && !isset($messages['error'])) {
             drupal_set_message(t('Successfully added a @type.', array('@type' => $field_collection_item->bundle())));
         }
     } else {
         $messages = drupal_get_messages(NULL, false);
         if (!isset($messages['warning']) && !isset($messages['error'])) {
             $field_collection_item->save();
             drupal_set_message(t('Successfully edited %label.', array('%label' => $field_collection_item->label())));
         }
     }
     if ($field_collection_item->id()) {
         $form_state->setValue('id', $field_collection_item->id());
         $form_state->set('id', $field_collection_item->id());
     } else {
         // In the unlikely case something went wrong on save, the block will be
         // rebuilt and block form redisplayed.
         drupal_set_message(t('The field collection item could not be saved.'), 'error');
         $form_state->setRebuild();
     }
     /*
     $form_state->setRedirect(
       'field_collection_item.view',
       array('field_collection_item' => $field_collection_item->id()
     ));
     */
 }
Example #16
0
 /**
  * Credential 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 submitCredentialForm(array &$form, FormStateInterface $form_state)
 {
     // Indicate the next step is confirmation.
     $form_state->setValue('step', 'confirm');
     $form_state->setRebuild();
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $block = $this->entity;
     // Save as a new revision if requested to do so.
     if (!$form_state->isValueEmpty('revision')) {
         $block->setNewRevision();
     }
     $insert = $block->isNew();
     $block->save();
     $context = array('@type' => $block->bundle(), '%info' => $block->label());
     $logger = $this->logger('block_content');
     $block_type = $this->blockContentTypeStorage->load($block->bundle());
     $t_args = array('@type' => $block_type->label(), '%info' => $block->label());
     if ($insert) {
         $logger->notice('@type: added %info.', $context);
         drupal_set_message($this->t('@type %info has been created.', $t_args));
     } else {
         $logger->notice('@type: updated %info.', $context);
         drupal_set_message($this->t('@type %info has been updated.', $t_args));
     }
     if ($block->id()) {
         $form_state->setValue('id', $block->id());
         $form_state->set('id', $block->id());
         if ($insert) {
             if (!($theme = $block->getTheme())) {
                 $theme = $this->config('system.theme')->get('default');
             }
             $form_state->setRedirect('block.admin_add', array('plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme));
         } else {
             $form_state->setRedirectUrl($block->urlInfo('collection'));
         }
     } else {
         // In the unlikely case something went wrong on save, the block will be
         // rebuilt and block form redisplayed.
         drupal_set_message($this->t('The block could not be saved.'), 'error');
         $form_state->setRebuild();
     }
 }
Example #18
0
 public function squad_ajax_remove_player(array &$form, FormStateInterface $form_state)
 {
     /***
      * Remove a player to the container
      */
     $players = $form_state->getValue('players', 0);
     // Checks if more then 1 player is in the value
     $players == 1 ?: $form_state->setValue('players', $players - 1);
     $form_state->setRebuild();
 }
 /**
  * Add a new group to the exposed filter groups.
  */
 public function addGroupForm($form, FormStateInterface $form_state)
 {
     $item =& $this->options;
     // Add a new row.
     $item['group_info']['group_items'][] = array();
     $view = $form_state->get('view');
     $display_id = $form_state->get('display_id');
     $type = $form_state->get('type');
     $id = $form_state->get('id');
     $view->getExecutable()->setHandler($display_id, $type, $id, $item);
     $view->cacheSet();
     $form_state->set('rerender', TRUE);
     $form_state->setRebuild();
     $form_state->get('force_build_group_options', TRUE);
 }
Example #20
0
 public function resetForm(&$form, FormStateInterface $form_state)
 {
     // _SESSION is not defined for users who are not logged in.
     // If filters are not overridden, store the 'remember' settings on the
     // default display. If they are, store them on this display. This way,
     // multiple displays in the same view can share the same filters and
     // remember settings.
     $display_id = $this->view->display_handler->isDefaulted('filters') ? 'default' : $this->view->current_display;
     if (isset($_SESSION['views'][$this->view->storage->id()][$display_id])) {
         unset($_SESSION['views'][$this->view->storage->id()][$display_id]);
     }
     // Set the form to allow redirect.
     if (empty($this->view->live_preview) && !\Drupal::request()->isXmlHttpRequest()) {
         $form_state->disableRedirect(FALSE);
     } else {
         $form_state->setRebuild();
         $this->view->exposed_data = array();
     }
     $form_state->setRedirect('<current>');
     $form_state->setValues([]);
 }
Example #21
0
 /**
  * Displays the Expose form.
  */
 public function displayExposedForm($form, FormStateInterface $form_state)
 {
     $item =& $this->options;
     // flip
     $item['exposed'] = empty($item['exposed']);
     // If necessary, set new defaults:
     if ($item['exposed']) {
         $this->defaultExposeOptions();
     }
     $view = $form_state->get('view');
     $display_id = $form_state->get('display_id');
     $type = $form_state->get('type');
     $id = $form_state->get('id');
     $view->getExecutable()->setHandler($display_id, $type, $id, $item);
     $view->addFormToStack($form_state->get('form_key'), $display_id, $type, $id, TRUE, TRUE);
     $view->cacheSet();
     $form_state->set('rerender', TRUE);
     $form_state->setRebuild();
     $form_state->set('force_expose_options', TRUE);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // If this form has not yet been confirmed, store the values and rebuild.
     if (!$this->data) {
         $form_state->setRebuild();
         $this->data = $form_state->getValues();
         return;
     }
     // If a simple configuration file was added, set the data and save.
     if ($this->data['config_type'] === 'system.simple') {
         $this->configFactory()->getEditable($this->data['config_name'])->setData($this->data['import'])->save();
         drupal_set_message($this->t('The %name configuration was imported.', array('%name' => $this->data['config_name'])));
     } else {
         try {
             $entity_storage = $this->entityManager->getStorage($this->data['config_type']);
             if ($this->configExists) {
                 $entity = $entity_storage->updateFromStorageRecord($this->configExists, $this->data['import']);
             } else {
                 $entity = $entity_storage->createFromStorageRecord($this->data['import']);
             }
             $entity->save();
             drupal_set_message($this->t('The @entity_type %label was imported.', array('@entity_type' => $entity->getEntityTypeId(), '%label' => $entity->label())));
         } catch (\Exception $e) {
             drupal_set_message($e->getMessage(), 'error');
         }
     }
 }
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $taxRate = $this->entity;
     try {
         $taxRate->save();
         drupal_set_message($this->t('Saved the %label tax rate.', ['%label' => $taxRate->label()]));
         $taxType = $this->taxTypeStorage->load($taxRate->getType());
         try {
             if (!$taxType->hasRate($taxRate)) {
                 $taxType->addRate($taxRate);
                 $taxType->save();
             }
             $form_state->setRedirect('entity.commerce_tax_rate.collection', ['commerce_tax_type' => $taxType->getId()]);
         } catch (\Exception $e) {
             drupal_set_message($this->t('The %label tax type was not saved.', ['%label' => $taxType->label()]));
             $this->logger('commerce_tax')->error($e);
             $form_state->setRebuild();
         }
     } catch (\Exception $e) {
         drupal_set_message($this->t('The %label tax rate was not saved.', ['%label' => $taxRate->label()]), 'error');
         $this->logger('commerce_tax')->error($e);
         $form_state->setRebuild();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     // @todo Redirect to a confirm form if changing server or tracker, since
     //   that isn't such a light operation (equaling a "clear", basically).
     // Only save the index if the form doesn't need to be rebuilt.
     if (!$form_state->isRebuilding()) {
         try {
             $this->getEntity()->save();
             drupal_set_message($this->t('The index was successfully saved.'));
             $form_state->setRedirect('entity.search_api_index.canonical', array('search_api_index' => $this->getEntity()->id()));
         } catch (SearchApiException $ex) {
             $form_state->setRebuild();
             watchdog_exception('search_api', $ex);
             drupal_set_message($this->t('The index could not be saved.'), 'error');
         }
     }
 }
 /**
  * @param $form_state
  */
 protected function automaticStartSubmit(FormStateInterface &$form_state)
 {
     $config = $this->config('acquia_connector.settings');
     $storage = $form_state->getStorage();
     if (empty($storage['response']['subscription'])) {
         drupal_set_message($this->t('No subscriptions were found for your account.'), 'error');
     } elseif (count($storage['response']['subscription']) > 1) {
         // Multistep form for choosing from available subscriptions.
         $storage['choose'] = TRUE;
         // Force rebuild with next step.
         $form_state->setRebuild(TRUE);
         $form_state->setStorage($storage);
     } else {
         // One subscription so set id/key pair.
         $sub = $storage['response']['subscription'][0];
         $config->set('key', $sub['key'])->set('identifier', $sub['identifier'])->set('subscription_name', $sub['name'])->save();
     }
 }
 /**
  * Submit handler for the entity_type select field.
  *
  * @param array $form
  *   The form array.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The form state object.
  *
  * @return $this
  */
 public function rebuildSubmit($form, FormStateInterface $form_state)
 {
     return $form_state->setRebuild();
 }
Example #27
0
 /**
  * Form submission handler for the Preview button.
  */
 public function submitPreview($form, FormStateInterface $form_state)
 {
     $form_state->set('show_preview', TRUE);
     $form_state->setRebuild();
 }
 /**
  * Form submission handler for the 'preview' action.
  */
 public function preview(array $form, FormStateInterface $form_state)
 {
     $message = $this->entity;
     $message->preview = TRUE;
     $form_state->setRebuild();
 }
Example #29
-2
 /**
  * Submit callback: switch a context to data selecor or direct input mode.
  */
 public function switchContextMode(array &$form, FormStateInterface $form_state)
 {
     $element_name = $form_state->getTriggeringElement()['#name'];
     $mode = $form_state->get($element_name);
     $switched_mode = $mode == 'selector' ? 'input' : 'selector';
     $form_state->set($element_name, $switched_mode);
     $form_state->setRebuild();
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $trigger = $form_state->getTriggeringElement();
     switch ($trigger['#name']) {
         case 'encrypt':
             if ($to_encrypt = $form_state->getValue('to_encrypt')) {
                 $encrypted_text = $this->encryptService->encrypt($to_encrypt, $this->entity);
                 if ($form_state->getValue('encrypt_base64')) {
                     $encrypted_text = base64_encode($encrypted_text);
                 }
                 $form_state->setValue('encrypted', $encrypted_text);
             }
             break;
         case 'decrypt':
             if ($to_decrypt = $form_state->getValue('to_decrypt')) {
                 if ($form_state->getValue('decrypt_base64')) {
                     $to_decrypt = base64_decode($to_decrypt);
                 }
                 $decrypted_text = $this->encryptService->decrypt($to_decrypt, $this->entity);
                 $form_state->setValue('decrypted', $decrypted_text);
             }
             break;
     }
     $form_state->setRebuild();
 }