Skip to content
Snippets Groups Projects

Resolve #3526164 "Move functionality to a service"

Files
5
@@ -19,6 +19,7 @@ use Drupal\Core\Messenger\MessengerTrait;
@@ -19,6 +19,7 @@ use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\Site\Settings;
use Drupal\Core\Site\Settings;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\Core\Url;
 
use Drupal\responsive_favicons\ResponsiveFavicons;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
/**
@@ -48,6 +49,8 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
@@ -48,6 +49,8 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
* The cache service.
* The cache service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler service.
* The module handler service.
 
* @param \Drupal\responsive_favicons\ResponsiveFavicons $responsiveFavicons
 
* The module handler service.
*/
*/
public function __construct(
public function __construct(
ConfigFactoryInterface $config_factory,
ConfigFactoryInterface $config_factory,
@@ -57,6 +60,7 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
@@ -57,6 +60,7 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
protected ArchiverManager $archiverManager,
protected ArchiverManager $archiverManager,
protected CacheBackendInterface $cache,
protected CacheBackendInterface $cache,
protected ModuleHandlerInterface $moduleHandler,
protected ModuleHandlerInterface $moduleHandler,
 
protected ResponsiveFavicons $responsiveFavicons,
) {
) {
parent::__construct($config_factory, $typedConfigManager);
parent::__construct($config_factory, $typedConfigManager);
}
}
@@ -74,6 +78,7 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
@@ -74,6 +78,7 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
$container->get('plugin.manager.archiver'),
$container->get('plugin.manager.archiver'),
$container->get('cache.default'),
$container->get('cache.default'),
$container->get('module_handler'),
$container->get('module_handler'),
 
$container->get('responsive_favicons.manager'),
);
);
}
}
@@ -292,7 +297,7 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
@@ -292,7 +297,7 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
if (preg_match('/\.json$/', $file)) {
if (preg_match('/\.json$/', $file)) {
$file_contents = file_get_contents($uri);
$file_contents = file_get_contents($uri);
$find = preg_quote('"\/android-chrome', '/');
$find = preg_quote('"\/android-chrome', '/');
$replace = '"' . str_replace('/', '\/', _responsive_favicons_normalise_path('/android-chrome${1}', $config));
$replace = '"' . str_replace('/', '\/', $this->responsiveFavicons->normalisePath('/android-chrome${1}', $config));
$file_contents = preg_replace('/' . $find . '([^"]*)/', $replace, $file_contents);
$file_contents = preg_replace('/' . $find . '([^"]*)/', $replace, $file_contents);
$this->fileSystem->saveData($file_contents, $uri, FileExists::Replace);
$this->fileSystem->saveData($file_contents, $uri, FileExists::Replace);
}
}
@@ -332,11 +337,11 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
@@ -332,11 +337,11 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
// Clear the icons' cache.
// Clear the icons' cache.
// Needed until the following domain module issue gets fixed:
// Needed until the following domain module issue gets fixed:
// https://www.drupal.org/project/domain/issues/3397693
// https://www.drupal.org/project/domain/issues/3397693
$this->cache->delete(_responsive_favicons_get_cache_id($config));
$this->cache->delete($this->responsiveFavicons->getCacheId($config));
// Check if all icons' files are available.
// Check if all icons' files are available.
$html = implode(PHP_EOL, $tags);
$html = implode(PHP_EOL, $tags);
$icons = _responsive_favicons_validate_tags($html, $config);
$icons = $this->responsiveFavicons->validateTags($html, $config);
if (!empty($icons['missing'])) {
if (!empty($icons['missing'])) {
$this->messenger()->addWarning($this->t('The favicon files are missing for the following tags.<br/><code>@tags</code>', [
$this->messenger()->addWarning($this->t('The favicon files are missing for the following tags.<br/><code>@tags</code>', [
':url' => Url::fromRoute('responsive_favicons.admin')->toString(),
':url' => Url::fromRoute('responsive_favicons.admin')->toString(),
@@ -346,7 +351,7 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
@@ -346,7 +351,7 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
// Display a warning if a manifest link is defined and the pwa module is
// Display a warning if a manifest link is defined and the pwa module is
// active.
// active.
if ($this->moduleHandler->moduleExists('pwa') && _responsive_favicons_has_link($icons, 'rel', 'manifest')) {
if ($this->moduleHandler->moduleExists('pwa') && $this->responsiveFavicons->hasLink($icons, 'rel', 'manifest')) {
$this->messenger()->addWarning($this->t('The PWA module is active and a conflicting web manifest has been declared in the Favicon tags field. Please remove it.'));
$this->messenger()->addWarning($this->t('The PWA module is active and a conflicting web manifest has been declared in the Favicon tags field. Please remove it.'));
}
}
}
}
@@ -368,7 +373,7 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
@@ -368,7 +373,7 @@ class ResponsiveFaviconsAdmin extends ConfigFormBase {
return preg_replace_callback(
return preg_replace_callback(
'/"' . preg_quote($prefix, '/') . '([^"]*)/',
'/"' . preg_quote($prefix, '/') . '([^"]*)/',
function ($matches) use ($prefix, $config) {
function ($matches) use ($prefix, $config) {
return '"' . _responsive_favicons_normalise_path($prefix . $matches[1], $config);
return '"' . $this->responsiveFavicons->normalisePath($prefix . $matches[1], $config);
},
},
$file_contents
$file_contents
);
);
Loading