Commit 0b962423 authored by Damien McKenna's avatar Damien McKenna Committed by Ra Mänd
Browse files

Issue #3112427 by DamienMcKenna, Johnny Santos: \Drupal calls should be...

Issue #3112427 by DamienMcKenna, Johnny Santos: \Drupal calls should be avoided in classes, use dependency injection instead in src/Plugin/Field/FieldWidget/InlineEntityFormBase.php
parent 0bd5cb7e
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\inline_entity_form\TranslationHelper;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\content_translation\ContentTranslationManagerInterface;

/**
 * Inline entity form widget base class.
@@ -54,6 +55,13 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
   */
  protected $entityDisplayRepository;

  /**
   * The content translation manager.
   *
   * @var \Drupal\content_translation\ContentTranslationManagerInterface
   */
  protected $contentTranslationManager;

  /**
   * Constructs an InlineEntityFormBase object.
   *
@@ -73,13 +81,16 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
   *   The entity type manager.
   * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
   *   The entity display repository.
   * @param \Drupal\content_translation\ContentTranslationManagerInterface $manager
   *   Content translation manager.
   */
  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, ContentTranslationManagerInterface $translation_manager) {
    parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);

    $this->entityTypeBundleInfo = $entity_type_bundle_info;
    $this->entityTypeManager = $entity_type_manager;
    $this->entityDisplayRepository = $entity_display_repository;
    $this->contentTranslationManager = $translation_manager;
    $this->createInlineFormHandler();
  }

@@ -95,7 +106,8 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
      $configuration['third_party_settings'],
      $container->get('entity_type.bundle.info'),
      $container->get('entity_type.manager'),
      $container->get('entity_display.repository')
      $container->get('entity_display.repository'),
      $container->get('content_translation.manager')
    );
  }

@@ -469,7 +481,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
   */
  protected function isTranslating(FormStateInterface $form_state) {
    if (TranslationHelper::isTranslating($form_state)) {
      $translation_manager = \Drupal::service('content_translation.manager');
      $translation_manager = $this->contentTranslationManager;
      $target_type = $this->getFieldSetting('target_type');
      foreach ($this->getTargetBundles() as $bundle) {
        if ($translation_manager->isEnabled($target_type, $bundle)) {
+14 −3
Original line number Diff line number Diff line
@@ -47,6 +47,13 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF
   */
  protected $selectionManager;

  /**
   * The content translation manager.
   *
   * @var \Drupal\content_translation\ContentTranslationManagerInterface
   */
  protected $contentTranslationManager;

  /**
   * Constructs a InlineEntityFormComplex object.
   *
@@ -70,11 +77,14 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF
   *   Module handler service.
   * @param \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface $selection_manager
   *   The selection plugin manager.
   * @param \Drupal\content_translation\ContentTranslationManagerInterface $translation_manager
   *   Content translation manager.
   */
  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, ModuleHandlerInterface $module_handler, SelectionPluginManagerInterface $selection_manager) {
    parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings, $entity_type_bundle_info, $entity_type_manager, $entity_display_repository);
  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, ModuleHandlerInterface $module_handler, SelectionPluginManagerInterface $selection_manager, ContentTranslationManagerInterface $translation_manager) {
    parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings, $entity_type_bundle_info, $entity_type_manager, $entity_display_repository, $translation_manager);
    $this->moduleHandler = $module_handler;
    $this->selectionManager = $selection_manager;
    $this->contentTranslationManager = $translation_manager;
  }

  /**
@@ -91,7 +101,8 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF
      $container->get('entity_type.manager'),
      $container->get('entity_display.repository'),
      $container->get('module_handler'),
      $container->get('plugin.manager.entity_reference_selection')
      $container->get('plugin.manager.entity_reference_selection'),
      $container->get('content_translation.manager')
    );
  }