abstract class FlagTypeBase in Flag 8.4
Provides a base class for flag type plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\flag\FlagType\FlagTypeBase implements FlagTypePluginInterface uses StringTranslationTrait
Expanded class hierarchy of FlagTypeBase
1 file declares its use of FlagTypeBase
- EntityFlagType.php in src/
Plugin/ Flag/ EntityFlagType.php
File
- src/
FlagType/ FlagTypeBase.php, line 20
Namespace
Drupal\flag\FlagTypeView source
abstract class FlagTypeBase extends PluginBase implements FlagTypePluginInterface {
use StringTranslationTrait;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, ModuleHandlerInterface $module_handler, TranslationInterface $string_translation) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleHandler = $module_handler;
$this->configuration += $this
->defaultConfiguration();
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('module_handler'), $container
->get('string_translation'));
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
}
/**
* Provides a form for this action link plugin settings.
*
* The form provided by this method is displayed by the FlagAddForm when
* creating or editing the Flag. Derived classes should override this.
*
* @param array $form
* The form array.
* @param FormStateInterface $form_state
* The form state.
*
* @return array
* The form array
*
* @see \Drupal\flag\Form\FlagAddForm
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
/**
* Handles the form submit for this action link plugin.
*
* Derived classes will want to override this.
*
* @param array $form
* The form array.
* @param FormStateInterface $form_state
* The form state.
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
// Override this.
}
/**
* Handles the validation for the action link plugin settings form.
*
* @param array $form
* The form array.
* @param FormStateInterface $form_state
* The form state.
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
// Override this.
}
/**
* Defines options for extra permissions.
*
* @return array
* An array of options suitable for FormAPI.
*/
protected function getExtraPermissionsOptions() {
return [];
}
/**
* Determines whether the flag is set to have the extra permissions set.
*
* @param string $option
* The name of an extra permissions set. These are defined in
* getExtraPermissionsOptions().
*
* @return bool
* TRUE if the flag is configured to have the permissions, FALSE if not.
*/
protected function hasExtraPermission($option) {
return in_array($option, $this->configuration['extra_permissions']);
}
/**
* {@inheritdoc}
*/
public function actionPermissions(FlagInterface $flag) {
return [
'flag ' . $flag
->id() => [
'title' => $this
->t('Flag %flag_title', [
'%flag_title' => $flag
->label(),
]),
],
'unflag ' . $flag
->id() => [
'title' => $this
->t('Unflag %flag_title', [
'%flag_title' => $flag
->label(),
]),
],
];
}
/**
* {@inheritdoc}
*/
public function actionAccess($action, FlagInterface $flag, AccountInterface $account, EntityInterface $flaggable = NULL) {
// Collect access results from objects.
$results = $this->moduleHandler
->invokeAll('flag_action_access', [
$action,
$flag,
$account,
$flaggable,
]);
// Add default access check.
$results[] = AccessResult::allowedIfHasPermission($account, $action . ' ' . $flag
->id());
/** @var \Drupal\Core\Access\AccessResultInterface $return */
$return = array_shift($results);
foreach ($results as $next) {
$return = $return
->orIf($next);
}
return $return;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlagTypeBase:: |
protected | property | The module handler. | |
FlagTypeBase:: |
public | function |
Checks whether a user has permission to flag/unflag or not. Overrides FlagTypePluginInterface:: |
1 |
FlagTypeBase:: |
public | function |
Returns the permissions available to this flag type. Overrides FlagTypePluginInterface:: |
1 |
FlagTypeBase:: |
public | function |
Provides a form for this action link plugin settings. Overrides PluginFormInterface:: |
1 |
FlagTypeBase:: |
public | function | ||
FlagTypeBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
FlagTypeBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
1 |
FlagTypeBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
FlagTypeBase:: |
protected | function | Defines options for extra permissions. | 1 |
FlagTypeBase:: |
protected | function | Determines whether the flag is set to have the extra permissions set. | |
FlagTypeBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
FlagTypeBase:: |
public | function |
Handles the form submit for this action link plugin. Overrides PluginFormInterface:: |
1 |
FlagTypeBase:: |
public | function |
Handles the validation for the action link plugin settings form. Overrides PluginFormInterface:: |
|
FlagTypeBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |
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. | |
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. |