class AJAXactionLink in Flag 8.4
Provides the AJAX link type.
This class is an extension of the Reload link type, but modified to provide AJAX links.
Plugin annotation
@ActionLinkType(
id = "ajax_link",
label = @Translation("AJAX link"),
description = @Translation("An AJAX JavaScript request will be made without reloading the page.")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\flag\ActionLink\ActionLinkTypeBase implements ContainerFactoryPluginInterface, ActionLinkTypePluginInterface uses RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\flag\Plugin\ActionLink\Reload
- class \Drupal\flag\Plugin\ActionLink\AJAXactionLink
- class \Drupal\flag\Plugin\ActionLink\Reload
- class \Drupal\flag\ActionLink\ActionLinkTypeBase implements ContainerFactoryPluginInterface, ActionLinkTypePluginInterface uses RedirectDestinationTrait, StringTranslationTrait
Expanded class hierarchy of AJAXactionLink
1 file declares its use of AJAXactionLink
- CountLink.php in modules/
flag_count/ src/ Plugin/ ActionLink/ CountLink.php
File
- src/
Plugin/ ActionLink/ AJAXactionLink.php, line 23
Namespace
Drupal\flag\Plugin\ActionLinkView source
class AJAXactionLink extends Reload {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* Build a new link type instance and sets the configuration.
*
* @param array $configuration
* The configuration array with which to initialize this plugin.
* @param string $plugin_id
* The ID with which to initialize this plugin.
* @param array $plugin_definition
* The plugin definition array.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request from the request stack.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, AccountInterface $current_user, Request $request) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $current_user);
$this->request = $request;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_user'), $container
->get('request_stack')
->getCurrentRequest());
}
/**
* {@inheritdoc}
*/
protected function getDestination() {
if ($destination = $this->request->query
->get('destination')) {
// Workaround the default behavior so we keep the GET[destination] value
// no matter how many times the flag is clicked.
return $destination;
}
parent::getDestination();
}
/**
* {@inheritdoc}
*/
public function getAsFlagLink(FlagInterface $flag, EntityInterface $entity) {
$build = parent::getAsFlagLink($flag, $entity);
$build['#attached']['library'][] = 'flag/flag.link_ajax';
$build['#attributes']['class'][] = 'use-ajax';
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActionLinkTypeBase:: |
protected | property | The current user. | |
ActionLinkTypeBase:: |
public | function |
Provides a form array for the action link plugin's settings form. Overrides PluginFormInterface:: |
1 |
ActionLinkTypeBase:: |
public | function | ||
ActionLinkTypeBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
1 |
ActionLinkTypeBase:: |
protected | function | Helper method to get the next flag action the user can take. | |
ActionLinkTypeBase:: |
public | function |
Get the action link as a Link object. Overrides ActionLinkTypePluginInterface:: |
|
ActionLinkTypeBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ActionLinkTypeBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ActionLinkTypeBase:: |
public | function |
Processes the action link setting form submit. Overrides PluginFormInterface:: |
1 |
ActionLinkTypeBase:: |
public | function |
Validates the action link setting form. Overrides PluginFormInterface:: |
1 |
AJAXactionLink:: |
protected | property | The request stack. | |
AJAXactionLink:: |
public static | function |
Creates an instance of the plugin. Overrides ActionLinkTypeBase:: |
|
AJAXactionLink:: |
public | function |
Get the action link formatted for use in entity links. Overrides ActionLinkTypeBase:: |
1 |
AJAXactionLink:: |
protected | function |
Helper method to generate a destination URL parameter. Overrides ActionLinkTypeBase:: |
|
AJAXactionLink:: |
public | function |
Build a new link type instance and sets the configuration. Overrides ActionLinkTypeBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
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. | |
Reload:: |
public | function |
Return a Url object for the given flag action. Overrides ActionLinkTypeBase:: |
|
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. |