/**
  * {@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');
 }
 /**
  * {@inheritdoc}
  */
 public function partialSubmitForm(array &$form, FormStateInterface $form_state)
 {
     // The title has not been validated, thus its value - in case of the test case
     // an empty string - may not be set.
     if (!$form_state->hasValue('title') && $form_state->hasValue('test')) {
         drupal_set_message('Only validated values appear in the form values.');
     }
 }
Example #3
0
  /**
   * Saves Schema.org mappings in \Drupal\node\NodeTypeForm.
   */
  public static function submitForm(array &$form, FormStateInterface $form_state) {
    if ($form_state->hasValue('types')) {
      $entity_type = $form_state->getFormObject()->getEntity();
      $mapping = rdf_get_mapping('node', $entity_type->id());
      if ($entity_type->isNew()) {
        $mapping = rdf_get_mapping('node', $form_state->getValue('types'));
      }

      if ($form_state->hasValue('types')) {
        $mapping->setBundleMapping(array('types' => array($form_state->getValue('types'))))
          ->save();
      }
    }
  }
 /**
  * @covers ::hasValue
  */
 public function testHasValue()
 {
     $key = ['foo', 'bar'];
     $has = TRUE;
     $this->decoratedFormState->hasValue($key)->willReturn($has)->shouldBeCalled();
     $this->assertSame($has, $this->formStateDecoratorBase->hasValue($key));
 }
Example #5
0
 /**
  * Creates a group formatted as horizontal tabs.
  *
  * @param array $element
  *   An associative array containing the properties and children of the
  *   details element.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param bool $on_form
  *   Are the tabs rendered on a form or not.
  *
  * @return array
  *   The processed element.
  */
 public static function processHorizontalTabs(&$element, FormStateInterface $form_state, $on_form = TRUE)
 {
     // Inject a new details as child, so that form_process_details() processes
     // this details element like any other details.
     $element['group'] = array('#type' => 'details', '#theme_wrappers' => array(), '#parents' => $element['#parents']);
     // Add an invisible label for accessibility.
     if (!isset($element['#title'])) {
         $element['#title'] = t('Horizontal Tabs');
         $element['#title_display'] = 'invisible';
     }
     // Add required JavaScript and Stylesheet.
     $element['#attached']['library'][] = 'field_group/formatter.horizontal_tabs';
     // Only add forms library on forms.
     if ($on_form) {
         $element['#attached']['library'][] = 'core/drupal.form';
     }
     // The JavaScript stores the currently selected tab in this hidden
     // field so that the active tab can be restored the next time the
     // form is rendered, e.g. on preview pages or when form validation
     // fails.
     $name = implode('__', $element['#parents']);
     if ($form_state->hasValue($name . '__active_tab')) {
         $element['#default_tab'] = $form_state->getValue($name . '__active_tab');
     }
     $element[$name . '__active_tab'] = array('#type' => 'hidden', '#default_value' => $element['#default_tab'], '#attributes' => array('class' => array('horizontal-tabs-active-tab')));
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $name = '')
 {
     $this->page = $page;
     $this->staticContext = $this->page->getStaticContext($name);
     // Allow the condition to add to the form.
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#default_value' => isset($this->staticContext['label']) ? $this->staticContext['label'] : '', '#required' => TRUE];
     $form['machine_name'] = ['#type' => 'machine_name', '#maxlength' => 64, '#required' => TRUE, '#machine_name' => ['exists' => [$this, 'contextExists'], 'source' => ['label']], '#default_value' => $name];
     $form['entity_type'] = ['#type' => 'select', '#title' => $this->t('Entity type'), '#options' => $this->entityManager->getEntityTypeLabels(TRUE), '#limit_validation_errors' => array(array('entity_type')), '#submit' => ['::rebuildSubmit'], '#executes_submit_callback' => TRUE, '#ajax' => array('callback' => '::updateEntityType', 'wrapper' => 'add-static-context-wrapper', 'method' => 'replace')];
     $entity = NULL;
     if ($form_state->hasValue('entity_type')) {
         $entity_type = $form_state->getValue('entity_type');
         if ($this->staticContext['value']) {
             $entity = $this->entityManager->loadEntityByUuid($entity_type, $this->staticContext['value']);
         }
     } elseif (!empty($this->staticContext['type'])) {
         list(, $entity_type) = explode(':', $this->staticContext['type']);
         $entity = $this->entityManager->loadEntityByUuid($entity_type, $this->staticContext['value']);
     } elseif ($this->entityManager->hasDefinition('node')) {
         $entity_type = 'node';
     } else {
         $entity_type = 'user';
     }
     $form['entity_type']['#default_value'] = $entity_type;
     $form['selection'] = ['#type' => 'entity_autocomplete', '#prefix' => '<div id="add-static-context-wrapper">', '#suffix' => '</div>', '#required' => TRUE, '#target_type' => $entity_type, '#default_value' => $entity, '#title' => $this->t('Select entity')];
     $form['actions'] = ['#type' => 'actions'];
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->submitButtonText(), '#button_type' => 'primary'];
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     $this->configuration['negate'] = $form_state->getValue('negate');
     if ($form_state->hasValue('context_mapping')) {
         $this->setContextMapping($form_state->getValue('context_mapping'));
     }
 }
