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
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\uc_quote\Form\QuoteSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
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\FormView 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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
QuoteSettingsForm:: |
protected | property | The module handler. | |
QuoteSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
QuoteSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
QuoteSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
QuoteSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
QuoteSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
QuoteSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |