Commit a68dd806 authored by Ankitha Shetty's avatar Ankitha Shetty Committed by Vladimir Proshin
Browse files

Issue #3289247 ankithashetty, omkar-pd, Aamir M: Automated Drupal 10 compatibility fixes

parent ff14db28
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
name: README Help
type: module
description: Renders README file on the admin/help/your_module page.
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^8.8 || ^9 || ^10
package: Help
dependencies:
  - drupal:help
+1 −1
Original line number Diff line number Diff line
services:
  readmehelp.markdown_converter:
    class: Drupal\readmehelp\ReadmeHelpMarkdownConverter
    arguments: ['@module_handler', '@router.request_context', '@plugin.manager.filter', '@app.root']
    arguments: ['@module_handler', '@router.request_context', '@plugin.manager.filter', '%app.root%']
+2 −2
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ class ReadmeHelpController extends HelpController {
  public function helpPage($name) {
    $build = [];
    $self = $name == 'readmehelp';
    $info = \Drupal::service('extension.list.module')->getExtensionInfo($name);
    $info = $this->moduleExtensionList->getExtensionInfo($name);
    $dependencies = isset($info['dependencies']) ? $info['dependencies'] : [];
    $depender = $self || in_array('readmehelp', $dependencies) || in_array('drupal:readmehelp', $dependencies);
    // Allow dependers to override default behaviour not displaying README
@@ -25,7 +25,7 @@ class ReadmeHelpController extends HelpController {
    // @code
    // function MY_MODULE_readmehelp() {}
    // @endcode
    if ($depender && !$this->moduleHandler()->implementsHook($name, 'readmehelp')) {
    if ($depender && !$this->moduleHandler()->hasImplementations('readmehelp', $name)) {
      $converter = \Drupal::service('readmehelp.markdown_converter');
      $build['top'] = [
        '#attached' => [
+41 −4
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ use Drupal\filter\Plugin\FilterBase;
use Drupal\filter\FilterProcessResult;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;

/**
 * Provides a filter for markdown.
@@ -24,7 +27,42 @@ use Drupal\Component\Utility\Unicode;
 *   weight = -100
 * )
 */
class ReadmehelpMarkdown extends FilterBase {
class ReadmehelpMarkdown extends FilterBase implements ContainerFactoryPluginInterface {
  /**
   * The current request.
   *
   * @var \Symfony\Component\HttpFoundation\Request
   */
  protected $request;

  /**
   * Creates a HelpBlock instance.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The current request.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->request = $request;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('request_stack')->getCurrentRequest(),
    );
  }

  /**
   * {@inheritdoc}
@@ -77,9 +115,8 @@ class ReadmehelpMarkdown extends FilterBase {
   */
  public function process($text, $langcode, $file_path = NULL) {
    if (!empty($text)) {
      $request = \Drupal::request();
      $path = $request->getPathInfo();
      $host = str_replace($path, '', $request->getSchemeAndHttpHost() . $request->getRequestUri());
      $path = $this->request->getPathInfo();
      $host = str_replace($path, '', $this->request->getSchemeAndHttpHost() . $this->request->getRequestUri());
      $path = $file_path ? trim($file_path, '/') : trim($path, '/');

      $text = $text . "\n";
+52 −2
Original line number Diff line number Diff line
@@ -2,9 +2,12 @@

namespace Drupal\readmehelp\Plugin\HelpSection;

use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Link;
use Drupal\help\Plugin\HelpSection\HookHelpSection;
use Drupal\readmehelp\ReadmeHelpInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides the module topics list section for the help page.
@@ -17,18 +20,65 @@ use Drupal\readmehelp\ReadmeHelpInterface;
 */
class ReadmeHookHelpSection extends HookHelpSection implements ReadmeHelpInterface {

  /**
   * The module extension list.
   *
   * @var \Drupal\Core\Extension\ModuleExtensionList
   */
  protected $moduleExtensionList;

  /**
   * Constructs a HookHelpSection object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler service.
   * @param \Drupal\Core\Extension\ModuleExtensionList $module_extension_list
   *   The module extension list.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, ModuleExtensionList $module_extension_list) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $module_handler);
    $this->moduleExtensionList = $module_extension_list;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('module_handler'),
      $container->get('extension.list.module')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function listTopics() {
    $dirs = $this->moduleHandler->getModuleDirectories();
    $hook_help = $this->moduleHandler->getImplementations('help');

    $hook_help = [];
    $this->moduleHandler->invokeAllWith(
      'help',
      function (callable $hook, string $module) use (&$hook_help) {
        $hook_help[] = $module;
      }
    );

    $topics = [];

    foreach ($this->moduleHandler->getModuleList() as $name => $module) {
      $file = FALSE;
      $self = $name == 'readmehelp';
      $extension_info = \Drupal::service('extension.list.module')->getExtensionInfo($name);
      $extension_info = $this->moduleExtensionList->getExtensionInfo($name);
      $dependencies = $extension_info['dependencies'];
      if (in_array('readmehelp', $dependencies) || in_array('drupal:readmehelp', $dependencies) || $self) {
        foreach (explode(', ', static::READMEHELP_FILES) as $readme) {
Loading