Commit 5590d9d0 authored by Joël Pittet's avatar Joël Pittet Committed by Joël Pittet
Browse files

Issue #3103679 by joelpittet remove deprecated unused classes for 3.0.0

parent c533b7a3
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
<?php

namespace Drupal\markdown\Annotation;

/**
 * Base Markdown Plugin Annotation.
 *
 * @deprecated in markdown:8.x-2.0 and is removed from markdown:3.0.0.
 *   Use \Drupal\markdown\Annotation\InstallablePlugin instead.
 * @see https://www.drupal.org/project/markdown/issues/3142418
 */
abstract class BaseMarkdownAnnotation extends InstallablePlugin {
}
+0 −44
Original line number Diff line number Diff line
<?php

namespace Drupal\markdown\Config;

use Drupal\Core\Config\ImmutableConfigException;

/**
 * Immutable Markdown Config.
 *
 * @deprecated in markdown:8.x-2.0 and is removed from markdown:3.0.0.
 *   Use \Drupal\markdown\Form\ParserConfigurationForm instead.
 * @see https://www.drupal.org/project/markdown/issues/3142418
 */
class ImmutableMarkdownConfig extends MarkdownConfig {

  /**
   * {@inheritdoc}
   */
  public function set($key, $value) {
    throw new ImmutableConfigException("Can not set values on immutable configuration {$this->getName()}:$key. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object");
  }

  /**
   * {@inheritdoc}
   */
  public function clear($key) {
    throw new ImmutableConfigException("Can not clear $key key in immutable configuration {$this->getName()}. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object");
  }

  /**
   * {@inheritdoc}
   */
  public function save($has_trusted_data = FALSE) {
    throw new ImmutableConfigException("Can not save immutable configuration {$this->getName()}. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object");
  }

  /**
   * {@inheritdoc}
   */
  public function delete() {
    throw new ImmutableConfigException("Can not delete immutable configuration {$this->getName()}. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object");
  }

}
+0 −13
Original line number Diff line number Diff line
<?php

namespace Drupal\markdown\Exception;

/**
 * Exception thrown when a version has not been satisfied.
 *
 * @deprecated in markdown:8.x-2.0 and is removed from markdown:3.0.0.
 *   No replacement.
 * @see https://www.drupal.org/project/markdown/issues/3142418
 */
class MarkdownVersionException extends MarkdownException {
}

src/Form/SettingsForm.php

deleted100644 → 0
+0 −148
Original line number Diff line number Diff line
<?php

namespace Drupal\markdown\Form;

use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\ElementInfoManagerInterface;
use Drupal\markdown\Config\MarkdownConfig;
use Drupal\markdown\MarkdownInterface;
use Drupal\markdown\Plugin\Filter\FilterMarkdown;
use Drupal\markdown\PluginManager\ParserManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Markdown Settings Form.
 *
 * @deprecated in markdown:8.x-2.0 and is removed from markdown:3.0.0.
 *   Use \Drupal\markdown\Form\ParserConfigurationForm instead.
 * @see https://www.drupal.org/project/markdown/issues/3142418
 */
class SettingsForm extends ParserConfigurationForm {

  /**
   * The Markdown service.
   *
   * @var \Drupal\markdown\MarkdownInterface
   */
  protected $markdown;

  /**
   * MarkdownSettingsForm constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   The Config Factory service.
   * @param \Drupal\Core\Config\TypedConfigManagerInterface $typedConfigManager
   *   The Typed Config Manager service.
   * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cacheTagsInvalidator
   *   The Cache Tags Invalidator service.
   * @param \Drupal\Core\Render\ElementInfoManagerInterface $elementInfo
   *   The Element Info Plugin Manager service.
   * @param \Drupal\markdown\MarkdownInterface $markdown
   *   The Markdown service.
   * @param \Drupal\markdown\PluginManager\ParserManagerInterface $parserManager
   *   The Markdown Parser Plugin Manager service.
   * @param \Drupal\markdown\Config\MarkdownConfig $settings
   *   The markdown settings config.
   */
  public function __construct(ConfigFactoryInterface $configFactory, TypedConfigManagerInterface $typedConfigManager, CacheTagsInvalidatorInterface $cacheTagsInvalidator, ElementInfoManagerInterface $elementInfo, MarkdownInterface $markdown, ParserManagerInterface $parserManager, MarkdownConfig $settings) {
    parent::__construct($configFactory, $typedConfigManager, $cacheTagsInvalidator, $elementInfo, $parserManager);
    $this->markdown = $markdown;
    $this->settings = $settings;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container = NULL, MarkdownConfig $settings = NULL) {
    if (!$container) {
      $container = \Drupal::getContainer();
    }
    return new static(
      $container->get('config.factory'),
      $container->get('config.typed'),
      $container->get('cache_tags.invalidator'),
      $container->get('plugin.manager.element_info'),
      $container->get('markdown'),
      $container->get('plugin.manager.markdown.parser'),
      $settings ?: MarkdownConfig::load('markdown.settings', NULL, $container)->setKeyPrefix('parser')
    );
  }