Example #8
0
 /**
  * Creates a group formatted as vertical tabs.
  *
  * @param array $element
  *   An associative array containing the properties and children of the
  *   details element.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param array $complete_form
  *   The complete form structure.
  *
  * @return array
  *   The processed element.
  */
 public static function processVerticalTabs(&$element, FormStateInterface $form_state, &$complete_form)
 {
     // Inject a new details as child, so that form_process_details() processes
     // this details element like any other details.
     $element['group'] = array('#type' => 'details', '#theme_wrappers' => array(), '#parents' => $element['#parents']);
     // Add an invisible label for accessibility.
     if (!isset($element['#title'])) {
         $element['#title'] = t('Vertical Tabs');
         $element['#title_display'] = 'invisible';
     }
     $element['#attached']['library'][] = 'core/drupal.vertical-tabs';
     // The JavaScript stores the currently selected tab in this hidden
     // field so that the active tab can be restored the next time the
     // form is rendered, e.g. on preview pages or when form validation
     // fails.
     $name = implode('__', $element['#parents']);
     if ($form_state->hasValue($name . '__active_tab')) {
         $element['#default_tab'] = $form_state->getValue($name . '__active_tab');
     }
     $element[$name . '__active_tab'] = array('#type' => 'hidden', '#default_value' => $element['#default_tab'], '#attributes' => array('class' => array('vertical-tabs-active-tab')));
     // Clean up the active tab value so it's not accidentally stored in
     // settings forms.
     $form_state->addCleanValueKey($name . '__active_tab');
     return $element;
 }
