You are here

public function EmojiExtension::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 BaseExtension::register

File

src/Plugin/Markdown/CommonMark/Extension/EmojiExtension.php, line 74

Class

EmojiExtension
Emoji extension.

Namespace

Drupal\markdown\Plugin\Markdown\CommonMark\Extension

Code

public function register($environment) {
  $token = $this
    ->getSetting('github_api_token');

  // Immediately return if no token was provided.
  if (!$token) {
    return;
  }
  switch ($this->pluginDefinition->object) {
    case 'CachetHQ\\Emoji\\EmojiExtension':
      $repo = new \CachetHQ\Emoji\Repositories\GitHubRepository(\Drupal::httpClient(), $token);
      $cache = new LaravelCacheRepositoryAdapter(new LaravelCacheStoreAdapter(\Drupal::cache('markdown'), 'commonmark-ext-emoji'));
      $parser = new \CachetHQ\Emoji\EmojiParser(new \CachetHQ\Emoji\Repositories\CachingRepository($repo, $cache, 'github-repo', 604800));
      $environment
        ->addInlineParser($parser);
      break;
  }
}