node.info.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * @file
  4. * Provides info about the node entity.
  5. */
  6. /**
  7. * Implements hook_entity_property_info() on top of node module.
  8. *
  9. * @see entity_entity_property_info()
  10. */
  11. function entity_metadata_node_entity_property_info() {
  12. $info = array();
  13. // Add meta-data about the basic node properties.
  14. $properties = &$info['node']['properties'];
  15. $properties['nid'] = array(
  16. 'label' => t("Node ID"),
  17. 'type' => 'integer',
  18. 'description' => t("The unique ID of the node."),
  19. 'schema field' => 'nid',
  20. );
  21. $properties['vid'] = array(
  22. 'label' => t("Revision ID"),
  23. 'type' => 'integer',
  24. 'description' => t("The unique ID of the node's revision."),
  25. 'schema field' => 'vid',
  26. );
  27. $properties['is_new'] = array(
  28. 'label' => t("Is new"),
  29. 'type' => 'boolean',
  30. 'description' => t("Whether the node is new and not saved to the database yet."),
  31. 'getter callback' => 'entity_metadata_node_get_properties',
  32. );
  33. $properties['type'] = array(
  34. 'label' => t("Content type"),
  35. 'type' => 'token',
  36. 'description' => t("The type of the node."),
  37. 'setter callback' => 'entity_property_verbatim_set',
  38. 'setter permission' => 'administer nodes',
  39. 'options list' => 'node_type_get_names',
  40. 'required' => TRUE,
  41. 'schema field' => 'type',
  42. );
  43. $properties['title'] = array(
  44. 'label' => t("Title"),
  45. 'description' => t("The title of the node."),
  46. 'setter callback' => 'entity_property_verbatim_set',
  47. 'schema field' => 'title',
  48. 'required' => TRUE,
  49. );
  50. $properties['language'] = array(
  51. 'label' => t("Language"),
  52. 'type' => 'token',
  53. 'description' => t("The language the node is written in."),
  54. 'setter callback' => 'entity_property_verbatim_set',
  55. 'options list' => 'entity_metadata_language_list',
  56. 'schema field' => 'language',
  57. 'setter permission' => 'administer nodes',
  58. );
  59. $properties['url'] = array(
  60. 'label' => t("URL"),
  61. 'description' => t("The URL of the node."),
  62. 'getter callback' => 'entity_metadata_entity_get_properties',
  63. 'type' => 'uri',
  64. 'computed' => TRUE,
  65. );
  66. $properties['edit_url'] = array(
  67. 'label' => t("Edit URL"),
  68. 'description' => t("The URL of the node's edit page."),
  69. 'getter callback' => 'entity_metadata_node_get_properties',
  70. 'type' => 'uri',
  71. 'computed' => TRUE,
  72. );
  73. $properties['status'] = array(
  74. 'label' => t("Status"),
  75. 'description' => t("Whether the node is published or unpublished."),
  76. // Although the status is expected to be boolean, its schema suggests
  77. // it is an integer, so we follow the schema definition.
  78. 'type' => 'integer',
  79. 'options list' => 'entity_metadata_status_options_list',
  80. 'setter callback' => 'entity_property_verbatim_set',
  81. 'setter permission' => 'administer nodes',
  82. 'schema field' => 'status',
  83. );
  84. $properties['promote'] = array(
  85. 'label' => t("Promoted to frontpage"),
  86. 'description' => t("Whether the node is promoted to the frontpage."),
  87. 'setter callback' => 'entity_property_verbatim_set',
  88. 'setter permission' => 'administer nodes',
  89. 'schema field' => 'promote',
  90. 'type' => 'boolean',
  91. );
  92. $properties['sticky'] = array(
  93. 'label' => t("Sticky in lists"),
  94. 'description' => t("Whether the node is displayed at the top of lists in which it appears."),
  95. 'setter callback' => 'entity_property_verbatim_set',
  96. 'setter permission' => 'administer nodes',
  97. 'schema field' => 'sticky',
  98. 'type' => 'boolean',
  99. );
  100. $properties['created'] = array(
  101. 'label' => t("Date created"),
  102. 'type' => 'date',
  103. 'description' => t("The date the node was posted."),
  104. 'setter callback' => 'entity_property_verbatim_set',
  105. 'setter permission' => 'administer nodes',
  106. 'schema field' => 'created',
  107. );
  108. $properties['changed'] = array(
  109. 'label' => t("Date changed"),
  110. 'type' => 'date',
  111. 'schema field' => 'changed',
  112. 'description' => t("The date the node was most recently updated."),
  113. );
  114. $properties['author'] = array(
  115. 'label' => t("Author"),
  116. 'type' => 'user',
  117. 'description' => t("The author of the node."),
  118. 'getter callback' => 'entity_metadata_node_get_properties',
  119. 'setter callback' => 'entity_property_verbatim_set',
  120. 'setter permission' => 'administer nodes',
  121. 'required' => TRUE,
  122. 'schema field' => 'uid',
  123. );
  124. $properties['source'] = array(
  125. 'label' => t("Translation source node"),
  126. 'type' => 'node',
  127. 'description' => t("The original-language version of this node, if one exists."),
  128. 'getter callback' => 'entity_metadata_node_get_properties',
  129. );
  130. $properties['log'] = array(
  131. 'label' => t("Revision log message"),
  132. 'type' => 'text',
  133. 'description' => t("In case a new revision is to be saved, the log entry explaining the changes for this version."),
  134. 'setter callback' => 'entity_property_verbatim_set',
  135. 'access callback' => 'entity_metadata_node_revision_access',
  136. );
  137. $properties['revision'] = array(
  138. 'label' => t("Creates revision"),
  139. 'type' => 'boolean',
  140. 'description' => t("Whether saving this node creates a new revision."),
  141. 'setter callback' => 'entity_property_verbatim_set',
  142. 'access callback' => 'entity_metadata_node_revision_access',
  143. );
  144. return $info;
  145. }
  146. /**
  147. * Implements hook_entity_property_info_alter() on top of node module.
  148. * @see entity_metadata_entity_property_info_alter()
  149. */
  150. function entity_metadata_node_entity_property_info_alter(&$info) {
  151. // Move the body property to the node by default, as its usually there this
  152. // makes dealing with it more convenient.
  153. $info['node']['properties']['body'] = array(
  154. 'type' => 'text_formatted',
  155. 'label' => t('The main body text'),
  156. 'getter callback' => 'entity_metadata_field_verbatim_get',
  157. 'setter callback' => 'entity_metadata_field_verbatim_set',
  158. 'property info' => entity_property_text_formatted_info(),
  159. 'auto creation' => 'entity_property_create_array',
  160. 'field' => TRUE,
  161. );
  162. // Make it a list if cardinality is not 1.
  163. $field_body = field_info_field('body');
  164. if (isset($field_body) && $field_body['cardinality'] != 1) {
  165. $info['node']['properties']['body']['type'] = 'list<text_formatted>';
  166. }
  167. }