rdf_example.module 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @file
  4. * This is an example outlining how a module can be used to define RDF mappings.
  5. * We define mappings for a node type defined in this module. We also customize
  6. * mappings for a node type that is defined in another module, node_example.
  7. */
  8. /**
  9. * @defgroup rdf_example Example: RDF
  10. * @ingroup examples
  11. * @{
  12. * Example RDF Mapping.
  13. */
  14. /**
  15. * Implements hook_rdf_mapping().
  16. *
  17. * This hook should only be used to define the RDF mapping for an entity or
  18. * bundle that has been defined by this module. On installation, this mapping
  19. * will be saved to the database. To alter anything in this mapping after module
  20. * installation (or to alter bundles defined in another module), the RDF CRUD
  21. * functions should be used, as shown below.
  22. */
  23. function rdf_example_rdf_mapping() {
  24. return array(
  25. array(
  26. 'type' => 'node',
  27. 'bundle' => 'recipe',
  28. 'mapping' => array(
  29. 'rdftype' => array('v:Recipe'),
  30. // We don't use the default bundle mapping for title. Instead, we add
  31. // the v:name property. We still want to use dc:title as well, though,
  32. // so we include it in the array.
  33. 'title' => array(
  34. 'predicates' => array('dc:title', 'v:name'),
  35. ),
  36. 'recipe_summary' => array(
  37. 'predicates' => array('v:summary'),
  38. ),
  39. // The photo URI isn't a string but instead points to a resource, so we
  40. // indicate that the attribute type is rel. If type isn't specified, it
  41. // defaults to property, which is used for string values.
  42. 'recipe_photo' => array(
  43. 'predicates' => array('v:photo'),
  44. 'type' => 'rel',
  45. ),
  46. ),
  47. ),
  48. );
  49. }
  50. /**
  51. * Implements hook_rdf_namespaces().
  52. *
  53. * This hook should be used to define any prefixes used by this module that are
  54. * not already defined in core by rdf_rdf_namespaces.
  55. *
  56. * @see hook_rdf_namespaces()
  57. */
  58. function rdf_example_rdf_namespaces() {
  59. return array(
  60. // Google's namespace for their custom vocabularies.
  61. 'v' => 'http://rdf.data-vocabulary.org/#',
  62. );
  63. }
  64. /**
  65. * Implements hook_help().
  66. */
  67. function rdf_example_help($path, $arg) {
  68. switch ($path) {
  69. case 'examples/rdf_example':
  70. return "<p>" . t(
  71. "The RDF Example module provides RDF mappings for a custom node type and
  72. alters another node type's RDF mapping.
  73. You can check your RDF using a <a href='!parser'>parser</a> by copying
  74. and pasting your HTML source code into the box. For clearest results,
  75. use Turtle as your output format.",
  76. array('!parser' => url('http://www.w3.org/2007/08/pyRdfa/#distill_by_input'))
  77. ) . "</p>";
  78. }
  79. }
  80. /**
  81. * @} End of "defgroup rdf_example".
  82. */