  /**
   * Indicates whether user is currently viewing the site-wide settings form.
   *
   * @return bool
   *   TRUE or FALSE
   *
   * @deprecated in markdown:8.x-2.0 and is removed from markdown:3.0.0.
   *   No replacement. Check route name yourself.
   * @see https://www.drupal.org/project/markdown/issues/3142418
   */
  public static function siteWideSettingsForm() {
    return \Drupal::routeMatch()->getRouteName() === 'markdown.settings';
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'markdown_configuration';
  }

  /**
   * Builds the subform for markdown settings.
   *
   * Note: building a subform requires that it's ultimately constructed in
   * a #process callback. This is to ensure the complete form (from the parent)
   * has been constructed properly.
   *
   * @param array $element
   *   A render array element.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   *
   * @return array
   *   The modified render array element.
   *
   * @deprecated in markdown:8.x-2.0 and is removed from markdown:3.0.0.
   *   No replacement.
   * @see https://www.drupal.org/project/markdown/issues/3142418
   */
  public function buildSubform(array $element, FormStateInterface $form_state) {
    return $element;
  }

  /**
   * The AJAX callback used to return the parser ajax wrapper.
   *
   * @deprecated in markdown:8.x-2.0 and is removed from markdown:3.0.0. Use
   *   \Drupal\markdown\Plugin\Filter\FilterMarkdown::ajaxChangeParser instead.
   * @see https://www.drupal.org/project/markdown/issues/3142418
   */
  public static function ajaxChangeParser(array $form, FormStateInterface $form_state) {
    return FilterMarkdown::ajaxChangeParser($form, $form_state);
  }

  /**
   * Retrieves configuration from values.
   *
   * @param array $values
   *   An array of values.
   *
   * @return array
   *   The configuration array.
   *
   * @deprecated in markdown:8.x-2.0 and is removed from markdown:3.0.0.
   *   Use \Drupal\markdown\Form\ParserConfigurationForm::getConfigFromValues
   *   instead.
   * @see https://www.drupal.org/project/markdown/issues/3142418
   */
  public function getConfigurationFromValues(array $values) {
    $config = $this->getConfigFromValues($this->settings->getName(), $values);
    return $config->get();
  }

}
+0 −116
Original line number Diff line number Diff line
<?php

namespace Drupal\markdown\Plugin\Markdown\CommonMark\Extension;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginFormInterface;
use Drupal\Core\Theme\ActiveTheme;
use Drupal\markdown\Plugin\Markdown\AllowedHtmlInterface;
use Drupal\markdown\Plugin\Markdown\CommonMark\BaseExtension;
use Drupal\markdown\Plugin\Markdown\ParserInterface;
use Drupal\markdown\Plugin\Markdown\SettingsInterface;
use Drupal\markdown\Traits\SettingsTrait;
use Drupal\markdown\Util\LaravelCacheRepositoryAdapter;
use Drupal\markdown\Util\LaravelCacheStoreAdapter;

/**
 * Emoji extension.
 *
 * @MarkdownAllowedHtml(
 *   id = "commonmark-emoji",
 * )
 * @MarkdownExtension(
 *   id = "commonmark-emoji",
 *   label = @Translation("Emoji"),
 *   description = @Translation("Adds emoji support to CommonMark."),
 *   libraries = {
 *     @ComposerPackage(
 *       id = "cachethq/emoji",
 *       experimental = @Translation("See <a href=':url' target='_blank'>thephpleague/commonmark#421</a>", arguments = {
 *         ":url" = "https://github.com/thephpleague/commonmark/issues/421",
 *       }),
 *       object = "\CachetHQ\Emoji\EmojiExtension",
 *       url = "https://github.com/CachetHQ/Emoji",
 *       requirements = {
 *          @InstallableRequirement(
 *             id = "parser:commonmark",
 *             callback = "::getVersion",
 *             constraints = {"Version" = ">=0.18.1 <1.0.0 || ^1.0"},
 *          ),
 *       },
 *     ),
 *   },
 * )
 */
class EmojiExtension extends BaseExtension implements AllowedHtmlInterface, PluginFormInterface, SettingsInterface {

  use SettingsTrait;

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings($pluginDefinition) {
    /* @var \Drupal\markdown\Annotation\InstallablePlugin $pluginDefinition */
    return [
      'github_api_token' => NULL,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function allowedHtmlTags(ParserInterface $parser, ActiveTheme $activeTheme = NULL) {
    return [
      'img' => [
        'class' => 'emoji',
        'data-emoji' => TRUE,
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  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;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $element, FormStateInterface $form_state) {
    /** @var \Drupal\markdown\Form\SubformStateInterface $form_state */

    $element += $this->createSettingElement('github_api_token', [
      '#type' => 'textfield',
      '#title' => $this->t('GitHub API Token'),
      '#description' => $this->t('You must <a href=":generate_token" target="_blank">generate a GitHub API token</a> that will be used as the map of available emojis. Note: it does not need any scopes or permissions, it is just used for authentication to avoid rate limiting.', [
        ':generate_token' => 'https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line',
      ]),
    ], $form_state);

    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function settingsKey() {
    return FALSE;
  }

}
Loading