Fix404IgnoreController.php in Redirect 8
File
modules/redirect_404/src/Controller/Fix404IgnoreController.php
View source
<?php
namespace Drupal\redirect_404\Controller;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\redirect_404\RedirectNotFoundStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
class Fix404IgnoreController extends ControllerBase {
protected $configuration;
protected $redirectStorage;
public function __construct(ConfigFactoryInterface $config_factory, RedirectNotFoundStorageInterface $redirect_storage) {
$this->configuration = $config_factory;
$this->redirectStorage = $redirect_storage;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('redirect.not_found_storage'));
}
public function ignorePath(Request $request) {
$ignored_paths = $this
->config('redirect_404.settings')
->get('pages');
$path = $request->query
->get('path');
$langcode = $request->query
->get('langcode');
if (empty($ignored_paths) || !strpos($path, $ignored_paths)) {
$this->redirectStorage
->resolveLogRequest($path, $langcode);
$this
->messenger()
->addMessage($this
->t('Resolved the path %path in the database. Please check the ignored list and save the settings.', [
'%path' => $path,
]));
}
$options = [
'query' => [
'ignore' => $path,
'destination' => Url::fromRoute('redirect_404.fix_404')
->getInternalPath(),
],
];
return $this
->redirect('redirect.settings', [], $options);
}
}