DemoOfMenuTabs.php

DemoOfMenuTabs

Namespace

Drupal\ooe\Demo\Tabs

File

lib/Drupal/ooe/Demo/Tabs/DemoOfMenuTabs.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * DemoOfMenuTabs
  5. */
  6. namespace Drupal\ooe\Demo\Tabs;
  7. use Drupal\ooe\Module\DefaultModuleHelper;
  8. use Drupal\ooe\Factory\IFactory;
  9. /**
  10. * Demonstrates @link MenuTabs @endlink
  11. *
  12. * Convention: This is called DemoOfMenuTabs rather than DemoMenuTabs
  13. * as it is not an IMenuTabs (it uses an IMenuTabs).
  14. *
  15. * It is extremely important that you examine this demonstration class
  16. * in conjunction with the explanation and UML diagram(s) at
  17. * @link http://drupal7demo.webel.com.au/node/1019 @endlink
  18. * as it deliberately includes some examples of HOW NOT TO DO THINGS
  19. * when working in general with the UML-friendly Webel coding recipe for OOE.
  20. *
  21. * Note also that this example is NOT an @link IProject @endlink;
  22. * most other examples in the OOE suite leverage @link IProject @endlink
  23. * as a starting point, but you are under no obligation to do so.
  24. *
  25. * @author darrenkelly
  26. */
  27. class DemoOfMenuTabs extends DefaultModuleHelper {
  28. /**
  29. * The menu tabs.
  30. *
  31. * @var \Drupal\ooe\Menu\IMenuTabs
  32. */
  33. private $menuTabs;
  34. /**
  35. * The menu tabs.
  36. *
  37. * @return \Drupal\ooe\Menu\IMenuTabs
  38. * The menu tabs.
  39. */
  40. public function getMenuTabs() {
  41. return $this->menuTabs;
  42. }
  43. /**
  44. * Constructor: fetches an @link IMenuTabs @endlink from a factory.
  45. *
  46. * Creates some tabs with page controllers.
  47. *
  48. * This example deliberately pragmatically uses inline "new" creation
  49. * of page controllers passed directly to the tab creation method
  50. * (instead of private variables with lazy creation/configuration methods
  51. * for each of the page controllers).
  52. *
  53. * The approach here is NOT graphical UML-friendly, and is only done
  54. * to show you WHAT NOT TO DO when working with OOE as explained here:
  55. *
  56. * @link http://drupal7demo.webel.com.au/node/1019 @endlink
  57. *
  58. * @link http://drupal7demo.webel.com.au/node/1177 @endlink
  59. *
  60. * @param string $module
  61. * The machine name of the module.
  62. * @param IFactory $factory
  63. * Optional factory; if none given or null
  64. * a @link DefaultFactory @endlink will be used.
  65. */
  66. public function __construct($module, IFactory $factory = NULL) {
  67. parent::__construct($module, $factory);
  68. $path = $module . '/demo/tabs';
  69. // @todo ENCAPSULATE!
  70. $this->menuTabs = $this->factory()->newMenuTabs(
  71. $path,
  72. new DemoPageControllerMain(),
  73. // Pseudo local page controller is not UML-friendly.
  74. $this->getModuleDisplayName() . ": Tabs demo"
  75. );
  76. $this->menuTabs->newTabMenuItem(
  77. new DemoPageControllerTab2(),
  78. // Pseudo local page controller is not UML-friendly.
  79. "Tab2"
  80. );
  81. $this->menuTabs->newTabMenuItem(
  82. new DemoPageControllerTab3(),
  83. // Pseudo local page controller is not UML-friendly.
  84. "Tab3"
  85. );
  86. }
  87. /**
  88. * All of the menu items of this.
  89. *
  90. * @return \Drupal\ooe\Menu\IMenuItem[]
  91. * All of the menu items of this.
  92. */
  93. public function getMenuItems() {
  94. return $this->menuTabs->getMenuItems();
  95. }
  96. }

Classes

Namesort descending Description
DemoOfMenuTabs Demonstrates MenuTabs