Commit 8b8e7264 authored by Ankitha Shetty's avatar Ankitha Shetty Committed by Mahtab Alam
Browse files

Issue #3124427 by urvashi_vora, ankithashetty, mahtab_alam: \Drupal calls...

Issue #3124427 by urvashi_vora, ankithashetty, mahtab_alam: \Drupal calls should be avoided in classes, use dependency injection instead
parent 5417043e
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -5,12 +5,40 @@ namespace Drupal\content_close\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * ContentCloseForm close.
 */
class ContentCloseForm extends ConfigFormBase {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a ContentCloseForm object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('entity_type.manager')
    );
  }

  /**
   * {@inheritdoc}
   */
@@ -38,7 +66,7 @@ class ContentCloseForm extends ConfigFormBase {
      '#open' => TRUE,
    ];

    $node_types = \Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple();
    $node_types = $this->entityTypeManager->getStorage('node_type')->loadMultiple();
    foreach ($node_types as $node_type) {
      $form['content_type_name'][$node_type->id()] = [
        '#type' => 'datetime',
@@ -54,7 +82,7 @@ class ContentCloseForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $node_types = \Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple();
    $node_types = $this->entityTypeManager->getStorage('node_type')->loadMultiple();
    foreach ($node_types as $node_type) {
      $this->configFactory->getEditable('content_close.settings')
        ->set($node_type->id(), ($form_state->getValue($node_type->id())) ? $form_state->getValue($node_type->id())->getTimeStamp() : '')