Unverified Commit fd21c15e authored by Josh Miller's avatar Josh Miller Committed by Josh Miller
Browse files

Issue #3064851 by joshmiller: Add date formatting to list

parent 14e6b8f8
Loading
Loading
Loading
Loading
+16 −1
Changes for src/Entity/AlexandersOrder.php: 16 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -60,6 +60,21 @@ use Drupal\Core\Field\BaseFieldDefinition;
 */
class AlexandersOrder extends ContentEntityBase implements AlexandersOrderInterface {

  /**
   * The date formatter.
   *
   * @var \Drupal\Core\Datetime\DateFormatterInterface
   */
  protected $dateFormatter;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $values, $entity_type, $bundle = FALSE, $translations = []) {
    parent::__construct($values, $entity_type, $bundle, $translations);
    $this->dateFormatter = \Drupal::service('date.formatter');
  }

  /**
   * {@inheritdoc}
   */
@@ -159,7 +174,7 @@ class AlexandersOrder extends ContentEntityBase implements AlexandersOrderInterf
   * {@inheritdoc}
   */
  public function getDue() {
    return $this->get('dueDate')->value;
    return $this->dateFormatter->format((int) $this->get('dueDate')->value);
  }

  /**
+5 −1
Changes for src/OrderListBuilder.php: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -74,9 +74,13 @@ class OrderListBuilder extends EntityListBuilder {
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $due = $entity->getDue();
    if ($due === "Jan 1, 1970") {
      $due = $this->t('Pending');
    }
    $row = [
      'order_id' => $entity->id(),
      'due_date' => $entity->getDue() ?? t('Waiting for Alexanders'),
      'due_date' => $due,
      'order_number' => $entity->label(),
    ];