class MathjaxSettingsForm in MathJax: LaTeX for Drupal 8.2
Same name and namespace in other branches
- 3.0.x src/Form/MathjaxSettingsForm.php \Drupal\mathjax\Form\MathjaxSettingsForm
Presents the module settings 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\mathjax\Form\MathjaxSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of MathjaxSettingsForm
1 string reference to 'MathjaxSettingsForm'
File
- src/
Form/ MathjaxSettingsForm.php, line 12
Namespace
Drupal\mathjax\FormView source
class MathjaxSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'mathjax_admin_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'mathjax.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('mathjax.settings');
$form['test'] = array(
'#type' => 'fieldset',
'#title' => 'MathJax Test',
);
$form['test']['library'] = array(
'#type' => 'item',
'#markup' => '<div class="tex2jax_process"><p>If the MathJax library is installed properly, you should see the square root of x here: $ \\sqrt{x} $ and the square root of y here: \\(\\sqrt{y}\\)</p><p>$$\\text{The quadratic formula should appear here: } x = \\frac {-b \\pm \\sqrt {b^2 - 4ac}}{2a}$$</p><p>\\[\\text{The cubic equation should appear here: } a x^3\\; +\\; b x^2\\; +\\; c x\\; +\\; d\\; =\\; 0\\]</p></div>',
);
$form['use_cdn'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Use MathJax Content Delivery Network (CDN)'),
'#default_value' => $config
->get('use_cdn'),
'#description' => t('Check this box to load MathJax source from MathJax servers (recommended) or from the link you can provide below. If you do not check this box, see the README about configuring a local MathJax source. <em>MathJax CDN services are provided subject to its <a href=":url">Terms of Service</a> (TOS). By accessing and using the MathJax CDN, you accept and agree to be bound by the terms and provisions of the TOS</em>.', [
':url' => 'https://www.mathjax.org/mathjax-cdn-terms-of-service/',
]),
);
$form['cdn_url'] = array(
'#type' => 'textfield',
'#title' => $this
->t('MathJax CDN URL'),
'#default_value' => $config
->get('cdn_url'),
'#description' => $this
->t("Enter the Mathjax CDN url here or leave it unchanged to use the one provided by <a target='_blank' href=':url'>www.mathjax.org</a>.", array(
':url' => 'http://www.mathjax.org',
)),
'#states' => array(
'invisible' => array(
':input[name="use_cdn"]' => array(
'checked' => FALSE,
),
),
),
);
$form['config_type'] = array(
'#type' => 'radios',
'#title' => $this
->t('Configuration Type'),
'#options' => array(
0 => $this
->t('Text Format (Recommended—Add the MathJax filter to a <a href=":textformats">text format</a>.)', array(
':textformats' => Url::fromRoute('filter.admin_overview')
->toString(),
)),
1 => $this
->t('Custom'),
),
'#default_value' => $config
->get('config_type'),
);
$form['mathjax_note_default'] = array(
'#type' => 'item',
'#prefix' => '<span class="tex2jax_ignore">',
'#markup' => $this
->t('MathJax
will be available as a text filter. Mathematics inside the
default delimiters will be rendered by MathJax. The
default math delimiters are $$...$$ and \\[...\\] for displayed mathematics,
and $...$ and \\(...\\) for in-line mathematics. <strong>You must add
the MathJax filter to a <a href=":textformats">text format</a> and put
MathJax at the bottom of the filter processing order.</strong>', array(
':textformats' => Url::fromRoute('filter.admin_overview')
->toString(),
)),
'#suffix' => '</span>',
'#states' => array(
'invisible' => array(
':input[name="config_type"]' => array(
'value' => 1,
),
),
),
);
$form['config_string'] = array(
'#type' => 'textarea',
'#title' => $this
->t('Custom configuration'),
'#default_value' => $config
->get('config_string') ? $config
->get('config_string') : $config
->get('default_config_string'),
'#description' => $this
->t("Enter a JSON configuration string as documented on <a target='_blank' href=':mathjax-help'>MathJax help</a>. Use with caution as you may introduce JavaScript errors.", array(
':mathjax-help' => 'http://docs.mathjax.org/en/latest/',
)),
'#states' => array(
'invisible' => array(
':input[name="config_type"]' => array(
'value' => 0,
),
),
),
);
$config_type = $config
->get('config_type');
if ($config_type == 0) {
$config_string = $config
->get('default_config_string');
}
else {
$config_string = $config
->get('config_string');
}
$form['#attached'] = [
'library' => [
'mathjax/source',
],
'drupalSettings' => [
'mathjax' => [
'config_type' => $config_type,
'config' => json_decode($config_string),
],
],
];
$form['enable_for_admin'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable on admin pages.'),
'#description' => $this
->t('Embeds the MathJax code on admin pages.'),
'#default_value' => $config
->get('enable_for_admin'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('mathjax.settings')
->set('use_cdn', $form_state
->getValue('use_cdn'))
->set('cdn_url', $form_state
->getValue('cdn_url'))
->set('config_type', $form_state
->getValue('config_type'))
->set('config_string', $form_state
->getValue('config_string'))
->set('enable_for_admin', $form_state
->getValue('enable_for_admin'))
->save();
drupal_flush_all_caches();
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 |
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. | |
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. | |
MathjaxSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
MathjaxSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
MathjaxSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
MathjaxSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
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. |