class FooterSettingsForm in Open Social 10.3.x
Same name and namespace in other branches
- 10.0.x modules/social_features/social_footer/src/Form/FooterSettingsForm.php \Drupal\social_footer\Form\FooterSettingsForm
- 10.1.x modules/social_features/social_footer/src/Form/FooterSettingsForm.php \Drupal\social_footer\Form\FooterSettingsForm
- 10.2.x modules/social_features/social_footer/src/Form/FooterSettingsForm.php \Drupal\social_footer\Form\FooterSettingsForm
Creates a form for configuring footer block.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\social_footer\Form\FooterSettingsForm
Expanded class hierarchy of FooterSettingsForm
1 string reference to 'FooterSettingsForm'
- social_footer.routing.yml in modules/
social_features/ social_footer/ social_footer.routing.yml - modules/social_features/social_footer/social_footer.routing.yml
File
- modules/
social_features/ social_footer/ src/ Form/ FooterSettingsForm.php, line 13
Namespace
Drupal\social_footer\FormView source
class FooterSettingsForm extends FormBase {
/**
* The file storage.
*
* @var \Drupal\file\FileStorageInterface
*/
protected $fileStorage;
/**
* Creates a FooterSettingsForm instance.
*
* @param \Drupal\file\FileStorageInterface $file_storage
* The file storage.
*/
public function __construct(FileStorageInterface $file_storage) {
$this->fileStorage = $file_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager')
->getStorage('file'));
}
/**
* {@inheritDoc}
*/
public function getFormId() {
return 'social_footer_config_form';
}
/**
* {@inheritDoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$block = self::configFactory()
->get('block.block.socialblue_footer_powered');
if ($block) {
$settings = $block
->get('settings');
}
$default_scheme = self::config('system.file')
->get('default_scheme');
$form['logo'] = [
'#type' => 'managed_file',
'#title' => $this
->t('Logo'),
'#upload_location' => $default_scheme . '://',
'#upload_validators' => [
'file_validate_is_image' => [],
],
'#default_value' => [
$settings['logo'],
] ?? NULL,
];
$form['text'] = [
'#type' => 'text_format',
'#title' => $this
->t('Text'),
'#default_value' => $settings['text']['value'] ?? NULL,
'#format' => $settings['text']['format'] ?? 'basic_html',
];
$form['link'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Link') ?? NULL,
];
$form['link']['url'] = [
'#type' => 'url',
'#title' => $this
->t('URL'),
'#default_value' => $settings['link']['url'] ?? NULL,
];
$form['link']['title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Title'),
'#default_value' => $settings['link']['title'] ?? NULL,
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save configuration'),
'#button_type' => 'primary',
];
return $form;
}
/**
* {@inheritDoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$logo = '';
$values = $form_state
->getValues();
if ($values['logo'] = $form_state
->getValue('logo')) {
/** @var \Drupal\file\FileInterface $file */
$file = $this->fileStorage
->load($logo = $values['logo'][0]);
$file
->setPermanent();
$file
->save();
}
$block = self::configFactory()
->getEditable('block.block.socialblue_footer_powered');
if ($block) {
$settings = $block
->get('settings');
$settings['logo'] = $logo;
$settings['text'] = $values['text'];
$settings['link']['url'] = $values['url'];
$settings['link']['title'] = $values['title'];
$block
->set('settings', $settings)
->save();
}
$this
->messenger()
->addStatus(t('Your footer settings have been updated'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FooterSettingsForm:: |
protected | property | The file storage. | |
FooterSettingsForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
FooterSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
FooterSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
FooterSettingsForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
FooterSettingsForm:: |
public | function | Creates a FooterSettingsForm instance. | |
FormBase:: |
protected | property | The config factory. | 3 |
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. | 3 |
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. | |
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:: |
72 |
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. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
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. | 4 |
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. |