Example #9
0
 /**
  * Ajax callback: Manually applies a shipping quote to an order.
  */
 public function applyQuote($form, FormStateInterface $form_state)
 {
     if ($form_state->hasValue(['quotes', 'quote_option'])) {
         if ($order = $form_state->get('order')) {
             $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->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']);
                 $form_state->set('uc_quote', array('lid' => $lid, 'title' => $label, 'amount' => $order->quote['rate']));
             } else {
                 uc_order_line_item_add($order->id(), 'shipping', $label, $order->quote['rate']);
             }
             // Save selected shipping
             uc_quote_uc_order_update($order);
             // Update line items.
             $order->line_items = $order->getLineItems();
             // @todo Still needed?
             $form_state->set('order', $order);
             $form_state->setRebuild();
             $form_state->set('quote_requested', FALSE);
         }
     }
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $filters = dblog_filters();
     foreach ($filters as $name => $filter) {
         if ($form_state->hasValue($name)) {
             $_SESSION['dblog_overview_filter'][$name] = $form_state->getValue($name);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $check_config = $this->config('uc_payment_pack.check.settings');
     $form['check_address_info'] = array('#markup' => '<div>' . t('Set the mailing address to display to customers who choose this payment method during checkout.') . '</div>');
     $form['uc_check_mailing_name'] = array('#type' => 'textfield', '#title' => t('Contact'), '#description' => t('Direct checks to a person or department.'), '#default_value' => $check_config->get('mailing_address.name'));
     $default_country = $check_config->get('mailing_address.country') ? $check_config->get('mailing_address.country') : $this->config('uc_store.settings')->get('address.country');
     $form['uc_check_address'] = array('#type' => 'uc_address', '#default_value' => array('uc_check_mailing_company' => $check_config->get('mailing_address.company'), 'uc_check_mailing_street1' => $check_config->get('mailing_address.street1'), 'uc_check_mailing_street2' => $check_config->get('mailing_address.street2'), 'uc_check_mailing_city' => $check_config->get('mailing_address.city'), 'uc_check_mailing_zone' => $check_config->get('mailing_address.zone'), 'uc_check_mailing_country' => $form_state->hasValue('uc_check_mailing_country') ? $form_state->getValue('uc_check_mailing_country') : $default_country, 'uc_check_mailing_postal_code' => $check_config->get('mailing_address.postal_code')), '#required' => FALSE, '#key_prefix' => 'uc_check_mailing');
     $form['uc_check_policy'] = array('#type' => 'textarea', '#title' => t('Check payment policy', [], ['context' => 'cheque']), '#description' => t('Instructions for customers on the checkout page.'), '#default_value' => $check_config->get('policy'), '#rows' => 3);
     return $form;
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $filters = $this->translateFilters();
     foreach ($filters as $name => $filter) {
         if ($form_state->hasValue($name)) {
             $_SESSION['locale_translate_filter'][$name] = $form_state->getValue($name);
         }
     }
     $form_state->setRedirect('locale.translate_page');
 }
 /**
  * {@inheritdoc}
  */
 public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state)
 {
     if ($form_state->hasValue('content_translation')) {
         $translation =& $form_state->getValue('content_translation');
         /** @var \Drupal\comment\CommentInterface $entity */
         $translation['status'] = $entity->isPublished();
         $translation['name'] = $entity->getAuthorName();
     }
     parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $parents = ['table', $this->uuid(), 'form'];
     $entity_type = $form_state->hasValue(array_merge($parents, ['entity_type'])) ? $form_state->getValue(array_merge($parents, ['entity_type'])) : $this->configuration['entity_type'];
     $bundle = $form_state->hasValue(array_merge($parents, ['bundle', 'select'])) ? $form_state->getValue(array_merge($parents, ['bundle', 'select'])) : $this->configuration['bundle'];
     $definitions = $this->entityManager->getDefinitions();
     $entity_types = array_combine(array_keys($definitions), array_map(function (EntityTypeInterface $item) {
         return $item->getLabel();
     }, $definitions));
     $form['entity_type'] = ['#type' => 'select', '#title' => $this->t('Entity type'), '#options' => $entity_types, '#default_value' => $entity_type, '#ajax' => ['wrapper' => 'bundle-wrapper', 'callback' => [$this, 'updateBundle']]];
     $bundles = [];
     if ($entity_type) {
         $definitions = $this->entityManager->getBundleInfo($entity_type);
         $bundles = array_map(function ($item) {
             return $item['label'];
         }, $definitions);
     }
     $form['bundle'] = ['#type' => 'container', 'select' => ['#type' => 'select', '#title' => $this->t('Bundle'), '#options' => $bundles, '#default_value' => $bundle], '#attributes' => ['id' => 'bundle-wrapper']];
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state)
 {
     if ($form_state->hasValue('content_translation')) {
         $translation =& $form_state->getValue('content_translation');
         $translation['status'] = $entity->isPublished();
         $account = $entity->uid->entity;
         $translation['uid'] = $account ? $account->id() : 0;
         $translation['created'] = format_date($entity->created->value, 'custom', 'Y-m-d H:i:s O');
     }
     parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state)
 {
     if ($form_state->hasValue('content_translation')) {
         $translation =& $form_state->getValue('content_translation');
         $translation['status'] = $entity->isPublished();
         // $form['content_translation']['name'] is the equivalent field
         // for translation author uid.
         $account = $entity->uid->entity;
         $translation['name'] = $account ? $account->getUsername() : '';
         $translation['created'] = format_date($entity->created->value, 'custom', 'Y-m-d H:i:s O');
     }
     parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_state->cleanValues();
     if ($form_state->hasValue('mid')) {
         db_merge('uc_weightquote_methods')->key(array('mid' => $form_state->getValue('mid')))->fields($form_state->getValues())->execute();
         drupal_set_message(t('Weight quote shipping method was updated.'));
         $form_state->setRedirect('uc_quote.methods');
     } else {
         db_insert('uc_weightquote_methods')->fields($form_state->getValues())->execute();
         // Ensure Rules picks up the new condition.
         // entity_flush_caches();
         drupal_set_message(t('Created and enabled new weight quote shipping method.'));
         $form_state->setRedirect('uc_quote.methods');
         //$form_state['redirect'] = 'admin/store/config/quotes/manage/get_quote_from_weightquote_' . $form_state->getValue('mid');
     }
 }
