You are here

abstract class InstallablePlugin in Markdown 8.2

Base annotation for "installable" plugins.

Note: Doctrine doesn't support multiple types, so if the property accepts more than a single type, "mixed" must be used instead of the desired piped types.

@todo Move upstream to https://www.drupal.org/project/installable_plugins.

Hierarchy

Expanded class hierarchy of InstallablePlugin

See also

https://github.com/doctrine/annotations/issues/129

4 files declare their use of InstallablePlugin
AllowedHtmlManager.php in src/PluginManager/AllowedHtmlManager.php
BaseExtension.php in src/Plugin/Markdown/BaseExtension.php
ExtensionManager.php in src/PluginManager/ExtensionManager.php
InstallablePluginManager.php in src/PluginManager/InstallablePluginManager.php

File

src/Annotation/InstallablePlugin.php, line 16

Namespace

Drupal\markdown\Annotation
View source
abstract class InstallablePlugin extends AnnotationObject {
  use InstallablePluginTrait;

  /**
   * An array of available installable libraries this plugin supports.
   *
   * @var \Drupal\markdown\Annotation\InstallableLibrary[]
   */
  public $libraries = [];

  /**
   * Retrieves the installed library or plugin identifier.
   *
   * @return string
   *   The installed identifier.
   */
  public function getInstalledId() {
    if (($installed = $this
      ->getInstalledLibrary()) && ($id = $installed
      ->getId())) {
      return $id;
    }
    return $this
      ->getId();
  }

  /**
   * Retrieves the installed library.
   *
   * @return \Drupal\markdown\Annotation\InstallableLibrary|void
   *   The installed library.
   */
  public function getInstalledLibrary() {
    return current(array_filter($this->libraries, function ($library) {
      return !$library->requirementViolations;
    })) ?: NULL;
  }

  /**
   * Retrieves the preferred library.
   *
   * @return \Drupal\markdown\Annotation\InstallableLibrary|void
   *   The preferred library.
   */
  public function getPreferredLibrary() {
    return current(array_filter($this->libraries, function ($library) {
      return $library->preferred;
    }));
  }

  /**
   * Retrieves requirements of a certain type.
   *
   * @param string $type
   *   The requirement type to limit by.
   * @param string $id
   *   Optional. A specific identifier to limit by.
   *
   * @return \Drupal\markdown\Annotation\InstallableRequirement[]
   *   An array of requirements matching the type.
   */
  public function getRequirementsByType($type, $id = NULL) {
    $requirements = [];
    foreach (array_merge($this->requirements, $this->runtimeRequirements) as $requirement) {
      if (!$requirement instanceof InstallableRequirement) {
        continue;
      }
      list($t, $i) = $requirement
        ->listTypeId();
      if ($type === $t) {
        if (isset($id) && $id !== $i) {
          continue;
        }
        $requirements[] = $requirement;
      }
    }
    return $requirements;
  }

  /**
   * Retrieves requirements of a certain constraint type.
   *
   * @param string $name
   *   The requirement constraint name to limit by.
   * @param mixed $value
   *   Optional. A specific value to limit by.
   *
   * @return \Drupal\markdown\Annotation\InstallableRequirement[]
   *   An array of requirements matching the type.
   */
  public function getRequirementsByConstraint($name, $value = NULL) {
    $requirements = [];
    foreach (array_merge($this->requirements, $this->runtimeRequirements) as $requirement) {
      if (!$requirement instanceof InstallableRequirement) {
        continue;
      }
      foreach ($requirement->constraints as $k => $v) {
        if ($k === $name) {
          if (isset($value) && $value !== $v) {
            continue;
          }
          $requirements[] = $requirement;
          continue 2;
        }
      }
    }
    return $requirements;
  }

  /**
   * Indicates whether plugin is installed.
   *
   * @return bool
   *   TRUE or FALSE
   */
  public function isInstalled() {
    return empty($this->requirementViolations);
  }

