You are here

class QuoteSettingsForm in Ubercart 8.4

Default shipping settings form.

Sets the default shipping location of the store. Allows the user to determine which quoting methods are enabled and which take precedence over the others. Also sets the default quote and shipping types of all products in the store. Individual products may be configured differently.

Hierarchy

Expanded class hierarchy of QuoteSettingsForm

1 string reference to 'QuoteSettingsForm'
uc_quote.routing.yml in shipping/uc_quote/uc_quote.routing.yml
shipping/uc_quote/uc_quote.routing.yml

File

shipping/uc_quote/src/Form/QuoteSettingsForm.php, line 18

Namespace

Drupal\uc_quote\Form
View source
class QuoteSettingsForm extends ConfigFormBase {

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Form constructor.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  public function __construct(ModuleHandlerInterface $module_handler) {
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('module_handler'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'uc_quote_admin_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'uc_quote.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $quote_config = $this
      ->config('uc_quote.settings');
    $form['display_debug'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Display debug information to administrators.'),
      '#default_value' => $quote_config
        ->get('display_debug'),
    ];
    $form['require_quote'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Prevent the customer from completing an order if a shipping quote is not selected.'),
      '#default_value' => $quote_config
        ->get('require_quote'),
    ];
    $form['default_address'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Default pickup address'),
      '#description' => $this
        ->t("When delivering products to customers, the original location of the product must be known in order to accurately quote the shipping cost and set up a delivery. This form provides the default location for all products in the store. If a product's individual pickup address is blank, Ubercart uses the store's default pickup address specified here."),
    ];
    $form['default_address']['address'] = [
      //    '#tree' => TRUE,
      '#type' => 'uc_address',
      '#hide' => [
        'first_name',
        'last_name',
        'company',
        'email',
      ],
      '#default_value' => $quote_config
        ->get('ship_from_address'),
      '#required' => FALSE,
    ];
    $shipping_types = uc_quote_shipping_type_options();
    if (is_array($shipping_types)) {
      $form['type_weight'] = [
        '#type' => 'details',
        '#title' => $this
          ->t('List position'),
        '#description' => $this
          ->t('Determines which shipping methods are quoted at checkout when products of different shipping types are ordered. Larger values take precedence.'),
        '#tree' => TRUE,
      ];
      $weight = $quote_config
        ->get('type_weight');
      $shipping_methods = $this->moduleHandler
        ->invokeAll('uc_shipping_method');
      $method_types = [];
      foreach ($shipping_methods as $method) {

        // Get shipping method types from shipping methods that provide quotes.
        if (isset($method['quote'])) {
          $method_types[$method['quote']['type']][] = $method['title'];
        }
      }
      if (isset($method_types['order']) && is_array($method_types['order'])) {
        $count = count($method_types['order']);
        $form['type_weight']['#description'] .= $this
          ->formatPlural($count, '<br />The %list method is compatible with any shipping type.', '<br />The %list methods are compatible with any shipping type.', [
          '%list' => implode(', ', $method_types['order']),
        ]);
      }
      foreach ($shipping_types as $id => $title) {
        $form['type_weight'][$id] = [
          '#type' => 'weight',
          '#title' => $title . (isset($method_types[$id]) && is_array($method_types[$id]) ? ' (' . implode(', ', $method_types[$id]) . ')' : ''),
          '#delta' => 5,
          '#default_value' => isset($weight[$id]) ? $weight[$id] : 0,
        ];
      }
    }
    $form['uc_store_shipping_type'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Default order fulfillment type for products'),
      '#options' => $shipping_types,
      '#default_value' => $quote_config
        ->get('shipping_type'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $quote_config = $this
      ->config('uc_quote.settings');
    $quote_config
      ->set('ship_from_address', $form_state
      ->getValue('address'))
      ->set('display_debug', $form_state
      ->getValue('display_debug'))
      ->set('require_quote', $form_state
      ->getValue('require_quote'))
      ->set('type_weight', $form_state
      ->getValue('type_weight'))
      ->set('shipping_type', $form_state
      ->getValue('uc_store_shipping_type'))
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
QuoteSettingsForm::$moduleHandler protected property The module handler.
QuoteSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
QuoteSettingsForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
QuoteSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
QuoteSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
QuoteSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
QuoteSettingsForm::__construct public function Form constructor. Overrides ConfigFormBase::__construct
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.