AbstractPageController.php

AbstractPageController

Namespace

Drupal\ooe\Page

File

lib/Drupal/ooe/Page/AbstractPageController.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * AbstractPageController
  5. */
  6. namespace Drupal\ooe\Page;
  7. use Drupal\page_controller\Controller\PageController;
  8. use Drupal\ooe\Module\DefaultModuleHelper;
  9. use Drupal\ooe\Factory\IFactory;
  10. use Drupal\ooe\Render\IRenderFactory;
  11. use Drupal\ooe\Xhtml\ITagFactory;
  12. use Drupal\ooe\Render\RenderFactory;
  13. /**
  14. * Implements shared aspects of all OOE page controllers,
  15. * which extend the strategy of the
  16. * @link https://drupal.org/project/page_controller Page Controller @endlink project.
  17. *
  18. * [Because PHP does not support multiple inheritance of implementations,
  19. * we have to mixin the implementation of @link IModuleHelper @endlink
  20. * available via @link DefaultModuleHelper @endlink.]
  21. *
  22. * UML:
  23. * @link http://drupal7demo.webel.com.au/node/1021 AbstractPageController @endlink
  24. *
  25. * @author darrenkelly
  26. */
  27. abstract class AbstractPageController extends PageController implements IPageController {
  28. /**
  29. * Delegate for mixin.
  30. *
  31. * Because of single inheritance in PHP need
  32. * wrap a delegate for mixin implementations.
  33. *
  34. * @var \Drupal\ooe\Module\IModuleHelper
  35. */
  36. private $moduleHelper;
  37. /**
  38. * Mixin. Sets the module machine name.
  39. *
  40. * @param string $module
  41. * The module machine name.
  42. *
  43. * @return \Drupal\ooe\Module\IModuleHelper
  44. * The module helper mixin of this.
  45. */
  46. public function setModule($module) {
  47. $this->moduleHelper($module);
  48. return $this->moduleHelper;
  49. // So signature the same !
  50. }
  51. /**
  52. * Mixin. The module machine name.
  53. *
  54. * @return string
  55. * The module machine name.
  56. */
  57. public function getModule() {
  58. return $this->moduleHelper->getModule();
  59. }
  60. /**
  61. * Mixin: A human readable and displayable name of the module.
  62. *
  63. * @return string
  64. * The module display name (if set)
  65. * or the module machine name as upper case.
  66. */
  67. public function getModuleDisplayName() {
  68. return $this->moduleHelper->getModuleDisplayName();
  69. }
  70. /**
  71. * Mixin. Sets the module display name.
  72. *
  73. * @param string $displayName
  74. * A human readable and displayable name of the module.
  75. *
  76. * @return IModuleHelper
  77. * The module helper mixin of this.
  78. */
  79. public function setModuleDisplayName($displayName) {
  80. return $this->moduleHelper->setModuleDisplayName($displayName);
  81. }
  82. /**
  83. * Constructor.
  84. *
  85. * @param string $module
  86. * The module machine name.
  87. */
  88. protected function __construct($module) {
  89. $this->moduleHelper = new DefaultModuleHelper($module);
  90. // Delegate for mixins.
  91. }
  92. /**
  93. * The callback name.
  94. *
  95. * @return string
  96. * The callback name.
  97. */
  98. abstract public function getCallbackName();
  99. /**
  100. * Mixin. Sets the factory of this.
  101. *
  102. * @param \Drupal\ooe\Factory\IFactory $factory
  103. * A factory.
  104. *
  105. * @return \Drupal\ooe\Module\IModuleHelper
  106. * The module helper mixin of this.
  107. */
  108. public function setFactory(IFactory $factory) {
  109. return $this->moduleHelper->setFactory($factory);
  110. }
  111. /**
  112. * Mixin. The factory of this.
  113. *
  114. * @return \Drupal\ooe\Factory\IFactory
  115. * The module helper mixin of this.
  116. */
  117. public function getFactory() {
  118. return $this->moduleHelper->getFactory();
  119. }
  120. /**
  121. * Shorthand version.
  122. *
  123. * @return \Drupal\ooe\Factory\IFactory
  124. * The factory.
  125. */
  126. protected function factory() {
  127. return $this->getFactory();
  128. }
  129. /**
  130. * A render factory for building pages with Drupal render arrays.
  131. *
  132. * @var \Drupal\ooe\Render\IRenderFactory
  133. */
  134. private $renderFactory;
  135. /**
  136. * Lazily creates a render factory.
  137. *
  138. * @return IRenderFactory
  139. * A render factory.
  140. */
  141. protected function renderFactory() {
  142. if (empty($this->renderFactory)) {
  143. $this->renderFactory = new RenderFactory();
  144. }
  145. return $this->renderFactory;
  146. }
  147. /**
  148. * Shorthand version of the lazily created render factory.
  149. *
  150. * Provided for convenience since this is used so often.
  151. *
  152. * @return IRenderFactory
  153. * A render factory.
  154. */
  155. protected function rf() {
  156. return $this->renderFactory();
  157. }
  158. /**
  159. * Shorthand version of the tag factory of the current render factory.
  160. *
  161. * Provided for convenience since this may be used often.
  162. *
  163. * @return ITagFactory
  164. * A tag factory.
  165. */
  166. protected function tf() {
  167. return $this->renderFactory()->getTagFactory();
  168. }
  169. }

Classes

Namesort descending Description
AbstractPageController Implements shared aspects of all OOE page controllers, which extend the strategy of the Page Controller project.