Commit 7b80cdd1 authored by Sourabh Jain's avatar Sourabh Jain Committed by Mark Quirvien Cristobal
Browse files

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

parent ed1ef5ce
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Plugin implementation of the 'zip file' field type.
@@ -23,6 +24,7 @@ use Drupal\Core\TypedData\DataDefinition;
 * )
 */
class ZipFileItem extends FileItem {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
@@ -73,9 +75,9 @@ class ZipFileItem extends FileItem {

    $element['tracking_script_field'] = [
      '#type' => 'checkbox',
      '#title' => t('Enable <em>Tracking Script</em> field'),
      '#title' => $this->t('Enable <em>Tracking Script</em> field'),
      '#default_value' => isset($settings['tracking_script_field']) ? $settings['tracking_script_field'] : '',
      '#description' => t('The tracking script field allows user to inject the tracking code/script to all html files'),
      '#description' => $this->t('The tracking script field allows user to inject the tracking code/script to all html files'),
      '#weight' => 11,
      '#attributes' => [
        'data-name' => 'tracking_script_field',
@@ -85,9 +87,9 @@ class ZipFileItem extends FileItem {

    $element['tracking_script_field_default'] = [
      '#type' => 'textarea',
      '#title' => t('Default <em>Tracking Script</em>'),
      '#title' => $this->t('Default <em>Tracking Script</em>'),
      '#default_value' => isset($settings['tracking_script_field_default']) ? $settings['tracking_script_field_default'] : '',
      '#description' => t('Tracking script default value.'),
      '#description' => $this->t('Tracking script default value.'),
      '#weight' => 11,
      '#states' => [
        'visible' => [
@@ -137,7 +139,7 @@ class ZipFileItem extends FileItem {
      }

      if ($this->tracking_script) {
        $tracking_script_file = $fs->saveData($this->tracking_script, $tracking_script, FileSystemInterface::EXISTS_REPLACE);
        $fs->saveData($this->tracking_script, $tracking_script, FileSystemInterface::EXISTS_REPLACE);
        if ($html_files = $fs->scanDirectory($folderUri, '/\b(\.html|\.HTML)\b/')) {
          foreach ($html_files as $file) {
            $fs->copy($file->uri, $folderUri . '/' . $file->name . '.old', FileSystemInterface::EXISTS_REPLACE);
+5 −3
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\field_zip_file\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Plugin\Field\FieldWidget\FileWidget;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Link;
use Drupal\Core\Url;

@@ -20,6 +21,7 @@ use Drupal\Core\Url;
 * )
 */
class ZipFileWidget extends FileWidget {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
@@ -36,7 +38,7 @@ class ZipFileWidget extends FileWidget {
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element['hide_unzipped_url'] = [
      '#type' => 'checkbox',
      '#title' => t('Hide the URL of the unzipped folder'),
      '#title' => $this->t('Hide the URL of the unzipped folder'),
      '#default_value' => $this->getSetting('hide_unzipped_url'),
    ];
    return $element;
@@ -47,7 +49,7 @@ class ZipFileWidget extends FileWidget {
   */
  public function settingsSummary() {
    $summary = parent::settingsSummary();
    $summary[] = t('Hide unzipped URL: @hide_unzipped_url', ['@hide_unzipped_url' => $this->getSetting('hide_unzipped_url') ? t('Yes') : t('No')]);
    $summary[] = $this->t('Hide unzipped URL: @hide_unzipped_url', ['@hide_unzipped_url' => $this->getSetting('hide_unzipped_url') ? $this->t('Yes') : $this->t('No')]);
    return $summary;
  }

@@ -116,7 +118,7 @@ class ZipFileWidget extends FileWidget {
    if ($element['#tracking_script_field'] && $item['fids']) {
      $element['tracking_script'] = [
        '#type' => 'textarea',
        '#title' => t('Tracking script'),
        '#title' => $this->t('Tracking script'),
        '#value' => isset($item['tracking_script']) ? $item['tracking_script'] : $element['#default_value']['tracking_script'],
      ];
    }