Example #1
1
 /**
  * {@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;
 }
 /**
  * {@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');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if (!$form_state->isValueEmpty('redirection')) {
         if (!$form_state->isValueEmpty('destination')) {
             // The destination is a random URL, so we can't use routed URLs.
             // @todo Revist this in https://www.drupal.org/node/2418219.
             $form_state->setRedirectUrl(Url::fromUserInput('/' . $form_state->getValue('destination')));
         }
     } else {
         $form_state->disableRedirect();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if (!$form_state->isValueEmpty('redirection')) {
         if (!$form_state->isValueEmpty('destination')) {
             // @todo Use Url::fromPath() once https://www.drupal.org/node/2351379 is
             //   resolved.
             $form_state->setRedirectUrl(Url::fromUri('base://' . $form_state->getValue('destination')));
         }
     } else {
         $form_state->disableRedirect();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $config = $this->config('simpletest.settings');
     // If a username was provided but a password wasn't, preserve the existing
     // password.
     if (!$form_state->isValueEmpty('simpletest_httpauth_username') && $form_state->isValueEmpty('simpletest_httpauth_password')) {
         $form_state->setValue('simpletest_httpauth_password', $config->get('httpauth.password'));
     }
     // If a password was provided but a username wasn't, the credentials are
     // incorrect, so throw an error.
     if ($form_state->isValueEmpty('simpletest_httpauth_username') && !$form_state->isValueEmpty('simpletest_httpauth_password')) {
         $form_state->setErrorByName('simpletest_httpauth_username', $this->t('HTTP authentication credentials must include a username in addition to a password.'));
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * @covers ::isValueEmpty
  */
 public function testIsValueEmpty()
 {
     $key = ['foo', 'bar'];
     $is_empty = TRUE;
     $this->decoratedFormState->isValueEmpty($key)->willReturn($is_empty)->shouldBeCalled();
     $this->assertSame($is_empty, $this->formStateDecoratorBase->isValueEmpty($key));
 }
 /**
  * {@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');
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     // Save as a new revision if requested to do so.
     if (!$form_state->isValueEmpty('revision')) {
         $this->entity->setNewRevision();
     }
     $insert = $this->entity->isNew();
     $this->entity->save();
     $context = ['@type' => $this->entity->bundle(), '%info' => $this->entity->label()];
     $logger = $this->logger($this->entity->id());
     $bundle_entity = $this->getBundleEntity();
     $t_args = ['@type' => $bundle_entity ? $bundle_entity->label() : 'None', '%info' => $this->entity->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 ($this->entity->id()) {
         $form_state->setValue('id', $this->entity->id());
         $form_state->set('id', $this->entity->id());
         if ($this->entity->getEntityType()->hasLinkTemplate('collection')) {
             $form_state->setRedirectUrl($this->entity->toUrl('collection'));
         } else {
             $form_state->setRedirectUrl($this->entity->toUrl('canonical'));
         }
     } else {
         // In the unlikely case something went wrong on save, the entity will be
         // rebuilt and entity form redisplayed.
         drupal_set_message($this->t('The entity could not be saved.'), 'error');
         $form_state->setRebuild();
     }
 }
Example #9
0
 /**
  * Implements \Drupal\Core\Form\FormInterface::validateForm().
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $form_state->set('notify_emails', []);
     if (!$form_state->isValueEmpty('update_notify_emails')) {
         $valid = array();
         $invalid = array();
         foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
             $email = trim($email);
             if (!empty($email)) {
                 if ($this->emailValidator->isValid($email)) {
                     $valid[] = $email;
                 } else {
                     $invalid[] = $email;
                 }
             }
         }
         if (empty($invalid)) {
             $form_state->set('notify_emails', $valid);
         } elseif (count($invalid) == 1) {
             $form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
         } else {
             $form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
         }
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@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'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // 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)) {
         $test_id = simpletest_run_tests($tests_list, 'drupal');
         $form_state->setRedirect('simpletest.result_form', array('test_id' => $test_id));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     /** @var EntityTypeBaseInterface $entity_type */
     $entities = $this->entity->type->referencedEntities();
     $entity_type = reset($entities);
     // Save as a new revision if requested to do so.
     if (!$form_state->isValueEmpty('revision')) {
         $this->entity->setNewRevision();
     }
     $insert = $this->entity->isNew();
     $this->entity->save();
     $context = ['@type' => $this->entity->bundle(), '%info' => $this->entity->label()];
     $logger = $this->logger($this->entity->id());
     $t_args = ['@type' => $entity_type->label(), '%info' => $this->entity->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 ($this->entity->id()) {
         $form_state->setValue('id', $this->entity->id());
         $form_state->set('id', $this->entity->id());
         $form_state->setRedirectUrl($this->entity->urlInfo('collection'));
     } else {
         // In the unlikely case something went wrong on save, the entity will be
         // rebuilt and entity form redisplayed.
         drupal_set_message($this->t('The entity could not be saved.'), 'error');
         $form_state->setRebuild();
     }
 }
