Commit 5f12c283 authored by gnuget's avatar gnuget Committed by gnuget
Browse files

Issue #3133663 by gnuget, mradcliffe: Drupal 9 deprecated code report

parent 7f8e9115
services:
plugin.manager.advanced_help:
class: Drupal\advanced_help\AdvancedHelpManager
arguments: ['@module_handler', '@theme_handler', '@cache.discovery', '@string_translation']
\ No newline at end of file
arguments: ['@module_handler', '@theme_handler', '@cache.discovery', '@string_translation', '@file_system']
......@@ -9,6 +9,7 @@ use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\File\FileSystemInterface;
/**
* AdvancedHelp plugin manager.
......@@ -16,6 +17,13 @@ use Drupal\Component\Serialization\Yaml;
class AdvancedHelpManager extends DefaultPluginManager {
use StringTranslationTrait;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* Constructs an AdvancedHelpManager instance.
*
......@@ -27,13 +35,16 @@ class AdvancedHelpManager extends DefaultPluginManager {
* Theme handler.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file handler.
*/
public function __construct(ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache_backend, TranslationInterface $string_translation) {
public function __construct(ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache_backend, TranslationInterface $string_translation, FileSystemInterface $file_system) {
$this->module_handler = $module_handler;
$this->theme_handler = $theme_handler;
$this->setStringTranslation($string_translation);
$this->alterInfo('advanced_help');
$this->setCacheBackend($cache_backend, 'advanced_help', ['advanced_help']);
$this->fileSystem = $file_system;
}
/**
......@@ -133,8 +144,14 @@ class AdvancedHelpManager extends DefaultPluginManager {
}
elseif (!file_exists("$module_path/help")) {
// Look for one or more README files.
$files = file_scan_directory("./$module_path",
'/^(readme).*\.(txt|md)$/i', ['recurse' => FALSE]);
if (floatval(\Drupal::VERSION) >= 8.8) {
$files = $this->fileSystem->scanDirectory("./$module_path",
'/^(readme).*\.(txt|md)$/i', ['recurse' => FALSE]);
}
else {
$files = file_scan_directory("./$module_path",
'/^(readme).*\.(txt|md)$/i', ['recurse' => FALSE]);
}
$path = "./$module_path";
foreach ($files as $name => $fileinfo) {
$info[$fileinfo->filename] = [
......
......@@ -11,6 +11,7 @@ use Drupal\advanced_help\AdvancedHelpManager;
use Drupal\search\Plugin\SearchIndexingInterface;
use Drupal\Core\Config\Config;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\search\SearchIndexInterface;
/**
* Executes a keyword search for Advanced Help against the {advanced_help} topic pages.
......@@ -50,11 +51,18 @@ class AdvancedHelpSearch extends SearchPluginBase implements AccessibleInterface
*/
protected $searchSettings;
/**
* The search index.
*
* @var \Drupal\search\SearchIndexInterface
*/
protected $searchIndex;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$instance = new static(
$container->get('database'),
$container->get('plugin.manager.advanced_help'),
$container->get('current_user'),
......@@ -63,6 +71,12 @@ class AdvancedHelpSearch extends SearchPluginBase implements AccessibleInterface
$plugin_id,
$plugin_definition
);
// The search Index service does not exist on Drupal 8.7 and below.
if (floatval(\Drupal::VERSION) >= 8.8) {
$instance->searchIndex = $container->get('search.index');
}
return $instance;
}
/**
......@@ -215,7 +229,12 @@ class AdvancedHelpSearch extends SearchPluginBase implements AccessibleInterface
}
// Update index, using search index "type" equal to the plugin ID.
search_index($this->getPluginId(), $info['sid'], $language, file_get_contents($file));
if (floatval(\Drupal::VERSION) >= 8.8) {
$this->searchIndex->index($this->getPluginId(), $info['sid'], $language, file_get_contents($file));
}
else {
search_index($this->getPluginId(), $info['sid'], $language, file_get_contents($file));
}
$count++;
if ($count >= $limit) {
$last['module'] = $module;
......@@ -232,14 +251,24 @@ class AdvancedHelpSearch extends SearchPluginBase implements AccessibleInterface
* {@inheritdoc}
*/
public function indexClear() {
search_index_clear($this->getPluginId());
if (floatval(\Drupal::VERSION) >= 8.8) {
$this->searchIndex->clear($this->getPluginId());
}
else {
search_index_clear($this->getPluginId());
}
}
/**
* {@inheritdoc}
*/
public function markForReindex() {
search_mark_for_reindex($this->getPluginId());
if (floatval(\Drupal::VERSION) >= 8.8) {
$this->searchIndex->markForReindex($this->getPluginId());
}
else {
search_mark_for_reindex($this->getPluginId());
}
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment