Skip to content
Snippets Groups Projects
Commit f683604b authored by Hardik Pandya's avatar Hardik Pandya Committed by aron novak
Browse files

Issue #3346861: Drupal Coding Standards Issues | phpcs

parent a46e3288
No related branches found
No related tags found
1 merge request!17Issue #3346861: Drupal Coding Standards Issues | phpcs
......@@ -16,7 +16,7 @@ class DateFormatAddForm extends DateFormatFormBase {
*/
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = t('Add format');
$actions['submit']['#value'] = $this->t('Add format');
return $actions;
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\intl_date\Form;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityDeleteForm;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -20,14 +21,24 @@ class DateFormatDeleteForm extends EntityDeleteForm {
*/
protected $dateFormatter;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* Constructs an DateFormatDeleteForm object.
*
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct(DateFormatterInterface $date_formatter) {
public function __construct(DateFormatterInterface $date_formatter, TimeInterface $time) {
$this->dateFormatter = $date_formatter;
$this->time = $time;
}
/**
......@@ -35,7 +46,8 @@ class DateFormatDeleteForm extends EntityDeleteForm {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('date.formatter')
$container->get('date.formatter'),
$container->get('datetime.time')
);
}
......@@ -43,9 +55,9 @@ class DateFormatDeleteForm extends EntityDeleteForm {
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the format %name : %format?', [
return $this->t('Are you sure you want to delete the format %name : %format?', [
'%name' => $this->entity->label(),
'%format' => $this->dateFormatter->format(\Drupal::time()->getRequestTime(), $this->entity->id()),
'%format' => $this->dateFormatter->format($this->time->getRequestTime(), $this->entity->id()),
]);
}
......
......@@ -16,7 +16,7 @@ class DateFormatEditForm extends DateFormatFormBase {
*/
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = t('Save format');
$actions['submit']['#value'] = $this->t('Save format');
unset($actions['delete']);
return $actions;
}
......
......@@ -3,10 +3,10 @@
namespace Drupal\intl_date\Form;
use Drupal\Core\Config\Entity\ConfigEntityStorageInterface;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityForm;
/**
* Provides a base form for date formats.
......
......@@ -2,9 +2,15 @@
namespace Drupal\intl_date;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a class to build a listing of Intl Date Format entities.
......@@ -13,12 +19,52 @@ use Drupal\Core\Entity\EntityInterface;
*/
class IntlDateFormatListBuilder extends ConfigEntityListBuilder {
use StringTranslationTrait;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* Constructs a new IntlDateFormatListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The translation manager.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, TimeInterface $time, TranslationInterface $string_translation) {
parent::__construct($entity_type, $storage);
$this->time = $time;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('datetime.time'),
$container->get('string_translation')
);
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = t('Name');
$header['pattern'] = t('Pattern');
$header['label'] = $this->t('Name');
$header['pattern'] = $this->t('Pattern');
return $header + parent::buildHeader();
}
......@@ -30,7 +76,7 @@ class IntlDateFormatListBuilder extends ConfigEntityListBuilder {
return [];
}
$row['label'] = $entity->label();
$row['pattern'] = IntlDate::format(\Drupal::time()->getRequestTime(), $entity->get('pattern'));
$row['pattern'] = IntlDate::format($this->time->getRequestTime(), $entity->get('pattern'));
return $row + parent::buildRow($entity);
}
......
......@@ -63,8 +63,8 @@ class IntlDateTimeDefaultFormatter extends DateTimeFormatterBase {
$form['format_type'] = [
'#type' => 'select',
'#title' => t('Date format'),
'#description' => t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."),
'#title' => $this->t('Date format'),
'#description' => $this->t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."),
'#options' => $options,
'#default_value' => $this->getSetting('format_type'),
];
......@@ -79,7 +79,7 @@ class IntlDateTimeDefaultFormatter extends DateTimeFormatterBase {
$summary = parent::settingsSummary();
$date = new DrupalDateTime();
$summary[] = t('Format: @display', ['@display' => $this->formatDate($date)]);
$summary[] = $this->t('Format: @display', ['@display' => $this->formatDate($date)]);
return $summary;
}
......
......@@ -2,8 +2,8 @@
namespace Drupal\Tests\intl_date\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\intl_date\IntlDate;
use Drupal\Tests\UnitTestCase;
/**
* Test date rendering.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment