vendor/ibexa/core/src/lib/MVC/Symfony/View/ContentView.php line 39

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. namespace Ibexa\Core\MVC\Symfony\View;
  7. use Ibexa\Contracts\Core\Repository\Values\Content\Content;
  8. use Ibexa\Contracts\Core\Repository\Values\Content\Location;
  9. /**
  10. * Main object to be rendered by the View Manager when viewing a content.
  11. * Holds the path to the template to be rendered by the view manager and the parameters to inject in it.
  12. *
  13. * The template path can be a closure. In that case, the view manager will invoke it instead of loading a template.
  14. * $parameters will be passed to the callable in addition to the Content or Location object (depending on the context).
  15. * The prototype of the closure must be :
  16. * <code>
  17. * namespace Foo;
  18. * use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
  19. * use Ibexa\Contracts\Core\Repository\Values\Content\Location;
  20. *
  21. * // For a content
  22. * function ( ContentInfo $contentInfo, array $parameters = array() )
  23. * {
  24. * // Do something to render
  25. * // Must return a string to display
  26. * }
  27. *
  28. * // For a location
  29. * function ( Location $location, array $parameters = array() )
  30. * {
  31. * // Do something to render
  32. * // Must return a string to display
  33. * }
  34. * </code>
  35. */
  36. class ContentView extends BaseView implements View, ContentValueView, LocationValueView, EmbedView, CachableView
  37. {
  38. /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content */
  39. private $content;
  40. /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location|null */
  41. private $location;
  42. /** @var bool */
  43. private $isEmbed = false;
  44. /**
  45. * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content $content
  46. */
  47. public function setContent(Content $content)
  48. {
  49. $this->content = $content;
  50. }
  51. /**
  52. * Returns the Content.
  53. *
  54. * @return \Ibexa\Contracts\Core\Repository\Values\Content\Content
  55. */
  56. public function getContent()
  57. {
  58. return $this->content;
  59. }
  60. /**
  61. * @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $location
  62. */
  63. public function setLocation(Location $location)
  64. {
  65. $this->location = $location;
  66. }
  67. /**
  68. * @return \Ibexa\Contracts\Core\Repository\Values\Content\Location|null
  69. */
  70. public function getLocation()
  71. {
  72. return $this->location;
  73. }
  74. protected function getInternalParameters()
  75. {
  76. $parameters = ['content' => $this->content];
  77. if ($this->location !== null) {
  78. $parameters['location'] = $this->location;
  79. }
  80. return $parameters;
  81. }
  82. /**
  83. * Sets the value as embed / not embed.
  84. *
  85. * @param bool $value
  86. */
  87. public function setIsEmbed($value)
  88. {
  89. $this->isEmbed = (bool)$value;
  90. }
  91. /**
  92. * Is the view an embed or not.
  93. *
  94. * @return bool True if the view is an embed, false if it is not.
  95. */
  96. public function isEmbed()
  97. {
  98. return $this->isEmbed;
  99. }
  100. }
  101. class_alias(ContentView::class, 'eZ\Publish\Core\MVC\Symfony\View\ContentView');