class CommerceAutoSkuForm in Commerce AutoSKU 8.2
Class CommerceAutoSkuForm.
@property \Drupal\Core\Config\ConfigFactoryInterface config_factory @property \Drupal\Core\Entity\EntityTypeManagerInterface entity_manager @property String entity_type_parameter @property String entity_type_id @property \Drupal\commerce_autosku\CommerceAutoSkuManager auto_entity_label_manager @package Drupal\commerce_autosku\Controller
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\commerce_autosku\Form\CommerceAutoSkuForm
Expanded class hierarchy of CommerceAutoSkuForm
File
- src/
Form/ CommerceAutoSkuForm.php, line 28 - Contains \Drupal\commerce_autosku\Controller\CommerceAutoSkuForm.
Namespace
Drupal\commerce_autosku\FormView source
class CommerceAutoSkuForm extends FormBase {
/**
* The commerce autoSku generator plugin manager.
*
* @var \Drupal\commerce_payment\PaymentGatewayManager
*/
protected $pluginManager;
/**
* The commerce autoSku generator plugin manager.
*
* @var ProductVariationTypeInterface
*/
protected $entity;
/**
* AutoEntityLabelController constructor.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* @param \Drupal\commerce_autosku\CommerceAutoSkuManager $plugin_manager
*/
public function __construct(ContainerInterface $container, CommerceAutoSkuGeneratorManager $plugin_manager) {
$this->pluginManager = $plugin_manager;
}
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return 'commerce_autosku_settings_form';
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container, $container
->get('plugin.manager.commerce_autosku_generator'));
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $commerce_product_variation_type = NULL) {
/** @var ProductVariationTypeInterface entity */
$this->entity = $commerce_product_variation_type;
$configuration = $this->entity
->getThirdPartySettings('commerce_autosku');
$form['mode'] = [
'#type' => 'radios',
'#default_value' => isset($configuration['mode']) ? $configuration['mode'] : CommerceAutoSkuManager::DISABLED,
'#options' => CommerceAutoSkuManager::commerce_autosku_options(),
];
$definition = $this->pluginManager
->getDefinitions();
$plugins = array_column($definition, 'label', 'id');
asort($plugins);
// $plugin = $this->getget('');
//
// // Use the first available plugin as the default value.
// if (!$gateway->getPluginId()) {
// $plugin_ids = array_keys($plugins);
// $plugin = reset($plugin_ids);
// $gateway->setPluginId($plugin);
// }
// The form state will have a plugin value if #ajax was used.
// $plugin = $form_state->getValue('plugin');
// Pass the plugin configuration only if the plugin hasn't been changed via #ajax.
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save configuration'),
'#button_type' => 'primary',
];
// By default, render the form using system-config-form.html.twig.
$form['#theme'] = 'system_config_form';
if (!empty($configuration['plugin']) && !isset($plugins[$configuration['plugin']])) {
return $form;
}
$wrapper_id = Html::getUniqueId('commerce-autosku-plugin-form');
$form['plugin'] = [
'#type' => 'radios',
'#title' => t('Plugin'),
'#options' => $plugins,
'#required' => TRUE,
'#ajax' => [
'callback' => '::ajaxRefresh',
'wrapper' => $wrapper_id,
],
];
if (!empty($configuration['plugin']) && isset($plugins[$configuration['plugin']])) {
$form['plugin']['#default_value'] = $configuration['plugin'];
$form['configuration'] = [
'#type' => 'commerce_plugin_configuration',
'#plugin_type' => 'commerce_autosku_generator',
'#plugin_id' => $configuration['plugin'],
];
if (!is_null($configuration['configuration'])) {
$form['configuration']['#default_value'] = $configuration['configuration'];
}
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$mode = $form_state
->getValue('mode');
$plugin = $form_state
->getValue('plugin');
$configuration = $form_state
->getValue('configuration');
$this->entity
->setThirdPartySetting('commerce_autosku', 'mode', $mode);
$this->entity
->setThirdPartySetting('commerce_autosku', 'plugin', $plugin);
$this->entity
->setThirdPartySetting('commerce_autosku', 'configuration', $configuration);
$this->entity
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommerceAutoSkuForm:: |
protected | property | The commerce autoSku generator plugin manager. | |
CommerceAutoSkuForm:: |
protected | property | The commerce autoSku generator plugin manager. | |
CommerceAutoSkuForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
CommerceAutoSkuForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
CommerceAutoSkuForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
CommerceAutoSkuForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
CommerceAutoSkuForm:: |
public | function | AutoEntityLabelController constructor. | |
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 | Retrieves a configuration object. | |
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. | |
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. |