  /**
   * Indicates whether the preferred library is installed.
   *
   * @return bool
   *   TRUE or FALSE
   */
  public function isPreferredLibraryInstalled() {
    return $this
      ->getPreferredLibrary() === $this
      ->getInstalledLibrary();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AnnotationBase::$class protected property The class used for this annotated class.
AnnotationBase::$id public property The annotated class ID. 1
AnnotationBase::$provider protected property The provider of the annotated class.
AnnotationBase::getClass public function Gets the class of the annotated class. Overrides AnnotationInterface::getClass
AnnotationBase::getProvider public function Gets the name of the provider of the annotated class. Overrides AnnotationInterface::getProvider
AnnotationBase::setClass public function Sets the class of the annotated class. Overrides AnnotationInterface::setClass
AnnotationBase::setProvider public function Sets the name of the provider of the annotated class. Overrides AnnotationInterface::setProvider
AnnotationObject::$description public property The description of the plugin.
AnnotationObject::$label public property A human-readable label.
AnnotationObject::$weight public property The weight of the plugin.
AnnotationObject::$_deprecated protected property Stores deprecated values.
AnnotationObject::$_deprecatedProperties protected property A list of deprecation messages, keyed by the deprecated property name.
AnnotationObject::$_triggeredDeprecations private property A list of triggered deprecations.
AnnotationObject::create public static function Allows the creation of new objects statically, for easier chainability.
AnnotationObject::DEPRECATED_REGEX constant
AnnotationObject::doMerge protected function Merges values with this plugin.
AnnotationObject::get public function Gets the value of an annotation. Overrides AnnotationInterface::get
AnnotationObject::getId public function Gets the unique ID for this annotated class. Overrides AnnotationBase::getId
AnnotationObject::getIterator public function
AnnotationObject::id public function Gets the unique identifier of the plugin. Overrides PluginDefinitionInterface::id
AnnotationObject::merge public function Merges values with this plugin.
AnnotationObject::normalizeValue protected function Normalizes a value to ensure its ready to be merged with the definition.
AnnotationObject::offsetExists public function
AnnotationObject::offsetGet public function
AnnotationObject::offsetSet public function
AnnotationObject::offsetUnset public function
AnnotationObject::protectedProperties protected function Indicates properties that should never be overridden after instantiation. 1
AnnotationObject::triggerDeprecation private function Triggers a deprecation notice for a given property.
AnnotationObject::validateIdentifier protected function Helper method for validating the definition identifier. 2
AnnotationObject::__construct public function AnnotationObject constructor. 1
AnnotationObject::__get public function
AnnotationObject::__isset public function
AnnotationObject::__set public function
AnnotationObject::__sleep public function
AnnotationObject::__unset public function
AnnotationObject::__wakeup public function
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function Aliased as: __sleepTrait 1
DependencySerializationTrait::__wakeup public function Aliased as: __wakeupTrait 2
InstallablePlugin::$libraries public property An array of available installable libraries this plugin supports.
InstallablePlugin::getInstalledId public function Retrieves the installed library or plugin identifier.
InstallablePlugin::getInstalledLibrary public function Retrieves the installed library.
InstallablePlugin::getPreferredLibrary public function Retrieves the preferred library.
InstallablePlugin::getRequirementsByConstraint public function Retrieves requirements of a certain constraint type.
InstallablePlugin::getRequirementsByType public function Retrieves requirements of a certain type.
InstallablePlugin::isInstalled public function Indicates whether plugin is installed.
InstallablePlugin::isPreferredLibraryInstalled public function Indicates whether the preferred library is installed.
InstallablePluginTrait::$deprecated public property Indicates the plugin has been deprecated by providing a message.
InstallablePluginTrait::$experimental public property Indicates the plugin is experimental by providing a message.
InstallablePluginTrait::$installed Deprecated public property Flag indicating whether plugin is installed.
InstallablePluginTrait::$object public property The class name of the primary object that is implemented by the library.
InstallablePluginTrait::$preferred public property Flag indicating whether it is the preferred library.
InstallablePluginTrait::$requirements public property An array of requirements for the plugin.
InstallablePluginTrait::$requirementViolations public property A list of requirement violation messages.
InstallablePluginTrait::$runtimeRequirements public property An array of runtime requirements for the plugin.
InstallablePluginTrait::$ui public property Flag indicating whether this plugin is to be visible in UI areas.
InstallablePluginTrait::$url public property A URL for the plugin, typically for installation instructions.
InstallablePluginTrait::$version public property The installed version.
InstallablePluginTrait::$versionConstraint Deprecated public property The constraint the version must satisfy to be considered "installable".
InstallablePluginTrait::getLink public function Retrieves the plugin as a link using its label and URL.
InstallablePluginTrait::getUrl public function Retrieves the definition's URL property as an object. 1
InstallablePluginTrait::getVersionRequirements public function Retrieves requirements that contain "Version" constraints.
InstallablePluginTrait::validate public function Validates the plugin requirements.