class BaseExtension in Markdown 3.0.x
Base class for markdown extensions.
Plugin annotation
@MarkdownExtension(
id = "_broken",
label = @Translation("Missing Extension"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\markdown\Plugin\Markdown\Extension\BaseExtension implements MarkdownExtensionInterface uses MarkdownStatesTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of BaseExtension
File
- src/
Plugin/ Markdown/ Extension/ BaseExtension.php, line 22
Namespace
Drupal\markdown\Plugin\Markdown\ExtensionView source
class BaseExtension extends PluginBase implements MarkdownExtensionInterface {
use MarkdownStatesTrait;
/**
* {@inheritdoc}
*/
public static function installed() : bool {
return FALSE;
}
/**
* {@inheritdoc}
*/
public static function version() {
return NULL;
}
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
}
/**
* Returns generic default configuration for markdown extension plugins.
*
* @return array
* An associative array with the default configuration.
*/
protected function baseConfigurationDefaults() {
return [
'id' => $this
->getPluginId(),
'label' => $this
->t('Broken'),
'provider' => $this->pluginDefinition['provider'],
'settings' => $this
->defaultSettings() + [
'enabled' => FALSE,
],
];
}
/**
* {@inheritdoc}
*/
public function defaultSettings() {
return [];
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->pluginDefinition['description'] ?? NULL;
}
/**
* {@inheritdoc}
*/
public function getLabel($version = TRUE) {
$label = $this->pluginDefinition['label'] ?? $this->pluginId;
if ($version && ($version = $this
->getVersion())) {
$label .= " ({$version})";
}
return $label;
}
/**
* {@inheritdoc}
*/
public function getSetting($name) {
$settings = $this
->getSettings();
return isset($settings[$name]) ? $settings[$name] : NULL;
}
/**
* {@inheritdoc}
*/
public function getUrl() {
$url = $this->pluginDefinition['url'] ?? NULL;
if ($url && UrlHelper::isExternal($url)) {
return Url::fromUri($url);
}
return $url ? Url::fromUserInput($url) : NULL;
}
/**
* {@inheritdoc}
*/
public function getVersion() {
return $this->pluginDefinition['version'] ?? NULL;
}
/**
* {@inheritdoc}
*/
public function isEnabled() {
return !!$this
->getSetting('enabled');
}
/**
* {@inheritdoc}
*/
public function isInstalled() : bool {
return $this->pluginDefinition['installed'] ?? FALSE;
}
/**
* {@inheritdoc}
*/
public function label() {
return $this->configuration['label'] ?: $this->pluginId;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->baseConfigurationDefaults(), $this
->defaultConfiguration(), $configuration);
}
/**
* {@inheritdoc}
*/
public function getSettings() {
return $this->configuration['settings'];
}
/**
* {@inheritdoc}
*/
public function setSetting($name, $value = NULL) {
if (isset($value)) {
// Get the type of the exist value (if any).
if (isset($this->configuration['settings'][$name]) && ($type = gettype($this->configuration['settings'][$name]))) {
$original_value = is_object($value) ? clone $value : $value;
if (!settype($value, $type)) {
$value = $original_value;
}
}
$this->configuration['settings'][$name] = $value;
}
else {
unset($this->configuration['settings'][$name]);
}
}
/**
* {@inheritdoc}
*/
public function setSettings(array $settings = []) {
foreach ($settings as $name => $value) {
$this
->setSetting($name, $value);
}
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $element, FormStateInterface $formState, MarkdownFilterInterface $filter) {
$definition = $this
->getPluginDefinition();
$element['provider'] = [
'#type' => 'value',
'#value' => $definition['provider'],
];
return $element;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BaseExtension:: |
protected | function | Returns generic default configuration for markdown extension plugins. | |
BaseExtension:: |
public | function | ||
BaseExtension:: |
public | function | ||
BaseExtension:: |
public | function |
Retrieves the default settings. Overrides MarkdownExtensionInterface:: |
3 |
BaseExtension:: |
public | function | ||
BaseExtension:: |
public | function |
Retrieves the description of the plugin, if set. Overrides MarkdownInstallablePluginInterface:: |
|
BaseExtension:: |
public | function |
Displays the human-readable label of the plugin. Overrides MarkdownInstallablePluginInterface:: |
|
BaseExtension:: |
public | function |
Retrieves a setting. Overrides MarkdownExtensionInterface:: |
|
BaseExtension:: |
public | function |
Retrieves the current settings. Overrides MarkdownExtensionInterface:: |
|
BaseExtension:: |
public | function |
Retrieves the URL of the plugin, if set. Overrides MarkdownInstallablePluginInterface:: |
|
BaseExtension:: |
public | function |
The current version of the parser. Overrides MarkdownInstallablePluginInterface:: |
|
BaseExtension:: |
public static | function |
Indicates whether the parser is installed. Overrides MarkdownInstallablePluginInterface:: |
|
BaseExtension:: |
public | function |
Indicates whether the extension is being used. Overrides MarkdownExtensionInterface:: |
|
BaseExtension:: |
public | function |
Indicates whether the parser is installed. Overrides MarkdownInstallablePluginInterface:: |
|
BaseExtension:: |
public | function | ||
BaseExtension:: |
public | function | ||
BaseExtension:: |
public | function |
Sets a specific setting. Overrides MarkdownExtensionInterface:: |
|
BaseExtension:: |
public | function |
Provides settings to an extension. Overrides MarkdownExtensionInterface:: |
|
BaseExtension:: |
public | function |
Returns the configuration form elements specific to this plugin. Overrides MarkdownExtensionInterface:: |
3 |
BaseExtension:: |
public static | function |
Retrieves the version of the installed parser. Overrides MarkdownInstallablePluginInterface:: |
|
BaseExtension:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MarkdownStatesTrait:: |
protected static | function | Retrieves the ancestry of the extension in a form/render array. | |
MarkdownStatesTrait:: |
protected static | function | Retrieves a states selector to use based on the form/render array parents. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
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:: |
2 |
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. | 4 |
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. |