DateFormat.php 1.9 KB

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