CreatedDay.php 1.2 KB
Newer Older
1 2
<?php

3 4
/**
 * @file
5
 * Definition of Drupal\node\Plugin\views\argument\CreatedDay.
6 7
 */

8
namespace Drupal\node\Plugin\views\argument;
9

10
use Drupal\Component\Annotation\Plugin;
11
use Drupal\views\Plugin\views\argument\Date;
12 13 14

/**
 * Argument handler for a day (DD)
15
 *
16
 * @Plugin(
17
 *   id = "node_created_day",
18 19
 *   arg_format = "d",
 *   format = "j",
20
 *   module = "node"
21 22 23
 * )
 */
class CreatedDay extends Date {
24

25 26 27 28 29 30
  /**
   * Provide a link to the next level of the view
   */
  function summary_name($data) {
    $day = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
    // strtotime respects server timezone, so we need to set the time fixed as utc time
31
    return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC');
32 33 34 35 36 37 38
  }

  /**
   * Provide a link to the next level of the view
   */
  function title() {
    $day = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
39
    return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC');
40 41 42 43 44 45
  }

  function summary_argument($data) {
    // Make sure the argument contains leading zeroes.
    return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT);
  }
46

47
}