diff --git a/config_patch.routing.yml b/config_patch.routing.yml index 290bacedc9eb77dd0caff233870eafa0c858edb9..91f4e60aa9a5b5af3cddfc7c4446138873b20667 100644 --- a/config_patch.routing.yml +++ b/config_patch.routing.yml @@ -22,6 +22,13 @@ config_patch.settings: requirements: _permission: 'administer config_patch' +config_patch.clear_cache: + path: '/admin/config/development/config_patch/clear-cache' + defaults: + _controller: '\Drupal\config_patch\Controller\ConfigPatchUtilities::clearCache' + requirements: + _permission: 'export configuration' + config_patch.toolbar: path: '/admin/config/development/config_patch/toolbar' defaults: diff --git a/src/Controller/ConfigPatchUtilities.php b/src/Controller/ConfigPatchUtilities.php new file mode 100644 index 0000000000000000000000000000000000000000..fef2e8837e18cd33885f208677a7abc8877e40da --- /dev/null +++ b/src/Controller/ConfigPatchUtilities.php @@ -0,0 +1,56 @@ +<?php + +namespace Drupal\config_patch\Controller; + +use Drupal\Core\Controller\ControllerBase; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Cache\CacheTagsInvalidatorInterface; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RedirectResponse; + +/** + * Class ConfigPatchUtilities. + * + * @package Drupal\config_patch\Controller + */ +class ConfigPatchUtilities extends ControllerBase { + + /** + * Invalidation service. + * + * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface + */ + protected $cacheTagInvalidator; + + /** + * ConfigSubscriber constructor. + * + * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cacheTagsInvalidator + * Invalidation service. + */ + public function __construct(CacheTagsInvalidatorInterface $cacheTagsInvalidator) { + $this->cacheTagInvalidator = $cacheTagsInvalidator; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('cache_tags.invalidator') + ); + } + + /** + * Clear the config change cache. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * The request object. + */ + public function clearCache(Request $request) { + $destination = $request->get('destination'); + $this->cacheTagInvalidator->invalidateTags(['config_patch']); + return new RedirectResponse($destination); + } + +} diff --git a/src/Form/ConfigPatch.php b/src/Form/ConfigPatch.php index 7989052a24bb7f9bfa867f980e1ea1ee85eac9a6..ab4400c712809e43d8cdda66a23a3b0444958511 100644 --- a/src/Form/ConfigPatch.php +++ b/src/Form/ConfigPatch.php @@ -58,16 +58,36 @@ class ConfigPatch extends FormBase { ]; $settings_link = Url::fromRoute('config_patch.settings', ['destination' => Url::fromRoute('config.patch')->toString()]); + $clear_cache_link = Url::fromRoute('config_patch.clear_cache', ['destination' => Url::fromRoute('config.patch')->toString()]); if (empty($this->config('config_patch.settings')->get('config_base_path'))) { $this->messenger()->addWarning($this->t('The path to config folder is not set. Please set it <a href="@link">here</a>', ['@link' => $settings_link->toString()])); } - $form['settings'] = [ + + $form['settings-buttons'] = [ + '#type' => 'container', + '#attributes' => [ + 'class' => [ + 'align-right', + ], + ], + ]; + $form['settings-buttons']['settings'] = [ '#type' => 'link', - '#title' => 'Change patch settings', + '#title' => 'Settings', '#url' => $settings_link, '#attributes' => [ 'class' => [ - 'align-right', + 'button', + ], + ], + ]; + $form['settings-buttons']['cache-clear'] = [ + '#type' => 'link', + '#title' => 'Clear change cache', + '#url' => $clear_cache_link, + '#attributes' => [ + 'class' => [ + 'button', ], ], ];