Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / web / core / lib / Drupal / Core / Datetime / Entity / DateFormat.php
1 <?php
2
3 namespace Drupal\Core\Datetime\Entity;
4
5 use Drupal\Core\Config\Entity\ConfigEntityBase;
6 use Drupal\Core\Config\Entity\ConfigEntityInterface;
7 use Drupal\Core\Datetime\DateFormatInterface;
8
9 /**
10  * Defines the Date Format configuration entity class.
11  *
12  * @ConfigEntityType(
13  *   id = "date_format",
14  *   label = @Translation("Date format"),
15  *   handlers = {
16  *     "access" = "Drupal\system\DateFormatAccessControlHandler",
17  *   },
18  *   entity_keys = {
19  *     "id" = "id",
20  *     "label" = "label"
21  *   },
22  *   admin_permission = "administer site configuration",
23  *   list_cache_tags = { "rendered" },
24  *   config_export = {
25  *     "id",
26  *     "label",
27  *     "locked",
28  *     "pattern",
29  *   }
30  * )
31  */
32 class DateFormat extends ConfigEntityBase implements DateFormatInterface {
33
34   /**
35    * The date format machine name.
36    *
37    * @var string
38    */
39   protected $id;
40
41   /**
42    * The human-readable name of the date format entity.
43    *
44    * @var string
45    */
46   protected $label;
47
48   /**
49    * The date format pattern.
50    *
51    * @var array
52    */
53   protected $pattern;
54
55   /**
56    * The locked status of this date format.
57    *
58    * @var bool
59    */
60   protected $locked = FALSE;
61
62   /**
63    * {@inheritdoc}
64    */
65   public function getPattern() {
66     return $this->pattern;
67   }
68
69   /**
70    * {@inheritdoc}
71    */
72   public function setPattern($pattern) {
73     $this->pattern = $pattern;
74     return $this;
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function isLocked() {
81     return (bool) $this->locked;
82   }
83
84   /**
85    * {@inheritdoc}
86    */
87   public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
88     if ($a->isLocked() == $b->isLocked()) {
89       $a_label = $a->label();
90       $b_label = $b->label();
91       return strnatcasecmp($a_label, $b_label);
92     }
93     return $a->isLocked() ? 1 : -1;
94   }
95
96   /**
97    * {@inheritdoc}
98    */
99   public function getCacheTagsToInvalidate() {
100     return ['rendered'];
101   }
102
103 }