Commit b9d98f0c authored by Ramon  Serra Vasconcelos's avatar Ramon Serra Vasconcelos Committed by NGUYEN Bao
Browse files

Issue #3310638 by ramonvasconcelos, akshay.kelotra, lazzyvn: \Drupal calls...

Issue #3310638 by ramonvasconcelos, akshay.kelotra, lazzyvn: \Drupal calls should be avoided in classes, use dependency injection instead
parent 902bcbec
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -3,5 +3,3 @@ type: module
description: This module uses the dhtmlx GANTT javascript library
package: Views
core_version_requirement: ^9 || ^10
dependencies:
  - views:views
+23 −3
Original line number Diff line number Diff line
@@ -7,6 +7,9 @@ use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\paragraphs\Entity\Paragraph;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\views\Views;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * Returns responses for Gantt routes.
@@ -28,13 +31,30 @@ class GanttController extends ControllerBase {
   */
  private $get = [];

  /**
   * {@inheritDoc}
   *
   * @var Drupal\Core\Datetime\Entity\DateFormat;
   */
  private $dateFormat;

  /**
   * {@inheritDoc}
   */
  public function __construct() {
    $request = \Drupal::request();
  public function __construct(RequestStack $request, DateFormat $dateFormat) {
    $this->post = $request->request->all();
    $this->get = $request->query->all();
    $this->dateFormat = $dateFormat;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('request_stack'),
      $container->get('date.formatter')
    );
  }

  /**
@@ -135,7 +155,7 @@ class GanttController extends ControllerBase {
   * Convert date return with format Y-m-d.
   */
  protected function formatDate($date, $type = 'date', $format = 'Y-m-d H:i:s') {
    $drupalShortFormat = DateFormat::load('short')->getPattern();
    $drupalShortFormat = $this->dateFormat->load('short')->getPattern();
    if ($type == 'date') {
      $format = current(explode(' ', $format));
      $drupalShortFormat = current(explode(' ', $drupalShortFormat));