Verified Commit 665d2d93 authored by Atul Ghate's avatar Atul Ghate Committed by Lee Rowlands
Browse files

Issue #3295464 by atul ghate, Rakhi Soni: t() calls should be avoided in classes

parent af4f49f1
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -10,11 +10,13 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Defines a class for altering the field UI.
 */
class ChainsUi implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * Entity field manager.
@@ -77,9 +79,9 @@ class ChainsUi implements ContainerInjectionInterface {
    $entity_type = $form['#entity_type'];
    $bundle = $form['#bundle'];

    /* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
    /** @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
    $entity_form = $form_state->getFormObject();
    /* @var \Drupal\Core\Entity\Display\EntityDisplayInterface $entity_display */
    /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $entity_display */
    $entity_display = $entity_form->getEntity();
    $view_mode = $entity_display->getMode();
    if (!$entity_display->getThirdPartySetting('ds', 'layout', FALSE)) {
@@ -110,7 +112,7 @@ class ChainsUi implements ContainerInjectionInterface {
    // Add chains form.
    $form['ds_chains'] = [
      '#type' => 'details',
      '#title' => t('Chained fields for @bundle in @view_mode', [
      '#title' => $this->t('Chained fields for @bundle in @view_mode', [
        '@bundle' => str_replace('_', ' ', $bundle),
        '@view_mode' => str_replace('_', ' ', $view_mode),
      ]),
@@ -133,7 +135,8 @@ class ChainsUi implements ContainerInjectionInterface {
   * Entity builder.
   */
  public static function buildEntity($entity_type, EntityViewDisplayInterface $display, array $form, FormStateInterface $form_state) {
    $display->setThirdPartySetting('ds_chains', 'fields', array_filter($form_state->getValue(['ds_chains', 'fields'], [])));
    $display->setThirdPartySetting('ds_chains', 'fields',
     array_filter($form_state->getValue(['ds_chains', 'fields'], [])));
    \Drupal::service('plugin.manager.ds')->clearCachedDefinitions();
  }

+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ class ChainsDeriver extends DeriverBase implements ContainerDeriverInterface {
          }
          $field = $field_instances[$field_name];
          $settings = $field->getSetting('handler_settings');
          $target_bundles = isset($settings['target_bundles']) ? $settings['target_bundles'] : array_keys($this->entityTypeBundleInfo->getBundleInfo($target_type));
          $target_bundles = $settings['target_bundles'] ?? array_keys($this->entityTypeBundleInfo->getBundleInfo($target_type));
          foreach ($target_bundles as $target_bundle) {
            $chained_fields = $this->entityFieldManager->getFieldDefinitions($target_type, $target_bundle);
            foreach ($chained_fields as $chained_field_name => $chained_field_definition) {
+4 −3
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ use Drupal\Core\Field\FormatterPluginManager;
use Drupal\Core\Form\FormStateInterface;
use Drupal\ds\Plugin\DsField\DsFieldBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Provides a DS field that chains entity reference fields.
@@ -21,7 +22,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 * )
 */
class ChainedField extends DsFieldBase {

  use StringTranslationTrait;
  /**
   * Formatter manager.
   *
@@ -107,7 +108,7 @@ class ChainedField extends DsFieldBase {
      $element['chain_settings']['ui_limit'] = [
        '#type' => 'number',
        '#title' => $this->t('UI Limit'),
        '#description' => t('Enter a number to limit the number of items to print for the items in the outer reference field. Leave empty to display them all.'),
        '#description' => $this->t('Enter a number to limit the number of items to print for the items in the outer reference field. Leave empty to display them all.'),
        '#default_value' => $this->configuration['chain_settings']['ui_limit'],
      ];
    }
@@ -141,7 +142,7 @@ class ChainedField extends DsFieldBase {
    $cache = new CacheableMetadata();
    $empty = TRUE;

    $ui_limit = isset($this->configuration['chain_settings']['ui_limit']) ? $this->configuration['chain_settings']['ui_limit'] : NULL;
    $ui_limit = $this->configuration['chain_settings']['ui_limit'] ?? NULL;

    /** @var \Drupal\Core\Field\FieldItemInterface $field_item */
    foreach ($entity->get($field_name) as $delta => $field_item) {
+0 −1
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\Tests\ds_chains\Kernel;

use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;