OoeBridge.php

OoeBridge

Namespace

Drupal\ooe\Demo\Module

File

lib/Drupal/ooe/Demo/Module/OoeBridge.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * OoeBridge
  5. */
  6. namespace Drupal\ooe\Demo\Module;
  7. // OK with xautoload, and MyClassOrInterface.php (not MyClassOrInterface.inc).
  8. use Drupal\ooe\Module\AbstractModuleMap;
  9. use Drupal\ooe\Common;
  10. use Drupal\ooe\Demo\Tabs\DemoOfMenuTabs;
  11. use Drupal\ooe\Theme\BartikRegions;
  12. use Drupal\ooe\Demo\Adapted\CurrentPosts;
  13. use Drupal\ooe\Demo\Project\Demo;
  14. use Drupal\ooe\Demo\Arguments\DemoOfPageArguments;
  15. use Drupal\ooe\Demo\Arguments\IDemoOfPageArguments;
  16. use Drupal\ooe\Demo\Form\DemoOfForms;
  17. // For convenience (brevity) define some holders of Common consts.
  18. define('STEM_DEMO_FORMS', Common::STEM_DEMO_FORMS);
  19. /**
  20. * @author Darren Kelly (Webel IT Australia)
  21. *
  22. * The is the "module-file to object-orientation" bridge
  23. * for the main OOE tutorial module:
  24. * @link http://drupal7demo.webel.com.au/module/ooe Webel Drupal7 demo: OOE @endlink
  25. *
  26. * It enables one, in combination with a
  27. * @link http://drupal7demo.webel.com.au/node/1034 special PHP coding recipe @endlink,
  28. * developed by Darren Kelly of Webel IT Australia,
  29. * to reverse-engineer and model significant portions
  30. * of the object-oriented parts of the system (everything on
  31. * the "other side" of the ooe.module file) in graphical
  32. * @link http://drupal7demo.webel.com.au/node/47 Unified Modelling Language (UML) @endlink !
  33. *
  34. * This class includes object-oriented bridge method equivalents of
  35. * all hook, handler, and callback functions in the .module file.
  36. * The main ooe.module file delegates every (!) non-OO
  37. * hook, handler, or callback function to
  38. * a method in this bridge with identical function name, except
  39. * the MYMODULE_ prefix is dropped from each delegate method here.
  40. * (The method parameter signatures need not always exactly match the
  41. * .module function signatures, since in some cases the entire set of
  42. * arguments is simple automatically forwarded to downstream delegates.)
  43. *
  44. * IMPORTANT: This special OOE bridge convention means that the delegate
  45. * methods (only) of such bridge classes (only) must depart from the
  46. * @link https://drupal.org/node/608152 Drupal OO coding standard recommendation @endlink
  47. * that 'Methods and class properties should use lowerCamel naming'
  48. * in order to match the
  49. * @link https://drupal.org/coding-standards">non-OO Drupal coding standard @endlink
  50. * that 'Functions and variables should be named using lowercase,
  51. * and words should be separated with an underscore'.
  52. *
  53. * The operations/methods of all other Classes and Interfaces in the
  54. * OOE system otherwise meet the Drupal function coding standards,
  55. * except that there is an outstanding inconsistency regarding
  56. * $camelCase vs $lower_case parameter variables for methods:
  57. * @link https://www.drupal.org/node/2303963 OO: Coder complains about camel caps (camelCase) argument to setter method in Class @endlink
  58. *
  59. * The only callbacks, validate and submit handlers
  60. * given here are for demonstration of the "old" Drupal7 way of doing it;
  61. * in OOE otherwise all callbacks and handlers are encapsulated in
  62. * special object-oriented controllers like
  63. * @link \Drupal\ooe\Page\IPageController @endlink
  64. * and
  65. * @link \Drupal\ooe\Form\IFormController @endlink.
  66. *
  67. * In other words, for the
  68. * sake of educational counter-demonstration, this bridge is more complex
  69. * than a bridge for a completely object-oriented OOE-style module need be.
  70. *
  71. * While one could directly implement many of the methods here, that would
  72. * undermine its role as a bridge; thus most of the delegate methods here
  73. * in turn delegate to implementations provided by demonstration
  74. * @link IProject @endlink implementations, and to page controller
  75. * and form controller demonstrations.
  76. */
  77. class OoeBridge extends AbstractModuleMap {
  78. /**
  79. * Constructor.
  80. *
  81. * @todo Consider introducing an IModule instead
  82. * of just passing the module machine name around.
  83. *
  84. * @param string $module
  85. * The module machine name.
  86. */
  87. public function __construct($module) {
  88. parent::__construct($module);
  89. }
  90. /**
  91. * Delegate for the ooe_help() implementation of hook_help().
  92. *
  93. * Displays help and module information
  94. * (in this case merely the Current Posts example help).
  95. *
  96. * Adapted from the Current Posts example:
  97. * @link https://drupal.org/node/1095546 Writing comments and implementing your first hook @endlink
  98. *
  99. * Visit also
  100. * @link https://drupal.org/node/632280 Help text standard (for core and contrib) @endlink
  101. *
  102. * @todo Use OOE
  103. * @link IRender @endlink objects (currently it just uses HTML markup).
  104. *
  105. * @param string $path
  106. * The path of the site we're using to display help
  107. *
  108. * @param array $arg
  109. * Array that holds the current path as returned from arg() function
  110. *
  111. * @return string|array
  112. * A page string or render array for help info.
  113. *
  114. * @see http://drupal7demo.webel.com.au/module/ooe
  115. *
  116. * @see http://drupal7demo.webel.com.au/module/ooe/uml
  117. *
  118. * @see http://drupal7demo.webel.com.au/module/api/ooe
  119. */
  120. public function help($path, $arg) {
  121. switch ($path) {
  122. // 'A switch statement is used here because it is typical for the
  123. // help function to offer more than one page containing help text.'
  124. case "admin/help#ooe":
  125. // ORIGINAL.
  126. // 'The admin/help#modulename case is used by Drupal core
  127. // to link from the main help page (/admin/help or ?q=admin/help).'
  128. // return '<p>' . t("Displays links to nodes created on this date") .
  129. // '</p>';
  130. // 'You will eventually want to add more text
  131. // to provide a better help message to the user'
  132. // Webel.
  133. return '<p>' . t("The Current Posts part of the OOE demo displays links to nodes created on this date") . '</p>';
  134. break;
  135. // Coder: WARNING | Code after RETURN statement cannot be executed.
  136. // Webel: left in since in the original Current Posts example.
  137. }
  138. }
  139. /**
  140. * Delegate for the ooe_block_info() implementation of hook_block_info().
  141. *
  142. * IMPORTANT: this version uses an OOE IBlockSet with multiple
  143. * IBlock implementations to encapsulate the block info arrays !
  144. *
  145. * Adapted from
  146. * @link https://drupal.org/node/1104464 Declaring the block @endlink
  147. *
  148. * 'You can use a given hook exactly once in any module,
  149. * so this hook must declare all blocks the module needs.'
  150. *
  151. * @return array
  152. * A block info array compatible with hook_block_info().
  153. */
  154. public function block_info() {
  155. $blockSet = $this->factory()->newBlockSet();
  156. $blockSet->addBlock($this->currentPosts()->getBlock());
  157. $blockSet->addBlock($this->demo()->getBlock());
  158. // $blockSet->addBlock($this->demoOfPageArguments()->getBlock());
  159. // $blockSet->addBlock($this->demoOfForms()->getBlock());
  160. return $blockSet->get();
  161. }
  162. /**
  163. * A current posts project.
  164. *
  165. * @var \Drupal\ooe\Demo\Adapted\ICurrentPosts
  166. */
  167. private $currentPosts;
  168. /**
  169. * Lazily creates and configures a @link CurrentPosts @endlink project.
  170. *
  171. * (It does not pass on its own factory as the @link CurrentPosts @endlink
  172. * project configures itself with a
  173. * @link \Drupal\ooe\Demo\Adapted\CurrentPostsFactory @endlink.)
  174. *
  175. * @return \Drupal\ooe\Demo\Adapted\ICurrentPosts
  176. * A lazily created and configured current posts project.
  177. */
  178. protected function currentPosts() {
  179. if (empty($this->currentPosts)) {
  180. $this->currentPosts = new CurrentPosts(
  181. $this->getModule(), $this->accessArguments());
  182. }
  183. return $this->currentPosts;
  184. }
  185. /**
  186. * A @link Demo @endlink page-controlled project.
  187. *
  188. * @var \Drupal\ooe\Project\IControlledProject
  189. */
  190. private $demo;
  191. /**
  192. * Lazily creates and configures a demo page-controlled project.
  193. *
  194. * Uses a new @link Demo @endlink page-controlled project.
  195. *
  196. * Shares the same @link IFactory @endlink.
  197. *
  198. * The controlled page of the @link Demo @endlink serves as
  199. * a welcome page and grouping page for all of the OOE demos:
  200. * @link http://drupal7demo.webel.com.au/ooe @endlink
  201. *
  202. * @return \Drupal\ooe\Project\IControlledProject
  203. * A lazily created and configured @link Demo @endlink project.
  204. */
  205. protected function demo() {
  206. if (empty($this->demo)) {
  207. $this->demo = new Demo(
  208. $this->getModule(),
  209. $this->factory(),
  210. $this->accessArguments(),
  211. $this->regionBartikSidebar1st());
  212. }
  213. return $this->demo;
  214. }
  215. /**
  216. * A project for demonstration of page argument extraction.
  217. *
  218. * @var \Drupal\ooe\Demo\Arguments\IDemoOfPageArguments
  219. */
  220. private $demoOfPageArguments;
  221. /**
  222. * Lazily creates and configures a @link DemoOfPageArguments @endlink.
  223. *
  224. * Shares the same @link IFactory @endlink.
  225. *
  226. * To run it please visit
  227. * @link http://drupal7demo.webel.com.au/ooe/demo_page_arguments @endlink
  228. *
  229. * @return \Drupal\ooe\Demo\Arguments\IDemoOfPageArguments
  230. * A lazily created and configured demo of Drupal page arguments processing.
  231. */
  232. protected function demoOfPageArguments() {
  233. if (empty($this->demoOfPageArguments)) {
  234. $this->demoOfPageArguments = new DemoOfPageArguments(
  235. $this->getModule(), $this->factory(), $this->accessArguments(), $this->regionBartikSidebar1st());
  236. }
  237. return $this->demoOfPageArguments;
  238. }
  239. /**
  240. * A demo of various forms, including Drupal7-style forms
  241. * with handlers in the ooe.module file, and OOE controlled forms
  242. * which encapsulate the form building and handlers in Class methods.
  243. *
  244. * @var \Drupal\ooe\Demo\Form\IDemoOfForms
  245. */
  246. private $demoOfForms;
  247. /**
  248. * Lazily creates a demo of various forms.
  249. *
  250. * Includes Drupal7-style forms
  251. * with handlers in the ooe.module file, and OOE-style controlled forms,
  252. * which encapsulate the form building and handlers in Class methods.
  253. *
  254. * Shares the same @link IFactory @endlink.
  255. *
  256. * @see DemoOfForms
  257. *
  258. * @return \Drupal\ooe\Demo\Form\IDemoOfForms
  259. * A lazily created and configured demo of various forms.
  260. */
  261. protected function demoOfForms() {
  262. if (empty($this->demoOfForms)) {
  263. // Create:
  264. //$this->demoOfForms = $this->factory()->newDemoOfForms();
  265. $this->demoOfForms = new DemoOfForms(
  266. $this->getModule(), $this->factory(), $this->accessArguments(), $this->regionBartikSidebar1st());
  267. // Configure:
  268. // $this->demoOfForms->set?
  269. }
  270. return $this->demoOfForms;
  271. }
  272. /**
  273. * A Bartik theme sidebar region.
  274. *
  275. * @var \Drupal\ooe\Layout\IRegion
  276. */
  277. private $regionBartikSidebar1st;
  278. /**
  279. * Lazily creates a Bartik theme sidebar region.
  280. *
  281. * @return \Drupal\ooe\Layout\IRegion
  282. * A lazily created Bartik them sidebar region.
  283. */
  284. protected function regionBartikSidebar1st() {
  285. if (empty($this->regionBartikSidebar1st)) {
  286. $this->regionBartikSidebar1st = $this->factory()->newRegion(BartikRegions::SIDEBAR_FIRST);
  287. }
  288. return $this->regionBartikSidebar1st;
  289. }
  290. /**
  291. * Delegate for the implementation of hook_block_view($delta).
  292. *
  293. * Delegates to @link IBlockView @endlink implementations
  294. * for construction of the block view arrays ! It leverages
  295. * @end IProject @endlink implementations to provide the
  296. * block views.
  297. *
  298. * @param string $delta
  299. * The block delta identifer.
  300. *
  301. * @return array
  302. * A block view array compatible with hook_block_view().
  303. */
  304. public function block_view($delta = '') {
  305. switch ($delta) {
  306. case $this->currentPosts()->getBlock()->getDelta():
  307. return $this->currentPosts()->getBlockView()->get();
  308. case $this->demo()->getBlock()->getDelta():
  309. return $this->demo()->getBlockView()->get();
  310. case $this->demoOfPageArguments()->getBlock()->getDelta():
  311. return $this->demoOfPageArguments()->getBlockView()->get();
  312. case $this->demoOfForms()->getBlock()->getDelta():
  313. return $this->demoOfForms()->getBlockView()->get();
  314. }
  315. }
  316. /**
  317. * A demo of Drupal menu tabs.
  318. *
  319. * Please note that as a point of demonstration, a concrete implementation
  320. * Class type has been chosen here, rather than an Interface as otherwise
  321. * recomended.
  322. *
  323. * All other examples here use Interface variables:
  324. * @link http://drupal7demo.webel.com.au/node/1804 Design-By-Contract @endlink
  325. *
  326. * @var \Drupal\ooe\Demo\Tabs\DemoOfMenuTabs
  327. */
  328. private $demoOfMenuTabs;
  329. /**
  330. * Lazily creates and configures a @link DemoOfMenuTabs @endlink.
  331. *
  332. * In this example a Class
  333. * without an Interface is used merely as a point of demonstration.
  334. *
  335. * All other examples here use Interface variables:
  336. * @link http://drupal7demo.webel.com.au/node/1804 Design-By-Contract @endlink
  337. *
  338. * To run it visit
  339. * @link http://drupal7demo.webel.com.au/ooe/demo/tabs @endlink
  340. *
  341. * @return \Drupal\ooe\Demo\Tabs\DemoOfMenuTabs
  342. * A lazily created and configured @link DemoOfMenuTabs @endlink.
  343. */
  344. protected function demoOfMenuTabs() {
  345. if (empty($this->demoOfMenuTabs)) {
  346. $this->demoOfMenuTabs = new DemoOfMenuTabs(
  347. $this->getModule(), $this->factory()
  348. );
  349. $this->demoOfMenuTabs->getMenuTabs()->setWeight(-1);
  350. }
  351. return $this->demoOfMenuTabs;
  352. }
  353. /**
  354. * An admin menu item.
  355. *
  356. * @var \Drupal\ooe\Menu\IMenuItem
  357. */
  358. private $menuItemAdmin;
  359. /**
  360. * Lazily creates and configures an admin menu item.
  361. *
  362. * @return \Drupal\ooe\Menu\IMenuItem
  363. * A lazily created admin menu item.
  364. */
  365. protected function menuItemAdmin() {
  366. // @todo Consider using page controlled.
  367. if (empty($this->menuItemAdmin)) {
  368. $this->menuItemAdmin = $this->factory()->newAdminMenuItem(
  369. $this->getModuleDisplayName() .
  370. ": settings", 'admin/config/development/' .
  371. $this->getModule()
  372. // NB: MUST match configure path in module.info !
  373. );
  374. $this->menuItemAdmin->setDescription(
  375. 'Configuration for ' . $this->getModuleDisplayName() . ' module'
  376. );
  377. // 'In Drupal's menu system, 'title' and 'description'
  378. // attributes are automatically translated.
  379. // Throughout Drupal, you are encouraged to use
  380. // the t() function on all string literals.
  381. // This is one place where you must remember not to do that.'
  382. //
  383. // $menuItemAdmin->setTypeNormal(true); // Redundant, default.
  384. }
  385. return $this->menuItemAdmin;
  386. }
  387. /**
  388. * A Drupal access arguments array for those demos with access restrictions.
  389. *
  390. * @var array
  391. */
  392. private $accessArguments;
  393. /**
  394. * Lazily creates a Drupal access arguments array.
  395. *
  396. * For those demos with access restrictions.
  397. *
  398. * @return array
  399. * A Drupal access arguments array for those demos with access restrictions.
  400. */
  401. protected function accessArguments() {
  402. if (empty($this->accessArguments)) {
  403. $this->accessArguments = array('access ' . $this->getModule() . ' content');
  404. }
  405. return $this->accessArguments;
  406. }
  407. /**
  408. * Demo menu item as private var to show more amenable to reverse in UML.
  409. *
  410. * @var \Drupal\ooe\Page\IPageMenuItem
  411. */
  412. private $demoMenuItem;
  413. /**
  414. * Delegate for the ooe_menu() implementation of hook_menu().
  415. *
  416. * Instead of using structured arrays directly, the @link OoeBridge @endlink
  417. * uses implementations of @link IMenuItem @endlink collected in an
  418. * @link IMenuItemSet @endlink, which builds the hook_menu() arrays.
  419. * This makes the menu building very compact, clear, and flexible.
  420. * Contributions to the set of menu items may in turn
  421. * be collected from (for example) multiple
  422. * @link IProject @endlink implementations.
  423. *
  424. * Adapted from the Current Posts Example:
  425. * @link https://drupal.org/node/1111212 Preparing for a module configuration form @endlink
  426. *
  427. * 'hook_menu() implementations return an associative array
  428. * whose keys define paths and whose
  429. * values are an associative array of properties
  430. * for each path. The definition for each path
  431. * may include a page callback function,
  432. * which is invoked when the registered path is requested.
  433. * After we have set up our form in hook_menu,
  434. * we will create the actual form by writing
  435. * the page callback function we define here.'
  436. *
  437. * @see ooe_menu()
  438. *
  439. * @return array
  440. * A Drupal array compatible with hook_menu().
  441. */
  442. public function menu() {
  443. $menuItemSet = $this->factory()->newMenuItemSet();
  444. // Add an admin menu item to the menu item set.
  445. // NOTE: this will ultimately place it with
  446. // an explicit key in the return array.
  447. $menuItemSet->addMenuItem($this->menuItemAdmin());
  448. // Demonstrate the OO adaptation of the 'current_posts' example before
  449. // the other demos since it does not use a page controller,
  450. // and the original is well known.
  451. $menuItemSet->addMenuItem($this->currentPosts()->getMenuItem());
  452. // The welcome page(s) for all OOE demos (uses a page controller).
  453. // As a class var so can demonstrate IDE prompting.
  454. $this->demoMenuItem = $this->demo()->getMenuItem();
  455. $this->demoMenuItem->setExpanded(TRUE);
  456. $menuItemSet->addMenuItem($this->demoMenuItem);
  457. // Here entire sets of menu items are added via IProject implementations.
  458. $menuItemSet->addMenuItems($this->demoOfMenuTabs()->getMenuItems());
  459. $menuItemSet->addMenuItems($this->demoOfPageArguments()->getMenuItems());
  460. $menuItemSet->addMenuItems($this->demoOfForms()->getMenuItems());
  461. // This will build the entire menu array compatible with hook_menu().
  462. return $menuItemSet->get();
  463. }
  464. /**
  465. * Delegate for a page callback for admin settings.
  466. *
  467. * Currently only for Current Posts.
  468. *
  469. * Adapted from the Current Post example:
  470. * @link https://drupal.org/node/1111260 Creating the configuration form @endlink
  471. *
  472. * The matching delegating function was set in the .module file's
  473. * @link ooe_menu @endlink() implementation of hook_menu() via
  474. * @link OoeBridge::menu @endlink().
  475. *
  476. * @param array $form
  477. * A Drupal form array.
  478. * @param array $form_state
  479. * A Drupal form state array.
  480. *
  481. * @return array
  482. * The admin form structure with the Current Posts settings.
  483. */
  484. public function form_admin(array $form, array &$form_state) {
  485. return $this->currentPosts()->getFormAdmin($form, $form_state);
  486. }
  487. /**
  488. * Delegate for validation of the admin settings form.
  489. *
  490. * Currently only uses an @link ICurrentPosts @endlink project.
  491. *
  492. * Adapted from the Current Posts example:
  493. * @link https://drupal.org/node/1111280 Validating the data @endlink
  494. *
  495. * 'Notice the $form_state array variable,
  496. * an argument here and also for our form function.
  497. * $form_state is passed by reference along through
  498. * each stage of form processing to capture information
  499. * about the form's workflow and its current state.
  500. * Incoming $_POST data is first sanitized and checked
  501. * against the structure of the form before being handed off
  502. * to validate and submit handlers.
  503. * The array's values key is the default key for storing this data.
  504. *
  505. * See drupal_build_form() for a list of $form_state keys.'
  506. *
  507. * @param array $form
  508. * A structured array containing the elements and properties of the form.
  509. * @param array $form_state
  510. * An array that stores information about the form's current state
  511. * during processing.
  512. */
  513. public function form_admin_validate(array $form, array &$form_state) {
  514. return $this->currentPosts()->validateAdmin($form, $form_state);
  515. }
  516. /**
  517. * Delegate for the ooe_permission() implementation of hook_permission().
  518. *
  519. * @todo OOE Access array encapsulation.
  520. *
  521. * Adapted from the Current Posts example:
  522. * @link https://drupal.org/node/1118210 Specifying a custom permission for a new page @endlink
  523. *
  524. * @return array
  525. * A Drupal permissions array
  526. */
  527. public function permission() {
  528. return array(
  529. 'access ' . $this->getModule() . ' content' => array(
  530. 'title' => t('Access content for the !module-display-name module',
  531. array('!module-display-name' => $this->getModuleDisplayName())),
  532. // https://www.drupal.org/node/322732
  533. // Dynamic strings with placeholders (recommends prefer hiphens).
  534. ),
  535. );
  536. // Coder: WARNING | Translatable strings must not begin or end
  537. // with white spaces use placeholders with t() for variables.
  538. // Coder: ERROR | Concatenating translatable strings is not allowed,
  539. // use placeholders instead and only one string literal.
  540. }
  541. /**
  542. * Delegate page callback function for Current Posts.
  543. *
  544. * Declared in ooe_menu() via @link OoeBridge::menu @endlink().
  545. *
  546. * Adapted from the Current Posts example:
  547. * @link https://drupal.org/node/1118218 Theming the page @endlink
  548. *
  549. * This OOE version encapsulates the database query and the
  550. * page construction in a @link CurrentPosts @endlink implementation
  551. * of an @link IProject @endlink and a
  552. * @link \Drupal\ooe\Demo\Adapted\CurrentPostsHelper @endlink.
  553. *
  554. * Visit also
  555. * @link https://drupal.org/node/930760 Render Arrays in Drupal 7 @endlink
  556. *
  557. * @return array
  558. * A Drupal render array for displaying the current posts.
  559. */
  560. public function page_current_posts() {
  561. return $this->currentPosts()->getPage();
  562. }
  563. /**
  564. * Encapsulates the name of a delegate page callback.
  565. *
  566. * For use in the .module file.
  567. *
  568. * The reason this is included in this bridge class (rather than say directly
  569. * as a string in the .module file that is a client of this) is that if the
  570. * delegate callback method name changes here then clients will automatically
  571. * catch the change (after the
  572. * @link DRY http://drupal7demo.webel.com.au/node/10 @endlink
  573. * coding principle).
  574. */
  575. const FUNC_DEMO_PAGE_ARGUMENTS_AUTO = 'demo_page_arguments_auto';
  576. /**
  577. * Delegate for a page callback to a demo of auto argument extraction.
  578. *
  579. * It delegates to an @link IDemoOfPageArguments @endlink project,
  580. * which leverages @link DemoArguments @endlink to
  581. * format a standard arguments extraction test page.
  582. *
  583. * From hook_menu():
  584. * 'Note that this automatic passing of optional path arguments
  585. * applies only to page and theme callback functions.'
  586. *
  587. * There is no need here to specify explicit parameters
  588. * matching the original .module file page callback,
  589. * as all arguments will simply be forwarded.
  590. *
  591. * @see func_get_args()
  592. *
  593. * @see call_user_func_array();
  594. *
  595. * @return array
  596. * A render array page with diagnostics on the argument extraction.
  597. */
  598. public function demo_page_arguments_auto() {
  599. return call_user_func_array(
  600. array(
  601. $this->demoOfPageArguments(),
  602. IDemoOfPageArguments::FUNC_PAGE_ARGUMENTS_AUTO,),
  603. func_get_args()
  604. );
  605. }
  606. /**
  607. * Encapsulates the name of a delegate page callback.
  608. *
  609. * For use in the .module file.
  610. *
  611. * The reason this is included in this bridge class (rather than say directly
  612. * as a string in the .module file that is a client of this) is that if the
  613. * delegate callback method name changes here then clients will automatically
  614. * catch the change (after the
  615. * @link DRY http://drupal7demo.webel.com.au/node/10 @endlink coding principle).
  616. */
  617. const FUNC_DEMO_PAGE_ARGUMENTS_FORCED = 'demo_page_arguments_forced';
  618. /**
  619. * Delegate for a page callback to a demo of forced arguments.
  620. *
  621. * It delegates to an @link IDemoOfPageArguments @endlink project,
  622. * which leverages @link DemoArguments @endlink to
  623. * format a standard arguments extraction test page.
  624. *
  625. * Forced arguments are explained at hook_menu().
  626. *
  627. * There is no need here to specify explicit parameters
  628. * matching the .module file page callback
  629. * as all arguments will simply be forwarded.
  630. *
  631. * @see func_get_args()
  632. *
  633. * @see call_user_func_array();
  634. *
  635. * @return array
  636. * A render array with diagnostics on the argument extraction.
  637. */
  638. public function demo_page_arguments_forced() {
  639. return call_user_func_array(
  640. array(
  641. $this->demoOfPageArguments(),
  642. IDemoOfPageArguments::FUNC_PAGE_ARGUMENTS_FORCED,),
  643. func_get_args()
  644. );
  645. }
  646. /**
  647. * Delegate for a Drupal7-style (uncontrolled) form.
  648. *
  649. * Adapted from the main Drupal7 form examples: form_example_tutorial_7();
  650. * Delegates in turn to
  651. * @link IFormManager::getForm @endlink($form, &$form_submit)
  652. * via an @link IDemoOfForms @endlink project.
  653. *
  654. * @see ooo_form_demo
  655. *
  656. * @param array $form
  657. * A Drupal form array.
  658. * @param array $form_submit
  659. * A Drupal form submission array.
  660. *
  661. * @return array
  662. * A Drupal form array.
  663. */
  664. public function form_demo(array $form, array &$form_submit) {
  665. return $this->demoOfForms()->build($form, $form_submit);
  666. }
  667. /**
  668. * Delegate for the (non-controlled) form validation example.
  669. *
  670. * Adapted from form_example_tutorial_6_validate($form, &$form_state);
  671. * delegates in turn to
  672. * @link IFormManager::validate @endlink($form, &$form_state)
  673. * via an @link IDemoOfForms @endlink.
  674. *
  675. * 'Now we add a handler/function to validate the data entered into the ..'
  676. * form.
  677. *
  678. * @see ooe_form_demo_validate($form, &$form_state)
  679. *
  680. * @param array $form
  681. * A Drupal form array.
  682. * @param array $form_state
  683. * A Drupal form state array.
  684. */
  685. public function form_demo_validate(array $form, array &$form_state) {
  686. $this->demoOfForms()->validate($form, $form_state);
  687. }
  688. /**
  689. * Delegate for the (non-controlled) submit function example.
  690. *
  691. * Adapted from form_example_tutorial_7();
  692. * delegates in turn to
  693. * @link IFormManager::submit @endlink ($form, &$form_state)
  694. * via an @link IDemoOfForms @endlink.
  695. *
  696. * 'Adds a submit handler/function to our form to send a successful
  697. * completion message to the screen.'
  698. *
  699. * @see ooe_form_demo_submit($form, &$form_state)
  700. *
  701. * @param array $form
  702. * A Drupal form array.
  703. * @param array $form_state
  704. * A Drupal form state array.
  705. */
  706. public function form_demo_submit(array $form, array &$form_state) {
  707. $this->demoOfForms()->submit($form, $form_state);
  708. }
  709. }

Constants

Namesort descending Description
STEM_DEMO_FORMS

Classes

Namesort descending Description
OoeBridge @author Darren Kelly (Webel IT Australia)