Commit 6b67dd0f authored by Andrey Vitushkin's avatar Andrey Vitushkin
Browse files

Issue #3311613 by wombatbuddy, EPAM Systems: Replace of programmatic cache...

Issue #3311613 by wombatbuddy, EPAM Systems: Replace of programmatic cache flushing with adding cache tags to improve performance
parent 9517345b
Loading
Loading
Loading
Loading
+0 −19
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ namespace Drupal\tab_manager\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Config form for the "Tab Manger" module.
@@ -20,22 +19,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 */
class TabManagerConfigForm extends ConfigFormBase {

  /**
   * Router builder.
   *
   * @var \Drupal\Core\Routing\RouteBuilderInterface
   */
  protected $routerBuilder;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $instance = parent::create($container);
    $instance->routerBuilder = $container->get('router.builder');
    return $instance;
  }

  /**
   * {@inheritdoc}
   */
@@ -76,8 +59,6 @@ class TabManagerConfigForm extends ConfigFormBase {
    $value = $form_state->getValue('apply_changes_for_administrator_role');
    $config->set('apply_changes_for_administrator_role', $value)->save();
    parent::submitForm($form, $form_state);
    // Flush routing and links cashes.
    $this->routerBuilder->rebuild();
  }

}
+0 −10
Original line number Diff line number Diff line
@@ -18,20 +18,12 @@ class TabManagerSettingsForm extends ConfigFormBase {
   */
  protected $state;

  /**
   * Router builder.
   *
   * @var \Drupal\Core\Routing\RouteBuilderInterface
   */
  protected $routerBuilder;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $instance = parent::create($container);
    $instance->state = $container->get('state');
    $instance->routerBuilder = $container->get('router.builder');
    return $instance;
  }

@@ -169,8 +161,6 @@ class TabManagerSettingsForm extends ConfigFormBase {
    else {
      $this->resetToDefault($modified_tabs);
    }
    // Flush routing and links cashes.
    $this->routerBuilder->rebuild();

    // Redirect to the page with tabs to force reloading and to see changes.
    $tabs_page_url = $this->state->get('tab_manager_tabs_page_url');
+6 −0
Original line number Diff line number Diff line
@@ -14,6 +14,12 @@ use Drupal\Core\Entity\ContentEntityInterface;
 */
function tab_manager_menu_local_tasks_alter(&$data, $route_name) {
  
  // Add cache tags to rerender local tasks after setting changes.
  $data['cacheability']->addCacheTags([
    'config:tab_manager.config',
    'config:tab_manager.settings',
  ]);  

  if ($route_name === 'tab_manager.settings' || $route_name === 'tab_manager.config') {
    return;
  }