vendor/pimcore/pimcore/lib/Twig/Extension/GlossaryExtension.php line 74

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Pimcore
  5. *
  6. * This source file is available under two different licenses:
  7. * - GNU General Public License version 3 (GPLv3)
  8. * - Pimcore Commercial License (PCL)
  9. * Full copyright and license information is available in
  10. * LICENSE.md which is distributed with this source code.
  11. *
  12. * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13. * @license http://www.pimcore.org/license GPLv3 and PCL
  14. */
  15. namespace Pimcore\Twig\Extension;
  16. use Pimcore\Tool\Glossary\Processor;
  17. use Pimcore\Twig\TokenParser\GlossaryTokenParser;
  18. use Twig\Extension\AbstractExtension;
  19. use Twig\TwigFilter;
  20. /**
  21. * @internal
  22. */
  23. class GlossaryExtension extends AbstractExtension
  24. {
  25. /**
  26. * @var \Pimcore\Tool\Glossary\Processor
  27. */
  28. private $glossaryProcessor;
  29. /**
  30. * @param \Pimcore\Tool\Glossary\Processor $glossaryProcessor
  31. *
  32. */
  33. public function __construct(Processor $glossaryProcessor)
  34. {
  35. $this->glossaryProcessor = $glossaryProcessor;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function getFilters(): array
  41. {
  42. return [
  43. new TwigFilter('pimcore_glossary', [$this, 'applyGlossary'], ['is_safe' => ['html']]),
  44. ];
  45. }
  46. /**
  47. * @param string $string
  48. * @param array $options
  49. *
  50. * @return string
  51. */
  52. public function applyGlossary(string $string, array $options = []): string
  53. {
  54. if (empty($string) || !is_string($string)) {
  55. return $string;
  56. } else {
  57. return $this->glossaryProcessor->process($string, $options);
  58. }
  59. }
  60. /**
  61. * @deprecated
  62. */
  63. public function getTokenParsers(): array
  64. {
  65. trigger_deprecation('pimcore/pimcore', '10.1', 'Usage of pimcoreglossary tag is deprecated since version 10.1 and will be removed in Pimcore 11. Use pimcore_glossary Twig filter instead.');
  66. return [
  67. new GlossaryTokenParser(),
  68. ];
  69. }
  70. /**
  71. * @deprecated
  72. */
  73. public function start()
  74. {
  75. ob_start();
  76. }
  77. /**
  78. * @deprecated
  79. *
  80. * @param array $options
  81. */
  82. public function stop(array $options = [])
  83. {
  84. $contents = ob_get_clean();
  85. if (empty($contents) || !is_string($contents)) {
  86. $result = $contents;
  87. } else {
  88. $result = $this->glossaryProcessor->process($contents, $options);
  89. }
  90. echo $result;
  91. }
  92. }