abstract class InstallablePluginBase in Markdown 8.2
Base class for installable plugins.
@property \Drupal\markdown\Annotation\InstallablePlugin $pluginDefinition @method \Drupal\markdown\Annotation\InstallablePlugin getPluginDefinition()
@todo Move upstream to https://www.drupal.org/project/installable_plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\markdown\Plugin\Markdown\AnnotatedPluginBase implements AnnotatedPluginInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
- class \Drupal\markdown\Plugin\Markdown\InstallablePluginBase implements InstallablePluginInterface uses PluginDependencyTrait, MoreInfoTrait
- class \Drupal\markdown\Plugin\Markdown\AnnotatedPluginBase implements AnnotatedPluginInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of InstallablePluginBase
File
- src/
Plugin/ Markdown/ InstallablePluginBase.php, line 30
Namespace
Drupal\markdown\Plugin\MarkdownView source
abstract class InstallablePluginBase extends AnnotatedPluginBase implements InstallablePluginInterface {
use MoreInfoTrait;
use PluginDependencyTrait {
getPluginDependencies as getPluginDependenciesTrait;
}
/**
* The config for this plugin.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* {@inheritdoc}
*/
public function buildLibrary(InstallableLibrary $library = NULL) {
}
/**
* {@inheritdoc}
*/
public function buildStatus($all = FALSE) {
$build = [
'#theme_wrappers' => [
'container__installable_libraries',
],
'#attributes' => [
'class' => [
'installable-libraries',
],
],
];
$libraries = $all ? $this->pluginDefinition->libraries : [
$this
->getInstalledLibrary() ?: $this
->getPreferredLibrary(),
];
foreach ($libraries as $library) {
$build[] = [
'#theme' => 'installable_library',
'#plugin' => $this,
'#library' => $library,
];
}
return $build;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
$configuration['id'] = $this
->getPluginId();
$configuration['weight'] = $this->pluginDefinition->weight;
if ($this instanceof EnabledPluginInterface) {
$configuration['enabled'] = $this
->enabledByDefault();
}
if ($this instanceof SettingsInterface) {
$pluginDefinition = $this
->getPluginDefinition();
$settings = isset($pluginDefinition['settings']) ? $pluginDefinition['settings'] : [];
$configuration['settings'] = NestedArray::mergeDeep($settings, static::defaultSettings($pluginDefinition));
}
return $configuration;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$dependencies = [];
if ($this instanceof ObjectWithPluginCollectionInterface) {
foreach ($this
->getPluginCollections() as $pluginCollection) {
foreach ($pluginCollection as $instance) {
$dependencies = array_map('array_unique', NestedArray::mergeDeep($dependencies, $this
->getPluginDependencies($instance)));
}
}
}
return $dependencies;
}
/**
* {@inheritdoc}
*/
public function config() {
return $this->config;
}
/**
* Retrieves available installs.
*
* @return \Drupal\markdown\Plugin\Markdown\InstallablePluginInterface[]
*/
public function getAvailableInstalls() {
$availableInstalls = [];
foreach ($this->pluginDefinition->libraries as $library) {
$definition = clone $this->pluginDefinition;
$definition
->merge($library);
$definition->libraries = [];
$availableInstall = new static($this->configuration, $this->pluginId, $definition);
if ($this instanceof ParserAwareInterface && $availableInstall instanceof ParserAwareInterface) {
$availableInstall
->setParser($this
->getParser());
}
if ($this instanceof FilterAwareInterface && $availableInstall instanceof FilterAwareInterface) {
$availableInstall
->setFilter($this
->getFilter());
}
if ($this instanceof FilterFormatAwareInterface && $availableInstall instanceof FilterFormatAwareInterface) {
$availableInstall
->setFilterFormat($this
->getFilterFormat());
}
$availableInstalls[] = $availableInstall;
}
return $availableInstalls;
}
/**
* Returns the configuration name for the plugin.
*
* @return string
* The configuration name.
*/
protected function getConfigurationName() {
return sprintf('installable.plugin.%s_%s', $this
->getProvider(), $this
->getPluginId());
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
$configuration = parent::getConfiguration();
$configuration['dependencies'] = $this
->getPluginDependencies($this);
if ($this instanceof EnabledPluginInterface) {
$configuration['enabled'] = $this
->isEnabled();
}
if ($this instanceof SettingsInterface) {
// Only return settings that have changed from the default values.
$configuration['settings'] = $this
->getSettingOverrides();
}
return $configuration;
}
/**
* Determines the configuration sort order by weight.
*
* @return int[]
* An array of weights, keyed by top level configuration property names.
*/
protected function getConfigurationSortOrder() {
$order = [
'dependencies' => -100,
'id' => -50,
'weight' => -30,
];
if ($this instanceof EnabledPluginInterface) {
$order['enabled'] = -20;
}
if ($this instanceof SettingsInterface) {
$order['settings'] = -10;
}
return $order;
}
/**
* Retrieves the container.
*
* @return \Symfony\Component\DependencyInjection\ContainerInterface
* The container.
*/
public function getContainer() {
return $this->container instanceof ContainerInterface ? $this->container : \Drupal::getContainer();
}
/**
* {@inheritdoc}
*/
public function getDeprecated() {
return $this->pluginDefinition->deprecated;
}
/**
* {@inheritdoc}
*/
public function getExperimental() {
return $this->pluginDefinition->experimental;
}
/**
* {@inheritdoc}
*/
public function getInstalledId() {
return $this->pluginDefinition
->getInstalledId();
}
/**
* {@inheritdoc}
*/
public function getInstalledLibrary() {
return $this->pluginDefinition
->getInstalledLibrary();
}
/**
* {@inheritdoc}
*
* @TODO: Refactor to use variadic parameters.
*/
public function getObject($args = NULL, $_ = NULL) {
if ($class = $this
->getObjectClass()) {
$ref = new \ReflectionClass($class);
return $ref
->newInstanceArgs(func_get_args());
}
}
/**
* {@inheritdoc}
*/
public function getObjectClass() {
return $this->pluginDefinition->object;
}
/**
* {@inheritdoc}
*/
public function getLabel($version = TRUE) {
$label = $this->pluginDefinition->label ?: $this->pluginDefinition
->getId();
try {
if ($version && ($version = $this
->getVersion())) {
$label .= " ({$version})";
}
} catch (MissingVersionException $exception) {
// Intentionally do nothing.
}
return $label;
}
/**
* {@inheritdoc}
*/
public function getLink($label = NULL, array $options = [], $fallbackToLabel = TRUE) {
return $this->pluginDefinition
->getLink($label, $options, $fallbackToLabel);
}
/**
* {@inheritdoc}
*/
protected function getPluginDependencies(PluginInspectionInterface $instance) {
return array_map('array_unique', $this
->getPluginDependenciesTrait($instance));
}
/**
* {@inheritdoc}
*/
public function getPreferredLibrary() {
return $this->pluginDefinition
->getPreferredLibrary();
}
/**
* {@inheritdoc}
*/
public function getSortedConfiguration() {
$configuration = $this
->getConfiguration();
$weights = $this
->getConfigurationSortOrder() + array_fill_keys(array_keys($configuration), 0);
uksort($configuration, function ($a, $b) use ($weights) {
$a = isset($weights[$a]) ? (int) $weights[$a] : 0;
$b = isset($weights[$b]) ? (int) $weights[$b] : 0;
if ($a === $b) {
return 0;
}
return $a < $b ? -1 : 1;
});
return $configuration;
}
/**
* {@inheritdoc}
*/
public function getUrl(array $options = []) {
if ($url = $this->pluginDefinition->url) {
if (UrlHelper::isExternal($url)) {
$options['attributes']['target'] = '_blank';
return Url::fromUri($url)
->setOptions($options);
}
return Url::fromUserInput($url)
->setOptions($options);
}
}
/**
* {@inheritdoc}
*/
public function getVersion() {
if (!$this->pluginDefinition->version) {
throw new MissingVersionException(sprintf('The library "%s" did not not specify a version. If the plugin has no version, it must be explicitly set to "0.0.0".', $this
->getPluginId()));
}
return $this->pluginDefinition->version;
}
/**
* {@inheritdoc}
*/
public function getVersionConstraint() {
if ($versionRequirement = current($this->pluginDefinition
->getRequirementsByConstraint('Version'))) {
return $versionRequirement->constraints['Version'];
}
}
/**
* {@inheritdoc}
*/
public function hasMultipleLibraries() {
return count($this->pluginDefinition->libraries) > 1;
}
/**
* {@inheritdoc}
*/
public function isInstalled() {
return $this->pluginDefinition
->isInstalled();
}
/**
* {@inheritdoc}
*/
public function isPreferred() {
return $this->pluginDefinition->preferred;
}
/**
* {@inheritdoc}
*/
public function isPreferredLibraryInstalled() {
return $this->pluginDefinition
->isPreferredLibraryInstalled();
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
// Filter out NULL values, they will be provided by default configuration.
$configuration = array_filter($configuration, function ($value) {
return $value !== NULL;
});
// Determine the default configuration for the plugin.
$defaultConfiguration = $this
->defaultConfiguration();
// Generate a new Config object.
$this->config = static::createConfig($this
->getConfigurationName(), $defaultConfiguration, TRUE, $this
->getContainer());
// Determine if there any configuration overrides. Merge defaults using
// a union with passed configuration. This ensures that the difference in
// overrides detected below are not different if they weren't explicitly
// passed.
// @todo This should be a nested union merge.
if ($overrides = $this
->getConfigurationOverrides($configuration + $defaultConfiguration)) {
$this->config
->setModuleOverride($overrides);
}
// Set all the config data as the property on the plugin.
parent::setConfiguration($this->config
->get());
}
protected static function createConfig($name, array $data = [], $immutable = TRUE, ContainerInterface $container = NULL) {
$class = $immutable ? ImmutableConfig::class : Config::class;
if (!$container) {
$container = \Drupal::getContainer();
}
$config = new $class($name, $container
->get('config.storage'), $container
->get('event_dispatcher'), $container
->get('config.typed'));
$config
->initWithData($data);
return $config;
}
/**
* {@inheritdoc}
*/
public function showInUi() {
return $this->pluginDefinition->ui;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AnnotatedPluginBase:: |
protected | property | The original plugin_id that was called, not a fallback identifier. | |
AnnotatedPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Retrieves the configuration overrides for the plugin. Overrides AnnotatedPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Retrieves the description of the plugin, if set. Overrides AnnotatedPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Retrieves the original plugin identifier. Overrides AnnotatedPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Returns the provider (extension name) of the plugin. Overrides AnnotatedPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Returns the weight of the plugin (used for sorting). Overrides AnnotatedPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
AnnotatedPluginBase:: |
public | function | ||
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 | |
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
InstallablePluginBase:: |
protected | property | The config for this plugin. | |
InstallablePluginBase:: |
public | function |
Builds a display for a library. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Builds a display status based on the current state of the plugin. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the config instance for this plugin. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
protected static | function | ||
InstallablePluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides AnnotatedPluginBase:: |
1 |
InstallablePluginBase:: |
public | function | Retrieves available installs. | |
InstallablePluginBase:: |
public | function |
Gets this plugin's configuration. Overrides AnnotatedPluginBase:: |
4 |
InstallablePluginBase:: |
protected | function | Returns the configuration name for the plugin. | |
InstallablePluginBase:: |
protected | function | Determines the configuration sort order by weight. | 1 |
InstallablePluginBase:: |
public | function | Retrieves the container. | |
InstallablePluginBase:: |
public | function |
Retrieves the deprecation message, if any. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the experimental message. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the composer package name of the installable library, if any. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the installed library used by the plugin. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Displays the human-readable label of the plugin. Overrides AnnotatedPluginBase:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the plugin as a link using its label and URL. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
@TODO: Refactor to use variadic parameters. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the class name of the object defined by the installed library. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
protected | function | 1 | |
InstallablePluginBase:: |
public | function |
Retrieves the preferred library of the plugin. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the configuration for the plugin, but sorted. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the URL of the plugin, if set. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
The current version of the plugin. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function | ||
InstallablePluginBase:: |
public | function |
Indicates whether plugin has multiple installs to check. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Indicates whether the plugin is installed. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Indicates whether the plugin is using the preferred library. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Indicates whether the preferred library is installed. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides AnnotatedPluginBase:: |
3 |
InstallablePluginBase:: |
public | function |
Indicates whether the plugin should be shown in the UI. Overrides InstallablePluginInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
MoreInfoTrait:: |
protected | function | Appends existing content with a "More Info" link. | |
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. | |
PluginDependencyTrait:: |
protected | function | Calculates and adds dependencies of a specific plugin instance. | |
PluginDependencyTrait:: |
protected | function | Calculates and returns dependencies of a specific plugin instance. Aliased as: getPluginDependenciesTrait | |
PluginDependencyTrait:: |
protected | function | Wraps the module handler. | |
PluginDependencyTrait:: |
protected | function | Wraps the theme handler. | |
RendererTrait:: |
protected static | property | The Renderer service. | |
RendererTrait:: |
protected | function | Retrieves the Renderer 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. |