class SkypeSettingsForm in Skype 8
Class SkypeSettingsForm.
@package Drupal\skype\Form
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\skype\Form\SkypeSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SkypeSettingsForm
1 string reference to 'SkypeSettingsForm'
File
- src/
Form/ SkypeSettingsForm.php, line 14
Namespace
Drupal\skype\FormView source
class SkypeSettingsForm extends ConfigFormBase {
protected $enabled;
protected $buttonStyle;
protected $initiateChat;
/**
* SkypeSettingsForm constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
*/
public function __construct(ConfigFactoryInterface $config_factory) {
parent::__construct($config_factory);
$config = $this
->config('skype.settings');
$this->enabled = $config
->get('enable_chat');
$this->initiateChat = $config
->get('initiate_chat');
$this->buttonStyle = $config
->get('button_style');
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'skype_settings_form';
}
/**
* {@inheritdoc}
*/
public function getEditableConfigNames() {
return [
'skype.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('skype.settings');
$form['#prefix'] = '<div id="skype-settings-ajax-wrapper">';
$form['#suffix'] = '</div>';
$ajax = [
'wrapper' => 'skype-settings-ajax-wrapper',
'callback' => '::ajaxRefreshForm',
'trigger_as' => [
'name' => 'dummy_submit',
],
];
$form['enable_chat'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable chat canvas'),
'#default_value' => $config
->get('enable_chat'),
'#description' => $this
->t('You can read the documentation on the Skype chat canvas <a href="@href" target="_blank">here</a>', [
'@href' => 'https://dev.skype.com/webcontrol',
]),
'#ajax' => $ajax,
];
$form['dummy_submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
'#name' => 'dummy_submit',
'#ajax' => [
'wrapper' => 'skype-settings-ajax-wrapper',
'callback' => '::ajaxRefreshForm',
],
'#submit' => [
'::dummySubmit',
],
'#attributes' => [
'class' => [
'js-hide',
],
],
];
if ($this->enabled) {
$form['message_recipient'] = [
'#type' => 'radios',
'#title' => $this
->t('Message recipient'),
'#options' => [
'data-bot-id' => 'Bot',
'data-contact-id' => $this
->t('Skype user'),
],
'#default_value' => $config
->get('message_recipient'),
'#description' => $this
->t('Note: if the recipient is a Skype user, then users will be prompted to sign in. (Because we want to prevent users from receiving spams)'),
'#required' => TRUE,
];
$form['chat_id'] = [
'#type' => 'textfield',
'#title' => $this
->t('Bot/Skype user ID'),
'#default_value' => $config
->get('chat_id'),
'#description' => $this
->t('Depends on the option chosen in "Message Recipient"'),
'#required' => TRUE,
];
$form['initiate_chat'] = [
'#type' => 'radios',
'#title' => $this
->t('Initiate chat'),
'#options' => [
'skype-button' => $this
->t('Button'),
'skype-chat' => $this
->t('Chat'),
],
'#default_value' => $config
->get('initiate_chat'),
'#description' => $this
->t('Use a Skype button to initiate a chat or show the chat immediately'),
'#required' => TRUE,
'#ajax' => $ajax,
];
if ($this->initiateChat == 'skype-button') {
$form['button_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Buttons settings'),
'#open' => TRUE,
];
$form['button_settings']['button_style'] = [
'#type' => 'select',
'#title' => $this
->t('Button style'),
'#options' => [
'bubble' => $this
->t('Bubble'),
'rectangle' => $this
->t('Rectangle'),
'rounded' => $this
->t('Rounded'),
],
'#default_value' => $config
->get('button_style'),
'#description' => $this
->t('Set an out-of-the-box style for the button'),
'#required' => TRUE,
'#ajax' => $ajax,
];
if ($this->buttonStyle == 'rectangle' || $this->buttonStyle == 'rounded') {
$form['button_settings']['text_only'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Text only'),
'#default_value' => $config
->get('text_only'),
'#description' => $this
->t('Do not show the chat icon'),
];
$form['button_settings']['button_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Button text'),
'#default_value' => $config
->get('button_text'),
'#description' => $this
->t('Change the label of the button, eg: Contact'),
];
$form['button_settings']['button_color'] = [
'#type' => 'textfield',
'#title' => $this
->t('Button color'),
'#default_value' => $config
->get('button_color'),
'#description' => $this
->t('Change the button color, eg: #00AFF0'),
];
}
}
elseif ($this->initiateChat == 'skype-chat') {
$form['chat_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Chat settings'),
'#open' => TRUE,
];
$form['chat_settings']['chat_can_collapse'] = [
'#type' => 'checkbox',
'#title' => 'Chat can collapse',
'#default_value' => $config
->get('chat_can_collapse'),
'#description' => $this
->t('Enables minimization functionality'),
];
$form['chat_settings']['chat_can_close'] = [
'#type' => 'checkbox',
'#title' => 'Chat can close',
'#default_value' => $config
->get('chat_can_close'),
'#description' => $this
->t('Enables the close button'),
];
$form['chat_settings']['chat_can_upload_file'] = [
'#type' => 'checkbox',
'#title' => 'Chat can upload file',
'#default_value' => $config
->get('chat_can_upload_file'),
'#description' => $this
->t('Enables the upload file button'),
];
$form['chat_settings']['chat_enable_animation'] = [
'#type' => 'checkbox',
'#title' => 'Opening animation enabled',
'#default_value' => $config
->get('chat_enable_animation'),
'#description' => $this
->t('Enables the opening animation'),
];
$form['chat_settings']['chat_enable_header'] = [
'#type' => 'checkbox',
'#title' => 'Header enabled',
'#default_value' => $config
->get('chat_enable_header'),
'#description' => $this
->t('Enables the conversation header'),
];
}
$form['page_track'] = [
'#type' => 'details',
'#title' => $this
->t('Pages'),
'#open' => TRUE,
];
$form['page_track']['exclude_mode'] = [
'#type' => 'radios',
'#title' => $this
->t('Add Skype chat canvas to specific pages'),
'#options' => [
0 => $this
->t('Every page except the listed pages'),
1 => $this
->t('The listed pages only'),
],
'#default_value' => $config
->get('exclude_mode'),
'#required' => TRUE,
];
$form['page_track']['exclude_pages'] = [
'#type' => 'textarea',
'#title' => $this
->t('Pages'),
'#title_display' => 'invisible',
'#default_value' => $config
->get('exclude_pages'),
'#description' => $this
->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.\", ['%blog' => '/blog', '%blog-wildcard' => '/blog/*', '%front' => '<front>']"),
'#rows' => 10,
];
}
return parent::buildForm($form, $form_state);
}
/**
* Ajax callback to refresh form.
*
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*
* @return array
*/
public function ajaxRefreshForm(array &$form, FormStateInterface $form_state) {
return $form;
}
/**
* Dummy submit callback to change rebuild form after ajax call.
*
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*/
public function dummySubmit(array &$form, FormStateInterface $form_state) {
$this->enabled = $form_state
->getValue('enable_chat');
if (!empty($form_state
->getValue('initiate_chat'))) {
$this->initiateChat = $form_state
->getValue('initiate_chat');
}
if (!empty($form_state
->getValue('button_style'))) {
$this->buttonStyle = $form_state
->getValue('button_style');
}
$form_state
->setRebuild(TRUE);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('skype.settings');
$config
->set('enable_chat', $form_state
->getValue('enable_chat'));
$config
->set('message_recipient', $form_state
->getValue('message_recipient'));
$config
->set('chat_id', $form_state
->getValue('chat_id'));
$config
->set('initiate_chat', $form_state
->getValue('initiate_chat'));
$config
->set('button_style', $form_state
->getValue('button_style'));
$config
->set('text_only', $form_state
->getValue('text_only'));
$config
->set('button_text', $form_state
->getValue('button_text'));
$config
->set('button_color', $form_state
->getValue('button_color'));
$config
->set('chat_can_collapse', $form_state
->getValue('chat_can_collapse'));
$config
->set('chat_can_close', $form_state
->getValue('chat_can_close'));
$config
->set('chat_can_upload_file', $form_state
->getValue('chat_can_upload_file'));
$config
->set('chat_enable_animation', $form_state
->getValue('chat_enable_animation'));
$config
->set('chat_can_upload_file', $form_state
->getValue('chat_can_upload_file'));
$config
->set('chat_enable_header', $form_state
->getValue('chat_enable_header'));
$config
->set('exclude_mode', $form_state
->getValue('exclude_mode'));
$config
->set('exclude_pages', $form_state
->getValue('exclude_pages'));
$config
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
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. | |
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. | |
SkypeSettingsForm:: |
protected | property | ||
SkypeSettingsForm:: |
protected | property | ||
SkypeSettingsForm:: |
protected | property | ||
SkypeSettingsForm:: |
public | function | Ajax callback to refresh form. | |
SkypeSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SkypeSettingsForm:: |
public | function | Dummy submit callback to change rebuild form after ajax call. | |
SkypeSettingsForm:: |
public | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SkypeSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SkypeSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SkypeSettingsForm:: |
public | function |
SkypeSettingsForm constructor. 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. |