Commit 06040d4f authored by git's avatar git Committed by Alexander Shumenko
Browse files

Issue #3292459 by Rakhi Soni, shumer: t() calls should be avoided in classes

parent 56c1d873
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -13,12 +13,15 @@ use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
use Drupal\Core\Plugin\PluginFormFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Override form for block instance forms.
 */
class CacheBlockForm extends BlockForm {

  use StringTranslationTrait;

  /**
   * The date formatter service.
   *
@@ -110,14 +113,14 @@ class CacheBlockForm extends BlockForm {
      86400,
    ];
    $period = array_map([$this->dateFormatter, 'formatInterval'], array_combine($period, $period));
    $period[0] = t('No caching');
    $period[0] = $this->t('No caching');

    $form['settings']['adv_varnish']['cache']['ttl'] = [
      '#type' => 'select',
      '#title' => t('TTL'),
      '#title' => $this->t('TTL'),
      '#default_value' => $settings['cache']['ttl'] ?? 0,
      '#options' => $period,
      '#description' => t('The maximum time a page can be cached by varnish.'),
      '#description' => $this->t('The maximum time a page can be cached by varnish.'),
      '#states' => [
        'visible' => [
          ':input[name="settings[adv_varnish][cache][esi]"]' => ['checked' => TRUE],
+7 −5
Original line number Diff line number Diff line
@@ -6,12 +6,14 @@ use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\adv_varnish\CacheManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Form to clear varnish cache.
 */
class ClearCacheForm extends FormBase {

  use StringTranslationTrait;
  /**
   * Constants that used for predefined options.
   */
@@ -53,7 +55,7 @@ class ClearCacheForm extends FormBase {
    ];

    $form['adv_varnish_cache_purge'] = [
      '#title' => t('Purge settings'),
      '#title' => $this->t('Purge settings'),
      '#type' => 'details',
      '#collapsible' => TRUE,
      '#open' => TRUE,
@@ -67,7 +69,7 @@ class ClearCacheForm extends FormBase {

    $form['adv_varnish_cache_purge']['type'] = [
      '#type' => 'radios',
      '#title' => t('Select purge type'),
      '#title' => $this->t('Select purge type'),
      '#options' => $options,
      '#default_value' => $form_state->getValue('type') ?: self::CACHE_CLEAR_TYPE_URI,
      '#required' => TRUE,
@@ -75,9 +77,9 @@ class ClearCacheForm extends FormBase {

    $form['adv_varnish_cache_purge']['arguments'] = [
      '#type' => 'textfield',
      '#title' => t('Tag or URL to purge.'),
      '#title' => $this->t('Tag or URL to purge.'),
      '#default_value' => $form_state->getValue('arguments'),
      '#description' => t("Examples: 'node:1', '/node/1', '/*/1'"),
      '#description' => $this->t("Examples: 'node:1', '/node/1', '/*/1'"),
      '#states' => [
        'invisible' => [
          ':input[name="type"]' => ['value' => self::CACHE_CLEAR_TYPE_FULL],
@@ -93,7 +95,7 @@ class ClearCacheForm extends FormBase {

    $form['submit'] = [
      '#type' => 'submit',
      '#value' => t('Run purge'),
      '#value' => $this->t('Run purge'),
    ];

    return $form;
+4 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\adv_varnish_block_test\Plugin\UserBlocks;
use Drupal\adv_varnish\UserBlockBase;
use Drupal\Core\Session\AccountProxyInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Provides a language config pages context.
@@ -16,6 +17,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 */
class Example extends UserBlockBase {

  use StringTranslationTrait;

  /**
   * User account interface.
   *
@@ -63,7 +66,7 @@ class Example extends UserBlockBase {
    ];

    $block['content'] = [
      '#block-bartik-account-menu ul .menu-item:first a' => t('Hi, @user', [
      '#block-bartik-account-menu ul .menu-item:first a' => $this->t('Hi, @user', [
        '@user' => $this->account->getDisplayName(),
      ]),
    ];