class Simplelogin in SimpleLogin 8.6
Defines a form that configure settings.
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\simplelogin\Form\Simplelogin
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of Simplelogin
1 string reference to 'Simplelogin'
File
- src/
Form/ Simplelogin.php, line 22 - Contains \Drupal\simplelogin\Form\SettingsForm. Simplelogin settings form.
Namespace
Drupal\simplelogin\FormView source
class Simplelogin extends ConfigFormBase {
/**
* Image factory.
*
* @var \Drupal\Core\Image\ImageFactory
* Image factory.
*/
protected $imageFactory;
/**
* {@inheritdoc}
*/
public function __construct(ConfigFactoryInterface $config_factory, ImageFactory $image_factory) {
parent::__construct($config_factory);
$this->imageFactory = $image_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('image.factory'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'simplelogin_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'simplelogin.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$form_state
->disableCache();
$simplelogin_config = $this
->config('simplelogin.settings');
$imageid = $simplelogin_config
->get('background_image');
if ($imageid) {
$file = File::load($imageid[0]);
// File Load
$fileUrl = $file
->getFileUri();
// Check if image is valid.
$image = $this->imageFactory
->get($fileUrl);
if ($image
->isValid()) {
$image_render = array(
'#theme' => 'image_style',
'#width' => $image
->getWidth(),
'#height' => $image
->getHeight(),
'#style_name' => 'medium',
'#uri' => $fileUrl,
);
}
}
$form['simplelogin'] = array(
'#type' => 'details',
'#title' => $this
->t('Configuration'),
'#open' => TRUE,
'background_active' => array(
'#type' => 'checkbox',
'#title' => $this
->t('Background Image'),
'#default_value' => $simplelogin_config
->get('background_active'),
'#description' => $this
->t('If enabled, the background image will be added on the simple login pages.'),
),
'settings' => array(
'#type' => 'details',
'#title' => $this
->t('Background Image Settings'),
'#open' => TRUE,
'background_image' => array(
'#type' => 'managed_file',
'#name' => 'Background Image',
'#title' => $this
->t('Image'),
'#default_value' => $simplelogin_config
->get('background_image') ? $simplelogin_config
->get('background_image') : '',
'#description' => $this
->t('Upload an image file for the Simplelogin pages'),
'#upload_location' => 'public://simplelogin/',
'#multiple' => FALSE,
'#upload_validators' => array(
'file_validate_is_image' => array(),
'file_validate_extensions' => array(
'gif png jpg jpeg',
),
'file_validate_size' => array(
25600000,
),
),
),
'background_url' => array(
'#type' => 'item',
'#markup' => render($image_render),
),
'background_opacity' => array(
'#type' => 'checkbox',
'#title' => $this
->t('Opacity'),
'#default_value' => $simplelogin_config
->get('background_opacity'),
'#description' => $this
->t('If enabled, the opacity will be added to the SimpleLogin pages. so the background image will take up with opacity.'),
),
),
'background_color' => array(
'#type' => 'color',
'#title' => $this
->t('Color'),
'#required' => TRUE,
'#default_value' => $simplelogin_config
->get('background_color') ? $simplelogin_config
->get('background_color') : '#00bfff',
//#76b852',
'#description' => $this
->t('If you want the background color you need to remove the background image. (example: [Red: 0, Green:191, Blue:255] , [red:118, Green:184, Blue:82])'),
),
'wrapper_width' => array(
'#type' => 'textfield',
'#title' => $this
->t('Wrapper width'),
'#default_value' => $simplelogin_config
->get('wrapper_width') ? $simplelogin_config
->get('wrapper_width') : '360',
'#description' => $this
->t('Simplelogin wrapper width in pixels.(example:360)'),
'#field_suffix' => 'PX',
'#size' => 5,
'#required' => TRUE,
),
'advanced' => array(
'#type' => 'details',
'#title' => $this
->t('Advanced Settings'),
'#open' => FALSE,
'unset_active_css' => array(
'#type' => 'checkbox',
'#title' => $this
->t('Unset Active theme CSS files'),
'#default_value' => $simplelogin_config
->get('unset_active_css'),
'#description' => $this
->t('If enabled, active theme CSS files are removed from the simple login pages.'),
),
'unset_css' => array(
'#type' => 'textarea',
'#title' => $this
->t('Unset CSS file path'),
'#default_value' => $simplelogin_config
->get('unset_css') ? $simplelogin_config
->get('unset_css') : '',
'#description' => $this
->t('Remove unwanted CSS files each path as a separate line(example: core/themes/classy/css/components/button.css)'),
),
),
);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$background_image = $form_state
->getValue([
'background_image',
]);
$opacity = $form_state
->getValue([
'background_opacity',
]);
if (empty($background_image) && !empty($opacity)) {
$form_state
->setErrorByName('background_image', "Opacity is applicable only for images. if image empty means we won't need Opacity. Please uncheck");
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$image_id = isset($values['background_image']) ? $values['background_image'] : '';
if (!empty($image_id)) {
$file = File::load($image_id[0]);
if ($file instanceof File) {
$file
->setPermanent();
// FILE_STATUS_PERMANENT;
$file
->save();
}
}
$this
->config('simplelogin.settings')
->set('background_active', $values['background_active'])
->set('background_image', $values['background_image'])
->set('background_color', $values['background_color'])
->set('background_opacity', $values['background_opacity'])
->set('wrapper_width', $values['wrapper_width'])
->set('unset_active_css', $values['unset_active_css'])
->set('unset_css', $values['unset_css'])
->save();
drupal_flush_all_caches();
}
}
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. | |
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. | |
Simplelogin:: |
protected | property | Image factory. | |
Simplelogin:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
Simplelogin:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
Simplelogin:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
Simplelogin:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
Simplelogin:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
Simplelogin:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
Simplelogin:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase:: |
|
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. |