Example #18
0
 /**
  * {@inheritdoc}
  */
 public function cartProcess(OrderInterface $order, array $form, FormStateInterface $form_state)
 {
     // Default our value for validation.
     $return = TRUE;
     if (!$form_state->hasValue(['panes', 'payment', 'details', 'ideal_issuer'])) {
         $form_state->setErrorByName('panes][payment][details][ideal_issuer', t('Please select an iDeal issuer'));
         $return = FALSE;
     }
     // We can still manipulate order when needed
     $order->payment_details = $form_state->getValue(['panes', 'payment', 'details']);
     $icepay_config = \Drupal::config('uc_icepay.settings');
     $order->currency = $icepay_config->get('currency');
     // need to save this order into table uc_payment_icepay with status cart_checkout
     $api = new IcepayApi();
     $api->enterPayment($order);
     return $return;
 }
Example #19
0
 /**
  * {@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;
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, array $addresses = [], OrderInterface $uc_order = NULL)
 {
     $form['#attached']['library'][] = 'uc_fulfillment/uc_fulfillment.scripts';
     $form['origin'] = array('#type' => 'fieldset', '#title' => t('Origin address'), '#weight' => -2);
     $form['origin']['pickup_address_select'] = $this->selectAddress($addresses);
     $form['origin']['pickup_address_select']['#weight'] = -2;
     $form['origin']['pickup_email'] = array('#type' => 'email', '#title' => t('E-mail'), '#default_value' => uc_store_email(), '#weight' => -1);
     $form['origin']['pickup_email']['#weight'] = -1;
     $form['origin']['pickup_address']['#tree'] = TRUE;
     $form['origin']['pickup_address']['pickup_address'] = array('#type' => 'uc_address', '#default_value' => reset($addresses), '#required' => FALSE);
     $form['destination'] = array('#type' => 'fieldset', '#title' => t('Destination address'), '#weight' => -1);
     if ($form_state->hasValue('delivery_country')) {
         $uc_order->delivery_country = $form_state->getValue('delivery_country');
     }
     $form['destination']['delivery_email'] = array('#type' => 'email', '#title' => t('E-mail'), '#default_value' => $uc_order->getEmail(), '#weight' => -1);
     $form['destination']['delivery_email']['#weight'] = -1;
     $form['destination']['delivery_address'] = array('#type' => 'uc_address', '#default_value' => $uc_order->getAddress('delivery'), '#required' => FALSE, '#key_prefix' => 'delivery');
     return $form;
 }
Example #21
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;
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $metatag_defaults = $this->entity;
     // Set the label on new defaults.
     if ($metatag_defaults->isNew()) {
         $metatag_defaults_id = $form_state->getValue('id');
         list($entity_type, $entity_bundle) = explode('__', $metatag_defaults_id);
         // Get the entity label.
         $entity_manager = \Drupal::service('entity.manager');
         $entity_info = $entity_manager->getDefinitions();
         $entity_label = (string) $entity_info[$entity_type]->get('label');
         // Get the bundle label.
         $bundle_info = $entity_manager->getBundleInfo($entity_type);
         $bundle_label = $bundle_info[$entity_bundle]['label'];
         // Set the label to the config entity.
         $this->entity->set('label', $entity_label . ': ' . $bundle_label);
     }
     // Set tags within the Metatag entity.
     $tag_manager = \Drupal::service('plugin.manager.metatag.tag');
     $tags = $tag_manager->getDefinitions();
     $tag_values = array();
     foreach ($tags as $tag_id => $tag_definition) {
         if ($form_state->hasValue($tag_id)) {
             // Some plugins need to process form input before storing it.
             // Hence, we set it and then get it.
             $tag = $tag_manager->createInstance($tag_id);
             $tag->setValue($form_state->getValue($tag_id));
             if (!empty($tag->value())) {
                 $tag_values[$tag_id] = $tag->value();
             }
         }
     }
     $metatag_defaults->set('tags', $tag_values);
     $status = $metatag_defaults->save();
     switch ($status) {
         case SAVED_NEW:
             drupal_set_message($this->t('Created the %label Metatag defaults.', ['%label' => $metatag_defaults->label()]));
             break;
         default:
             drupal_set_message($this->t('Saved the %label Metatag defaults.', ['%label' => $metatag_defaults->label()]));
     }
     $form_state->setRedirectUrl($metatag_defaults->urlInfo('collection'));
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $language = \Drupal::languageManager()->getCurrentLanguage();
     $ln = $language->getId();
     if (!preg_match('/^[1-9][0-9]{0,4}$/', $form_state->getValue(['eu_cookie_compliance_' . $ln, 'popup_height'])) && $form_state->hasValue(['eu_cookie_compliance_' . $ln, 'popup_height'])) {
         $form_state->setErrorByName("eu_cookie_compliance_popup_height", t('Height must be an integer value.'));
     }
     if (!preg_match('/^[1-9][0-9]{0,4}$/', $form_state->getValue(['eu_cookie_compliance_' . $ln, 'popup_delay']))) {
         $form_state->setErrorByName('eu_cookie_compliance_popup_delay', t('Delay must be an integer value.'));
     }
     if (!preg_match('/^[1-9][0-9]{0,4}\\%?$/', $form_state->getValue(['eu_cookie_compliance_' . $ln, 'popup_width']))) {
         $form_state->setErrorByName('eu_cookie_compliance_popup_width', t('Width must be an integer or a percentage value.'));
     }
     $popup_link = $form_state->getValue(['eu_cookie_compliance_' . $ln, 'popup_link']);
     //if the link contains a fragment then check if it validates then rewrite link with full url
     if (strpos($popup_link, '#') !== FALSE && strpos($popup_link, 'http') === FALSE) {
         $fragment = explode('#', $popup_link);
         $popup_link = _url($fragment[0], array('fragment' => $fragment[1], 'absolute' => TRUE));
         $form_state->setErrorByName(['eu_cookie_compliance_' . $ln, 'popup_link'], t('Looks like your privacy policy link contains fragment #, you should make this an absolute url eg @link', array('@link' => $popup_link)));
     }
     \Drupal::cache()->delete('eu_cookie_compliance_client_settings_' . $language->getId());
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('uc_store.settings');
     $form['store'] = array('#type' => 'vertical_tabs');
     $form['basic'] = array('#type' => 'details', '#title' => $this->t('Basic information'), '#group' => 'store');
     $form['basic']['uc_store_name'] = array('#type' => 'textfield', '#title' => $this->t('Store name'), '#default_value' => uc_store_name());
     $form['basic']['uc_store_email'] = array('#type' => 'email', '#title' => $this->t('E-mail address'), '#size' => 32, '#required' => TRUE, '#default_value' => uc_store_email());
     $form['basic']['uc_store_email_include_name'] = array('#type' => 'checkbox', '#title' => $this->t('Include the store name in the "From" line of store e-mails.'), '#description' => $this->t('May not be available on all server configurations. Turn off if this causes problems.'), '#default_value' => $config->get('mail_include_name'));
     $form['basic']['uc_store_phone'] = array('#type' => 'tel', '#title' => $this->t('Phone number'), '#default_value' => $config->get('phone'));
     $form['basic']['uc_store_fax'] = array('#type' => 'tel', '#title' => $this->t('Fax number'), '#default_value' => $config->get('fax'));
     $form['basic']['uc_store_help_page'] = array('#type' => 'textfield', '#title' => $this->t('Store help page'), '#description' => $this->t('The Drupal page for the store help link.'), '#default_value' => $config->get('help_page'), '#size' => 32, '#field_prefix' => $this->url('<front>', [], ['absolute' => TRUE]));
     $form['address'] = array('#type' => 'details', '#title' => $this->t('Store address'), '#group' => 'store');
     $form['address']['address'] = array('#type' => 'uc_address', '#default_value' => array('uc_store_street1' => $config->get('address.street1'), 'uc_store_street2' => $config->get('address.street2'), 'uc_store_city' => $config->get('address.city'), 'uc_store_zone' => $config->get('address.zone'), 'uc_store_country' => $form_state->hasValue('uc_store_country') ? $form_state->getValue('uc_store_country') : $config->get('address.country'), 'uc_store_postal_code' => $config->get('address.postal_code')), '#required' => FALSE, '#key_prefix' => 'uc_store');
     $form['currency'] = array('#type' => 'details', '#title' => $this->t('Currency format'), '#group' => 'store');
     $form['currency']['uc_currency_code'] = array('#type' => 'textfield', '#title' => $this->t('Currency code'), '#description' => $this->t('While not used directly in formatting, the currency code is used by other modules as the primary currency for your site.  Enter here your three character <a href=":url">ISO 4217</a> currency code.', [':url' => Url::fromUri('http://en.wikipedia.org/wiki/ISO_4217#Active_codes')->toString()]), '#default_value' => $config->get('currency.code'), '#maxlength' => 3, '#size' => 5);
     $form['currency']['example'] = array('#type' => 'textfield', '#title' => $this->t('Current format'), '#value' => uc_currency_format(1000.1234), '#disabled' => TRUE, '#size' => 10);
     $form['currency']['uc_currency_sign'] = array('#type' => 'textfield', '#title' => $this->t('Currency sign'), '#default_value' => $config->get('currency.symbol'), '#size' => 10, '#maxlength' => 10);
     $form['currency']['uc_sign_after_amount'] = array('#type' => 'checkbox', '#title' => $this->t('Display currency sign after amount.'), '#default_value' => $config->get('currency.symbol_after'));
     $form['currency']['uc_currency_thou'] = array('#type' => 'textfield', '#title' => $this->t('Thousands marker'), '#default_value' => $config->get('currency.thousands_marker'), '#size' => 10, '#maxlength' => 10);
     $form['currency']['uc_currency_dec'] = array('#type' => 'textfield', '#title' => $this->t('Decimal marker'), '#default_value' => $config->get('currency.decimal_marker'), '#size' => 10, '#maxlength' => 10);
     $form['currency']['uc_currency_prec'] = array('#type' => 'select', '#title' => $this->t('Number of decimal places'), '#options' => array(0 => 0, 1 => 1, 2 => 2), '#default_value' => $config->get('currency.precision'));
     $form['weight'] = array('#type' => 'details', '#title' => $this->t('Weight format'), '#group' => 'store');
     $form['weight']['uc_weight_unit'] = array('#type' => 'select', '#title' => $this->t('Default weight units'), '#default_value' => $config->get('weight.units'), '#options' => array('lb' => $this->t('Pounds'), 'oz' => $this->t('Ounces'), 'kg' => $this->t('Kilograms'), 'g' => $this->t('Grams')));
     $form['weight']['uc_weight_thou'] = array('#type' => 'textfield', '#title' => $this->t('Thousands marker'), '#default_value' => $config->get('weight.thousands_marker'), '#size' => 10, '#maxlength' => 10);
     $form['weight']['uc_weight_dec'] = array('#type' => 'textfield', '#title' => $this->t('Decimal marker'), '#default_value' => $config->get('weight.decimal_marker'), '#size' => 10, '#maxlength' => 10);
     $form['weight']['uc_weight_prec'] = array('#type' => 'select', '#title' => $this->t('Number of decimal places'), '#options' => array(0 => 0, 1 => 1, 2 => 2), '#default_value' => $config->get('weight.precision'));
     $form['length'] = array('#type' => 'details', '#title' => $this->t('Length format'), '#group' => 'store');
     $form['length']['uc_length_unit'] = array('#type' => 'select', '#title' => $this->t('Default length units'), '#default_value' => $config->get('length.units'), '#options' => array('in' => $this->t('Inches'), 'ft' => $this->t('Feet'), 'cm' => $this->t('Centimeters'), 'mm' => $this->t('Millimeters')));
     $form['length']['uc_length_thou'] = array('#type' => 'textfield', '#title' => $this->t('Thousands marker'), '#default_value' => $config->get('length.thousands_marker'), '#size' => 10, '#maxlength' => 10);
     $form['length']['uc_length_dec'] = array('#type' => 'textfield', '#title' => $this->t('Decimal marker'), '#default_value' => $config->get('length.decimal_marker'), '#size' => 10, '#maxlength' => 10);
     $form['length']['uc_length_prec'] = array('#type' => 'select', '#title' => $this->t('Number of decimal places'), '#options' => array(0 => 0, 1 => 1, 2 => 2), '#default_value' => $config->get('length.precision'));
     $form['display'] = array('#type' => 'details', '#title' => $this->t('Display settings'), '#group' => 'store');
     $form['display']['uc_customer_list_address'] = array('#type' => 'radios', '#title' => $this->t('Primary customer address'), '#description' => $this->t('Select the address to be used on customer lists and summaries.'), '#options' => array('billing' => $this->t('Billing address'), 'shipping' => $this->t('Shipping address')), '#default_value' => $config->get('customer_address'));
     $form['display']['uc_order_capitalize_addresses'] = array('#type' => 'checkbox', '#title' => $this->t('Capitalize address on order screens'), '#default_value' => $config->get('capitalize_address'));
     return parent::buildForm($form, $form_state);
 }
Example #25
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Only perform this logic if we're moving to the next page. This prevents
     // the loss of cached values on ajax submissions.
     if ((string) $form_state->getValue('op') == (string) $this->getNextOp()) {
         $cached_values = $form_state->getTemporaryValue('wizard');
         if ($form_state->hasValue('label')) {
             $cached_values['label'] = $form_state->getValue('label');
         }
         if ($form_state->hasValue('id')) {
             $cached_values['id'] = $form_state->getValue('id');
         }
         if (is_null($this->machine_name) && !empty($cached_values['id'])) {
             $this->machine_name = $cached_values['id'];
         }
         $this->getTempstore()->set($this->getMachineName(), $cached_values);
         if (!$form_state->get('ajax')) {
             $form_state->setRedirect($this->getRouteName(), $this->getNextParameters($cached_values));
         }
     }
 }
Example #26
0
 public function validateOptionsForm(&$form, FormStateInterface $form_state)
 {
     // Don't run validation on style plugins without the grouping setting.
     if ($form_state->hasValue(array('style_options', 'grouping'))) {
         // Don't save grouping if no field is specified.
         $groupings = $form_state->getValue(array('style_options', 'grouping'));
         foreach ($groupings as $index => $grouping) {
             if (empty($grouping['field'])) {
                 $form_state->unsetValue(array('style_options', 'grouping', $index));
             }
         }
     }
 }
Example #27
0
 public function buildSearchUrlQuery(FormStateInterface $form_state)
 {
     // Read keyword and advanced search information from the form values,
     // and put these into the GET parameters.
     $keys = trim($form_state->getValue('keys'));
     $advanced = FALSE;
     // Collect extra filters.
     $filters = array();
     if ($form_state->hasValue('type') && is_array($form_state->getValue('type'))) {
         // Retrieve selected types - Form API sets the value of unselected
         // checkboxes to 0.
         foreach ($form_state->getValue('type') as $type) {
             if ($type) {
                 $advanced = TRUE;
                 $filters[] = 'type:' . $type;
             }
         }
     }
     if ($form_state->hasValue('term') && is_array($form_state->getValue('term'))) {
         foreach ($form_state->getValue('term') as $term) {
             $filters[] = 'term:' . $term;
             $advanced = TRUE;
         }
     }
     if ($form_state->hasValue('language') && is_array($form_state->getValue('language'))) {
         foreach ($form_state->getValue('language') as $language) {
             if ($language) {
                 $advanced = TRUE;
                 $filters[] = 'language:' . $language;
             }
         }
     }
     if ($form_state->getValue('or') != '') {
         if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state->getValue('or'), $matches)) {
             $keys .= ' ' . implode(' OR ', $matches[1]);
             $advanced = TRUE;
         }
     }
     if ($form_state->getValue('negative') != '') {
         if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state->getValue('negative'), $matches)) {
             $keys .= ' -' . implode(' -', $matches[1]);
             $advanced = TRUE;
         }
     }
     if ($form_state->getValue('phrase') != '') {
         $keys .= ' "' . str_replace('"', ' ', $form_state->getValue('phrase')) . '"';
         $advanced = TRUE;
     }
     $keys = trim($keys);
     // Put the keywords and advanced parameters into GET parameters. Make sure
     // to put keywords into the query even if it is empty, because the page
     // controller uses that to decide it's time to check for search results.
     $query = array('keys' => $keys);
     if ($filters) {
         $query['f'] = $filters;
     }
     // Record that the person used the advanced search form, if they did.
     if ($advanced) {
         $query[self::ADVANCED_FORM] = '1';
     }
     return $query;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     $contexts = $this->getContexts($cached_values);
     $context = ['context' => $form_state->getValue('context'), 'label' => $form_state->getValue('label'), 'machine_name' => $form_state->getValue('machine_name'), 'description' => $form_state->getValue('description')];
     if ($form_state->hasValue('id')) {
         $contexts[$form_state->getValue('id')] = $context;
     } else {
         $contexts[] = $context;
     }
     $cached_values = $this->setContexts($cached_values, $contexts);
     $this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
     list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
     $form_state->setRedirect($route_name, $route_parameters);
 }
Example #29
0
 /**
  * {@inheritdoc}
  */
 public function submitOptionsForm(&$form, FormStateInterface $form_state)
 {
     // Not sure I like this being here, but it seems (?) like a logical place.
     $cache_plugin = $this->getPlugin('cache');
     if ($cache_plugin) {
         $cache_plugin->cacheFlush();
     }
     $section = $form_state->get('section');
     switch ($section) {
         case 'display_id':
             if ($form_state->hasValue('display_id')) {
                 $this->display['new_id'] = $form_state->getValue('display_id');
             }
             break;
         case 'display_title':
             $this->display['display_title'] = $form_state->getValue('display_title');
             $this->setOption('display_description', $form_state->getValue('display_description'));
             break;
         case 'query':
             $plugin = $this->getPlugin('query');
             if ($plugin) {
                 $plugin->submitOptionsForm($form['query']['options'], $form_state);
                 $this->setOption('query', $form_state->getValue($section));
             }
             break;
         case 'link_display':
             $this->setOption('link_url', $form_state->getValue('link_url'));
         case 'title':
         case 'css_class':
         case 'display_comment':
         case 'distinct':
         case 'group_by':
             $this->setOption($section, $form_state->getValue($section));
             break;
         case 'rendering_language':
             $this->setOption('rendering_language', $form_state->getValue('rendering_language'));
             break;
         case 'use_ajax':
         case 'hide_attachment_summary':
         case 'show_admin_links':
         case 'exposed_block':
             $this->setOption($section, (bool) $form_state->getValue($section));
             break;
         case 'use_more':
             $this->setOption($section, intval($form_state->getValue($section)));
             $this->setOption('use_more_always', intval($form_state->getValue('use_more_always')));
             $this->setOption('use_more_text', $form_state->getValue('use_more_text'));
             break;
         case 'access':
         case 'cache':
         case 'exposed_form':
         case 'pager':
         case 'row':
         case 'style':
             $plugin_type = $section;
             $plugin_options = $this->getOption($plugin_type);
             $type = $form_state->getValue(array($plugin_type, 'type'));
             if ($plugin_options['type'] != $type) {
                 /** @var \Drupal\views\Plugin\views\ViewsPluginInterface $plugin */
                 $plugin = Views::pluginManager($plugin_type)->createInstance($type);
                 if ($plugin) {
                     $plugin->init($this->view, $this, $plugin_options['options']);
                     $plugin_options = array('type' => $type, 'options' => $plugin->options);
                     $plugin->filterByDefinedOptions($plugin_options['options']);
                     $this->setOption($plugin_type, $plugin_options);
                     if ($plugin->usesOptions()) {
                         $form_state->get('view')->addFormToStack('display', $this->display['id'], $plugin_type . '_options');
                     }
                 }
             }
             break;
         case 'access_options':
         case 'cache_options':
         case 'exposed_form_options':
         case 'pager_options':
         case 'row_options':
         case 'style_options':
             // Submit plugin options. Every section with "_options" in it, belongs to
             // a plugin type, like "style_options".
             $plugin_type = str_replace('_options', '', $section);
             if ($plugin = $this->getPlugin($plugin_type)) {
                 $plugin_options = $this->getOption($plugin_type);
                 $plugin->submitOptionsForm($form[$plugin_type . '_options'], $form_state);
                 $plugin_options['options'] = $form_state->getValue($section);
                 $this->setOption($plugin_type, $plugin_options);
             }
             break;
     }
     $extender_options = $this->getOption('display_extenders');
     foreach ($this->extenders as $extender) {
         $extender->submitOptionsForm($form, $form_state);
         $plugin_id = $extender->getPluginId();
         $extender_options[$plugin_id] = $extender->options;
     }
     $this->setOption('display_extenders', $extender_options);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $config = $this->config('mimemail.settings');
     // Set the default mimemail format.
     if ($form_state->hasValue('format')) {
         $config->set('format', $form_state->getValue('format'));
     }
     // Set the default mimemail site name.
     if ($form_state->hasValue('name')) {
         $config->set('name', $form_state->getValue('name'));
     }
     // Set the default mimemail site email.
     if ($form_state->hasValue('mail')) {
         $config->set('mail', $form_state->getValue('mail'));
     }
     // Finally save the configuration.
     $config->save();
 }