PageContentTrait.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @package Grav\Common\Flex
  5. *
  6. * @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved.
  7. * @license MIT License; see LICENSE file for details.
  8. */
  9. namespace Grav\Common\Flex\Types\Pages\Traits;
  10. use Grav\Common\Utils;
  11. /**
  12. * Implements PageContentInterface.
  13. */
  14. trait PageContentTrait
  15. {
  16. /**
  17. * @inheritdoc
  18. */
  19. public function id($var = null): string
  20. {
  21. $property = 'id';
  22. $value = null === $var ? $this->getProperty($property) : null;
  23. if (null === $value) {
  24. $value = $this->language() . ($var ?? ($this->modified() . md5($this->filePath() ?? $this->getKey())));
  25. $this->setProperty($property, $value);
  26. if ($this->doHasProperty($property)) {
  27. $value = $this->getProperty($property);
  28. }
  29. }
  30. return $value;
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function date($var = null): int
  36. {
  37. return $this->loadHeaderProperty(
  38. 'date',
  39. $var,
  40. function ($value) {
  41. $value = $value ? Utils::date2timestamp($value, $this->getProperty('dateformat')) : false;
  42. if (!$value) {
  43. // Get the specific translation updated date.
  44. $meta = $this->getMetaData();
  45. $language = $meta['lang'] ?? '';
  46. $template = $this->getProperty('template');
  47. $value = $meta['markdown'][$language][$template] ?? 0;
  48. }
  49. return $value ?: $this->modified();
  50. }
  51. );
  52. }
  53. /**
  54. * @inheritdoc
  55. * @param bool $bool
  56. */
  57. public function isPage(bool $bool = true): bool
  58. {
  59. $meta = $this->getMetaData();
  60. return empty($meta['markdown']) !== $bool;
  61. }
  62. }