class AjaxLinksApiSettingsForm in Ajaxify Drupal with JQuery Ajax 8
Displays the Ajax links API 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\ajax_links_api\Form\AjaxLinksApiSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of AjaxLinksApiSettingsForm
1 file declares its use of AjaxLinksApiSettingsForm
- ajax_links_api.module in ./
ajax_links_api.module - Make any links or create new links via jQuery Ajax.
1 string reference to 'AjaxLinksApiSettingsForm'
File
- src/
Form/ AjaxLinksApiSettingsForm.php, line 11
Namespace
Drupal\ajax_links_api\FormView source
class AjaxLinksApiSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ajax_links_api_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = \Drupal::config('ajax_links_api.admin_settings');
$form['ajax_links_api_trigger'] = array(
'#type' => 'textarea',
'#title' => t('jQuery selector to trigger ajax (One per line)'),
'#default_value' => $config
->get('ajax_links_api.trigger'),
'#description' => t('Just like jQuery, for example by providing ".content a" will ajaxify all link under .content. You can also exclude some selectors by specifying ! (for example "!#toolbar a")'),
);
$form['ajax_links_api_selector'] = array(
'#type' => 'textfield',
'#title' => t('Default Target DIV'),
'#default_value' => $config
->get('ajax_links_api.selector'),
'#description' => t('This can be override for indivdual link by providing rel. Check Demo.'),
);
$form['ajax_links_api_html5'] = array(
'#type' => 'checkbox',
'#title' => t('Enable URL and Title change (for HTML5 Only)'),
'#default_value' => $config
->get('ajax_links_api.html5'),
'#description' => t('Change URL and Title according to ajax content. This will work only for HTML5 supported browsers. Tested on latest Chrome,Firefox.'),
);
$form['ajax_links_api_scripts_included'] = array(
'#type' => 'checkbox',
'#title' => t('Included js-bottom-placeholder in template'),
'#default_value' => $config
->get('ajax_links_api.scripts_included'),
'#description' => t('If you removed js-bottom-placeholder from html--ajax.html.twig, uncheck this. For details, please check https://drupal.org/node/1923320'),
);
$form['ajax_links_api_vpager'] = array(
'#type' => 'checkbox',
'#title' => t('Remove ?ajax=1 from Views pager'),
'#default_value' => $config
->get('ajax_links_api.vpager'),
'#description' => t('Remove ?ajax=1 from Views pager. For details, please check http://drupal.org/node/1907376.'),
);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
\Drupal::configFactory()
->getEditable('ajax_links_api.admin_settings')
->set('ajax_links_api.trigger', $values['ajax_links_api_trigger'])
->set('ajax_links_api.selector', $values['ajax_links_api_selector'])
->set('ajax_links_api.html5', $values['ajax_links_api_html5'])
->set('ajax_links_api.scripts_included', $values['ajax_links_api_scripts_included'])
->set('ajax_links_api.vpager', $values['ajax_links_api_vpager'])
->save();
return parent::submitForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function getEditableConfigNames() {
return [
'ajax_links_api.settings',
];
}
/**
* Get trigger classes/ids.
*
* Ajax links triggers now come in two varieties:
*
* positive triggers: these are selectors that are used to select
* a set of links
* negative triggers: these are selectors used in .not() to remove
* links from the set of matched ones
*
* The user can specify these in the admin/config screen. Negative triggers
* are those listed with a "!" as the first character.
*/
public static function ajaxLinksApiGetTriggers() {
$config = \Drupal::config('ajax_links_api.admin_settings');
$trigger = $config
->get('ajax_links_api.trigger');
$trigger = explode("\n", $trigger);
// Trim all entries.
$trigger = array_map('trim', $trigger);
// Filter out empty lines.
$trigger = array_filter($trigger);
$positive_triggers = array();
$negative_triggers = array();
foreach ($trigger as $this_trigger) {
if (preg_match('/^!/', $this_trigger)) {
$negative_triggers[] = substr($this_trigger, 1);
}
else {
$positive_triggers[] = $this_trigger;
}
}
$positive_trigger = implode(',', $positive_triggers);
$negative_trigger = implode(',', $negative_triggers);
return array(
$positive_trigger,
$negative_trigger,
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxLinksApiSettingsForm:: |
public static | function | Get trigger classes/ids. | |
AjaxLinksApiSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
AjaxLinksApiSettingsForm:: |
public | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
AjaxLinksApiSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AjaxLinksApiSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
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. | |
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. |