class GoogleQRCodeAdminForm in Google QR Code Generator 8
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\google_qr_code\Form\GoogleQRCodeAdminForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of GoogleQRCodeAdminForm
1 string reference to 'GoogleQRCodeAdminForm'
File
- src/
Form/ GoogleQRCodeAdminForm.php, line 16
Namespace
Drupal\google_qr_code\FormView source
class GoogleQRCodeAdminForm extends ConfigFormBase {
// Establish form ID.
public function getFormID() {
return 'googleqrcode_admin_settings';
}
// Establish what values are editable via the form.
public function getEditableConfigNames() {
return [
'google_qr_code.settings',
];
}
// Build out the form.
public function buildForm(array $form, FormStateInterface $form_state) {
// Load configuration values
$config = $this
->config('google_qr_code.settings');
$form['google_qr_code_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Google QR Code Configuration'),
);
$form['google_qr_code_settings']['google_qr_code_when_show'] = array(
'#type' => 'select',
'#title' => t('When to render QR COde'),
'#options' => array(
"on_pageload" => t('On Page Load'),
"on_click" => t('On Click'),
),
'#default_value' => $config
->get('whenshow') ? $config
->get('whenshow') : 'on_pageload',
'#required' => FALSE,
'#description' => t('Choose whether you want the QR code to load everytime the page loads (jQuery code) or only get the QR code when generate text in block is clicked.'),
);
$form['google_qr_code_image_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Google QR Code Image Settings'),
'#description' => t('Configure QR code width and height here. There is a
maximum size of 1000 pixels for any single dimension, and a total size
of 300,000 pixels'),
);
$form['google_qr_code_image_settings']['google_qr_code_height'] = array(
'#type' => 'textfield',
'#title' => t('QR Code Height'),
'#default_value' => $config
->get('height') ? $config
->get('height') : 250,
'#size' => 40,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => t('Enter the QR Code Height'),
);
$form['google_qr_code_image_settings']['google_qr_code_width'] = array(
'#type' => 'textfield',
'#title' => t('QR Code Width'),
'#default_value' => $config
->get('width') ? $config
->get('width') : 250,
'#size' => 40,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => t('Enter the QR Code Width'),
);
return parent::buildForm($form, $form_state);
}
// Form validation.
public function validateForm(array &$form, FormStateInterface $form_state) {
// Check that entered values are numeric.
if (!is_numeric($form_state
->getValue('google_qr_code_height')) || !is_numeric($form_state
->getValue('google_qr_code_width'))) {
$error_text = $this
->t('Values entered for height and width must be numeric!');
$form_state
->setErrorByName('google_qr_code_image_settings', $error_text);
}
// Check entered pixels VS maximum amount of pixels.
$total_pixels = $form_state
->getValue('google_qr_code_height') * $form_state
->getValue('google_qr_code_width');
if ($total_pixels > 300000) {
$error_text = $this
->t('Total dimensions cannot exceed 300,000px. Currently at @total px', array(
'@total' => $total_pixels,
));
$form_state
->setErrorByName('google_qr_code_image_settings', $error_text);
}
parent::validateForm($form, $form_state);
// TODO: Change the autogenerated stub
}
// Submit form processing function.
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('google_qr_code.settings')
->set('whenshow', $form_state
->getValue('google_qr_code_when_show'))
->set('height', $form_state
->getValue('google_qr_code_height'))
->set('width', $form_state
->getValue('google_qr_code_width'))
->save();
parent::submitForm($form, $form_state);
}
// Helper function to determine a fields maximum singular dimension.
private function _google_qr_code_max_single_dimension($element) {
if (!empty($element['#value']) && !is_numeric($element['#value'])) {
form_error($element, t('Has to be a number. Do not include "px"'));
}
else {
if (!empty($element['#value']) && $element['#value'] > 1000) {
form_error($element, t('Google does not allow single dimensions over 1000px'));
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
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. | |
FormInterface:: |
public | function | Returns a unique string identifying the form. | 236 |
GoogleQRCodeAdminForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
GoogleQRCodeAdminForm:: |
public | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
GoogleQRCodeAdminForm:: |
public | function | ||
GoogleQRCodeAdminForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
GoogleQRCodeAdminForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
GoogleQRCodeAdminForm:: |
private | function | ||
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. |