You are here

public function BaseExtension::register in Markdown 8.2

Allows the extension to register itself with the CommonMark Environment.

Parameters

\League\CommonMark\Environment\ConfigurableEnvironmentInterface|\League\CommonMark\ConfigurableEnvironmentInterface|\League\CommonMark\Environment $environment: The CommonMark environment. The exact object passed here has changed namespaces over various versions. It is unlikely to be incompatible, however, explicit typechecking via instanceof may be needed.

Overrides ExtensionInterface::register

2 calls to BaseExtension::register()
ExternalLinkExtension::register in src/Plugin/Markdown/CommonMark/Extension/ExternalLinkExtension.php
Allows the extension to register itself with the CommonMark Environment.
StrikethroughExtension::register in src/Plugin/Markdown/CommonMark/Extension/StrikethroughExtension.php
Allows the extension to register itself with the CommonMark Environment.
4 methods override BaseExtension::register()
EmojiExtension::register in src/Plugin/Markdown/CommonMark/Extension/EmojiExtension.php
Allows the extension to register itself with the CommonMark Environment.
ExternalLinkExtension::register in src/Plugin/Markdown/CommonMark/Extension/ExternalLinkExtension.php
Allows the extension to register itself with the CommonMark Environment.
MentionExtension::register in src/Plugin/Markdown/CommonMark/Extension/MentionExtension.php
Allows the extension to register itself with the CommonMark Environment.
StrikethroughExtension::register in src/Plugin/Markdown/CommonMark/Extension/StrikethroughExtension.php
Allows the extension to register itself with the CommonMark Environment.

File

src/Plugin/Markdown/CommonMark/BaseExtension.php, line 23

Class

BaseExtension
Base CommonMark Extension.

Namespace

Drupal\markdown\Plugin\Markdown\CommonMark

Code

public function register($environment) {

  // Immediately return if the parser automatically registers the extension.
  // @todo Refactor terminology here as "bundled" should mean that it is
  //   installed/included with a library; which is different from being
  //   automatically registered.
  if (($parser = $this
    ->getParser()) instanceof ExtensibleParserInterface && in_array($this
    ->getPluginId(), $parser
    ->getBundledExtensionIds(), TRUE)) {
    return;
  }

  // Most plugins define the library object as the extension class that
  // represents the extension that should be registered with CommonMark.
  // This is added to the base class to assist with this common workflow.
  // Plugins can still override this method for advanced use cases as needed.
  $environment
    ->addExtension($this
    ->getObject());
}