Example #13
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());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(OrderInterface $order, array $form, FormStateInterface $form_state)
 {
     db_delete('uc_order_comments')->condition('order_id', $order->id())->execute();
     if (!$form_state->isValueEmpty(['panes', 'comments', 'comments'])) {
         uc_order_comment_save($order->id(), 0, $form_state->getValue(['panes', 'comments', 'comments']), 'order', uc_order_state_default('post_checkout'), TRUE);
     }
     return TRUE;
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // If both fields are empty or filled, cancel.
     $file_upload = $this->getRequest()->files->get('files[upload]', NULL, TRUE);
     if ($form_state->isValueEmpty('remote') == empty($file_upload)) {
         $form_state->setErrorByName('remote', $this->t('<em>Either</em> upload a file or enter a URL.'));
     }
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $child_type = $form_state->getValue('book_child_type');
     if ($form_state->isValueEmpty(array('book_allowed_types', $child_type))) {
         $form_state->setErrorByName('book_child_type', $this->t('The content type for the %add-child link must be one of those selected as an allowed book outline type.', array('%add-child' => $this->t('Add child page'))));
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // No directory now; truncate the file list.
     if ($form_state->isValueEmpty('base_dir')) {
         uc_file_empty();
     } else {
         uc_file_refresh();
     }
     $file_config = $this->config('uc_file.settings');
     $file_config->set('base_dir', $form_state->getValue('base_dir'))->set('duplicate_warning', $form_state->getValue('duplicate_warning'))->set('download_limit_number', $form_state->getValue('download_limit_number'))->set('download_limit_addresses', $form_state->getValue('download_limit_addresses'))->set('download_limit_duration_qty', $form_state->getValue('download_limit_duration_qty'))->set('download_limit_duration_granularity', $form_state->getValue('download_limit_duration_granularity'))->save();
     parent::submitForm($form, $form_state);
 }
Example #18
0
 /**
  * {@inheritdoc}
  */
 public function validateExposed(&$form, FormStateInterface $form_state)
 {
     if (!isset($this->options['expose']['identifier'])) {
         return;
     }
     $key = $this->options['expose']['identifier'];
     if (!$form_state->isValueEmpty($key)) {
         $this->queryParseSearchExpression($form_state->getValue($key));
         if (count($this->searchQuery->words()) == 0) {
             $form_state->setErrorByName($key, $this->formatPlural(\Drupal::config('search.settings')->get('index.minimum_word_size'), 'You must include at least one keyword to match in the content, and punctuation is ignored.', 'You must include at least one keyword to match in the content. Keywords must be at least @count characters, and punctuation is ignored.'));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $uid = $this->currentUser()->id();
     if (!$form_state->isValueEmpty('order_comment')) {
         uc_order_comment_save($form_state->getValue('order_id'), $uid, $form_state->getValue('order_comment'), 'order', $form_state->getValue('status'), $form_state->getValue('notify'));
     }
     if (!$form_state->isValueEmpty('admin_comment')) {
         uc_order_comment_save($form_state->getValue('order_id'), $uid, $form_state->getValue('admin_comment'));
     }
     if ($form_state->getValue('status') != $form_state->getValue('current_status')) {
         Order::load($form_state->getValue('order_id'))->setStatusId($form_state->getValue('status'))->save();
         if ($form_state->isValueEmpty('order_comment')) {
             uc_order_comment_save($form_state->getValue('order_id'), $uid, '-', 'order', $form_state->getValue('status'), $form_state->getValue('notify'));
         }
     }
     // Let Rules send email if requested.
     // if ($form_state->getValue('notify')) {
     //   $order = Order::load($form_state->getValue('order_id'));
     //   rules_invoke_event('uc_order_status_email_update', $order);
     // }
     drupal_set_message($this->t('Order updated.'));
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 public function validateExposed(&$form, FormStateInterface $form_state)
 {
     if (!isset($this->options['expose']['identifier'])) {
         return;
     }
     $key = $this->options['expose']['identifier'];
     if (!$form_state->isValueEmpty($key)) {
         $this->queryParseSearchExpression($form_state->getValue($key));
         if (count($this->searchQuery->words()) == 0) {
             $form_state->setErrorByName($key, format_plural(\Drupal::config('search.settings')->get('index.minimum_word_size'), 'You must include at least one positive keyword with 1 character or more.', 'You must include at least one positive keyword with @count characters or more.'));
         }
     }
 }
Example #21
0
 /**
  * Returns the date for a given format string.
  *
  * @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.
  *
  * @return \Drupal\Core\Ajax\AjaxResponse
  *   An AJAX Response to update the date-time value of the date format.
  */
 public static function dateTimeLookup(array $form, FormStateInterface $form_state)
 {
     $format = '';
     if (!$form_state->isValueEmpty('date_format_pattern')) {
         $format = t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $form_state->getValue('date_format_pattern'))));
     }
     // Return a command instead of a string, since the Ajax framework
     // automatically prepends an additional empty DIV element for a string, which
     // breaks the layout.
     $response = new AjaxResponse();
     $response->addCommand(new ReplaceCommand('#edit-date-format-suffix', '<small id="edit-date-format-suffix">' . $format . '</small>'));
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     if (!$form_state->isValueEmpty('variants')) {
         foreach ($form_state->getValue('variants') as $variant_id => $data) {
             if ($variant_entity = $this->entity->getVariant($variant_id)) {
                 $variant_entity->setWeight($data['weight']);
                 $variant_entity->save();
             }
         }
     }
     parent::save($form, $form_state);
     drupal_set_message($this->t('The %label page has been updated.', ['%label' => $this->entity->label()]));
     $form_state->setRedirect('entity.page.collection');
 }
Example #23
0
 /**
  * {@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'));
     }
     // The test for drupal_move_uploaded_file() triggering a warning is
     // unavoidable. We're interested in what happens afterwards in
     // file_save_upload().
     if (\Drupal::state()->get('file_test.disable_error_collection')) {
         define('SIMPLETEST_COLLECT_ERRORS', FALSE);
     }
     $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');
     }
 }
Example #24
0
 /**
  * {@inheritdoc}
  */
 public function view(OrderInterface $order, array $form, FormStateInterface $form_state)
 {
     $user = \Drupal::currentUser();
     $pane = $this->pluginDefinition['id'];
     $source = $this->sourcePaneId();
     $contents['#description'] = $this->getDescription();
     if ($source != $pane) {
         $contents['copy_address'] = array('#type' => 'checkbox', '#title' => $this->getCopyAddressText(), '#default_value' => $this->configuration['default_same_address'], '#ajax' => array('callback' => array($this, 'ajaxRender'), 'wrapper' => $pane . '-address-pane', 'progress' => array('type' => 'throbber')));
     }
     if ($user->isAuthenticated() && ($addresses = uc_select_addresses($user->id(), $pane))) {
         $contents['select_address'] = array('#type' => 'select', '#title' => t('Saved addresses'), '#options' => $addresses['#options'], '#ajax' => array('callback' => array($this, 'ajaxRender'), 'wrapper' => $pane . '-address-pane', 'progress' => array('type' => 'throbber')), '#states' => array('invisible' => array('input[name="panes[' . $pane . '][copy_address]"]' => array('checked' => TRUE))));
     }
     $contents['address'] = array('#type' => 'uc_address', '#default_value' => $order->getAddress($pane), '#prefix' => '<div id="' . $pane . '-address-pane">', '#suffix' => '</div>');
     if ($form_state->hasValue(['panes', $pane, 'copy_address'])) {
         $contents['address']['#hidden'] = !$form_state->isValueEmpty(['panes', $pane, 'copy_address']);
     } elseif (isset($contents['copy_address'])) {
         $contents['address']['#hidden'] = $this->configuration['default_same_address'];
     }
     if ($element = $form_state->getTriggeringElement()) {
         $input = $form_state->getUserInput();
         if ($element['#name'] == "panes[{$pane}][copy_address]") {
             $address =& $form_state->getValue(['panes', $source]);
             foreach ($address as $field => $value) {
                 if (substr($field, 0, strlen($source)) == $source) {
                     $field = str_replace($source, $pane, $field);
                     $input['panes'][$pane][$field] = $value;
                     $order->{$field} = $value;
                 }
             }
         }
         if ($element['#name'] == "panes[{$pane}][select_address]") {
             $address = $addresses[$element['#value']];
             foreach ($address as $field => $value) {
                 $input['panes'][$pane][$pane . '_' . $field] = $value;
                 $order->{$pane . '_' . $field} = $value;
             }
         }
         $form_state->setUserInput($input);
         // Forget any previous Ajax submissions, as we send new default values.
         $form_state->unsetValue('uc_address');
     }
     return $contents;
 }
Example #25
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $account = $this->entity;
     $pass = $account->getPassword();
     $admin = $form_state->getValue('administer_users');
     $notify = !$form_state->isValueEmpty('notify');
     // Save has no return value so this cannot be tested.
     // Assume save has gone through correctly.
     $account->save();
     $form_state->set('user', $account);
     $form_state->setValue('uid', $account->id());
     $this->logger('user')->notice('New user: %name %email.', array('%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => $account->link($this->t('Edit'), 'edit-form')));
     // Add plain text password into user account to generate mail tokens.
     $account->password = $pass;
     // New administrative account without notification.
     if ($admin && !$notify) {
         drupal_set_message($this->t('Created a new user account for <a href=":url">%name</a>. No email has been sent.', array(':url' => $account->url(), '%name' => $account->getUsername())));
     } elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) {
         _user_mail_notify('register_no_approval_required', $account);
         user_login_finalize($account);
         drupal_set_message($this->t('Registration successful. You are now logged in.'));
         $form_state->setRedirect('<front>');
     } elseif ($account->isActive() || $notify) {
         if (!$account->getEmail() && $notify) {
             drupal_set_message($this->t('The new user <a href=":url">%name</a> was created without an email address, so no welcome message was sent.', array(':url' => $account->url(), '%name' => $account->getUsername())));
         } else {
             $op = $notify ? 'register_admin_created' : 'register_no_approval_required';
             if (_user_mail_notify($op, $account)) {
                 if ($notify) {
                     drupal_set_message($this->t('A welcome message with further instructions has been emailed to the new user <a href=":url">%name</a>.', array(':url' => $account->url(), '%name' => $account->getUsername())));
                 } else {
                     drupal_set_message($this->t('A welcome message with further instructions has been sent to your email address.'));
                     $form_state->setRedirect('<front>');
                 }
             }
         }
     } else {
         _user_mail_notify('register_pending_approval', $account);
         drupal_set_message($this->t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, a welcome message with further instructions has been sent to your email address.'));
         $form_state->setRedirect('<front>');
     }
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     foreach ($this->getRankings() as $var => $values) {
         if (!$form_state->isValueEmpty(['rankings', $var, 'value'])) {
             $this->configuration['rankings'][$var] = $form_state->getValue(['rankings', $var, 'value']);
         } else {
             unset($this->configuration['rankings'][$var]);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function blockSubmit($form, FormStateInterface $form_state)
 {
     if (!$form_state->isValueEmpty('views_label_checkbox')) {
         $this->configuration['views_label'] = $form_state->getValue('views_label');
     } else {
         $this->configuration['views_label'] = '';
     }
 }
Example #28
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Update image effect weights.
     if (!$form_state->isValueEmpty('effects')) {
         $this->updateEffectWeights($form_state->getValue('effects'));
     }
     parent::submitForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // File deletion status.
     $status = TRUE;
     // Delete the selected file(s), with recursion if selected.
     $status = uc_file_remove_by_id($form_state->getValue('file_ids'), !$form_state->isValueEmpty('recurse_directories')) && $status;
     if ($status) {
         drupal_set_message($this->t('The selected file(s) have been deleted.'));
     } else {
         drupal_set_message($this->t('One or more files could not be deleted.'), 'warning');
     }
     $form_state->setRedirect('uc_file.downloads');
 }
Example #30
0
 /**
  * {@inheritdoc}
  */
 public function validateOptionsForm(&$form, FormStateInterface $form_state)
 {
     $section = $form_state->get('section');
     switch ($section) {
         case 'display_title':
             if ($form_state->isValueEmpty('display_title')) {
                 $form_state->setError($form['display_title'], $this->t('Display title may not be empty.'));
             }
             break;
         case 'css_class':
             $css_class = $form_state->getValue('css_class');
             if (preg_match('/[^a-zA-Z0-9-_ ]/', $css_class)) {
                 $form_state->setError($form['css_class'], $this->t('CSS classes must be alphanumeric or dashes only.'));
             }
             break;
         case 'display_id':
             if ($form_state->getValue('display_id')) {
                 if (preg_match('/[^a-z0-9_]/', $form_state->getValue('display_id'))) {
                     $form_state->setError($form['display_id'], $this->t('Display name must be letters, numbers, or underscores only.'));
                 }
                 foreach ($this->view->displayHandlers as $id => $display) {
                     if ($id != $this->view->current_display && ($form_state->getValue('display_id') == $id || isset($display->new_id) && $form_state->getValue('display_id') == $display->new_id)) {
                         $form_state->setError($form['display_id'], $this->t('Display id should be unique.'));
                     }
                 }
             }
             break;
         case 'query':
             if ($this->view->query) {
                 $this->view->query->validateOptionsForm($form['query'], $form_state);
             }
             break;
     }
     // Validate plugin options. Every section with "_options" in it, belongs to
     // a plugin type, like "style_options".
     if (strpos($section, '_options') !== FALSE) {
         $plugin_type = str_replace('_options', '', $section);
         // Load the plugin and let it handle the validation.
         if ($plugin = $this->getPlugin($plugin_type)) {
             $plugin->validateOptionsForm($form[$section], $form_state);
         }
     }
     foreach ($this->extenders as $extender) {
         $extender->validateOptionsForm($form, $form_state);
     }
 }