vendor/sulu/sulu/src/Sulu/Bundle/SnippetBundle/Twig/DefaultSnippetTwigExtension.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Sulu.
  4. *
  5. * (c) Sulu GmbH
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Sulu\Bundle\SnippetBundle\Twig;
  11. use Sulu\Bundle\SnippetBundle\Snippet\DefaultSnippetManagerInterface;
  12. use Sulu\Bundle\SnippetBundle\Snippet\SnippetResolverInterface;
  13. use Sulu\Component\Webspace\Analyzer\RequestAnalyzerInterface;
  14. use Twig\Extension\AbstractExtension;
  15. use Twig\TwigFunction;
  16. /**
  17. * @deprecated
  18. *
  19. * Load snippets over the sulu_snippet_load_default is deprecated
  20. * and will be removed in 2.0 use sulu_snippet_load_by_area instead.
  21. *
  22. * Provides default snippets.
  23. */
  24. class DefaultSnippetTwigExtension extends AbstractExtension
  25. {
  26. public function __construct(
  27. private DefaultSnippetManagerInterface $defaultSnippetManager,
  28. private RequestAnalyzerInterface $requestAnalyzer,
  29. private SnippetResolverInterface $snippetResolver,
  30. ) {
  31. }
  32. public function getFunctions()
  33. {
  34. return [
  35. new TwigFunction('sulu_snippet_load_default', [$this, 'getDefault'], ['deprecated' => true]),
  36. ];
  37. }
  38. public function getDefault($snippetType, $webspaceKey = null, $locale = null)
  39. {
  40. @trigger_deprecation('sulu/sulu', '1.6', 'Loading snippets over the sulu_snippet_load_default is deprecated and will be removed in 2.0, use sulu_snippet_load_by_area instead.');
  41. if (!$webspaceKey) {
  42. $webspaceKey = $this->requestAnalyzer->getWebspace()->getKey();
  43. }
  44. if (!$locale) {
  45. $locale = $this->requestAnalyzer->getCurrentLocalization()->getLocale();
  46. }
  47. $ids = [
  48. $this->defaultSnippetManager->loadIdentifier($webspaceKey, $snippetType),
  49. ];
  50. // to filter null default snippet
  51. $ids = \array_filter($ids);
  52. return $this->snippetResolver->resolve($ids, $webspaceKey, $locale);
  53. }
  54. }