{"action":"opened","issue":{"url":"https://api.github.com/repos/backdrop-ops/api.backdropcms.org/issues/37","repository_url":"https://api.github.com/repos/backdrop-ops/api.backdropcms.org","labels_url":"https://api.github.com/repos/backdrop-ops/api.backdropcms.org/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/backdrop-ops/api.backdropcms.org/issues/37/comments","events_url":"https://api.github.com/repos/backdrop-ops/api.backdropcms.org/issues/37/events","html_url":"https://github.com/backdrop-ops/api.backdropcms.org/issues/37","id":187901251,"number":37,"title":"Proposed example hook_menu for https://api.backdropcms.org/modules","user":{"login":"serundeputy","id":6763671,"avatar_url":"https://avatars.githubusercontent.com/u/6763671?v=3","gravatar_id":"","url":"https://api.github.com/users/serundeputy","html_url":"https://github.com/serundeputy","followers_url":"https://api.github.com/users/serundeputy/followers","following_url":"https://api.github.com/users/serundeputy/following{/other_user}","gists_url":"https://api.github.com/users/serundeputy/gists{/gist_id}","starred_url":"https://api.github.com/users/serundeputy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serundeputy/subscriptions","organizations_url":"https://api.github.com/users/serundeputy/orgs","repos_url":"https://api.github.com/users/serundeputy/repos","events_url":"https://api.github.com/users/serundeputy/events{/privacy}","received_events_url":"https://api.github.com/users/serundeputy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-08T04:48:39Z","updated_at":"2016-11-08T04:48:39Z","closed_at":null,"body":"On https://api.backdropcms.org/modules for the `example hook` TBD section here is a first pass at an example `hook_menu`\r\n\r\n### Some Examples of hooks\r\n\r\n* `hook_menu` allows you to define a menu item that Backdrop will respond to at a path\r\n  * If you are writing a module named `my_module` then you can define some path(s) where the module will provide content, user facing forms, or admin config forms with `hook_menu`. Here is an example where we want to consume a feed from an external data source:\r\n```php\r\n/**\r\n * Implements hook_menu().\r\n */\r\nfunction my_module_menu() {\r\n  $items['my-path'] = array(\r\n    'title' => 'My Feed',\r\n    'description' => 'Get data from another website feed, parse it and display it on our Backdrop site.',\r\n    'page callback' => 'my_module_get_data',\r\n    'access callback' => TRUE,\r\n  );\r\n  return $items;\r\n}\r\n```\r\n\r\nLet's break down the elements here:\r\n\r\n*     `'title' => 'My Feed',` \r\n  * Sets the title on the page, replace `My Feed` with the title you want for your page.\r\n* `'description' => 'Get data from another website feed, parse it and display it on our Backdrop site.',`\r\n  * Describe the page you are going to display to users.\r\n* ` 'page callback' => 'my_module_get_data',`\r\n  * This tells backdrop about the callback function to use for the page.  When Backdrop receives a request in this case at `example.com/my-path` the hook `my_module_menu` will tell that request to use the callback function in this case `my_module_get_data`.\r\n  * You would then define the function `my_module_get_data` later in the `my_module.module` file.  That might look something like this:\r\n\r\n```php\r\n/**\r\n * Callback function for the path my-path.\r\n * Process the data from the feed and define output markup.\r\n * \r\n * return string $markup\r\n *   The $markup to return for the page request to /my-path\r\n */\r\nfunction my_module_get_data() {\r\n  // Make request to external data feed, parse, and store in $markup variable.  \r\n\r\n  return $markup;\r\n}\r\n```\r\n\r\n* `'access callback' => TRUE,`\r\n  * The access callback to use for this path.  In this case `TRUE` indicates that anyone including anonymous users can see the content at this path."}}
{"actor":{"display_login":"serundeputy"}}