ds.ds_fields_info.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <?php
  2. /**
  3. * @file
  4. * Display Suite fields.
  5. */
  6. /**
  7. * Implements hook_ds_fields_info().
  8. */
  9. function ds_ds_fields_info($entity_type) {
  10. /* --------------------------------------------------------------
  11. Custom fields.
  12. -------------------------------------------------------------- */
  13. ctools_include('export');
  14. $custom_fields = ctools_export_crud_load_all('ds_fields');
  15. foreach ($custom_fields as $key => $field) {
  16. if (isset($field->entities[$entity_type])) {
  17. $fields[$entity_type][$key] = array(
  18. 'title' => $field->label,
  19. 'field_type' => $field->field_type,
  20. 'properties' => $field->properties,
  21. );
  22. if (!empty($field->ui_limit)) {
  23. $lines = explode("\n", $field->ui_limit);
  24. $fields[$entity_type][$key]['ui_limit'] = $lines;
  25. }
  26. }
  27. }
  28. /* --------------------------------------------------------------
  29. General node fields.
  30. -------------------------------------------------------------- */
  31. // Node title.
  32. $fields['node']['title'] = array(
  33. 'title' => t('Title'),
  34. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  35. 'function' => 'ds_render_field',
  36. 'properties' => array(
  37. 'entity_render_key' => 'title',
  38. 'settings' => array(
  39. 'link' => array('type' => 'select', 'options' => array('no', 'yes')),
  40. 'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
  41. 'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
  42. ),
  43. 'default' => array('wrapper' => 'h2', 'link' => 0, 'class' => ''),
  44. )
  45. );
  46. // Links.
  47. $fields['node']['links'] = array(
  48. 'title' => t('Links'),
  49. 'field_type' => DS_FIELD_TYPE_IGNORE,
  50. );
  51. // Comments.
  52. if (module_exists('comment')) {
  53. $fields['node']['comments'] = array(
  54. 'title' => t('Comments'),
  55. 'field_type' => DS_FIELD_TYPE_IGNORE,
  56. 'ui_limit' => array(
  57. '*|full', '*|default',
  58. ),
  59. );
  60. }
  61. // Node link.
  62. $fields['node']['node_link'] = array(
  63. 'title' => t('Read more'),
  64. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  65. 'function' => 'ds_render_field',
  66. 'properties' => array(
  67. 'settings' => array(
  68. 'link text' => array('type' => 'textfield'),
  69. 'link class' => array('type' => 'textfield', 'description' => t('Put a class on the link. Eg: btn btn-default')),
  70. 'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
  71. 'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
  72. ),
  73. 'default' => array('link text' => 'Read more', 'link class' => '', 'wrapper' => '', 'class' => '', 'link' => 1),
  74. )
  75. );
  76. // Author.
  77. $fields['node']['author'] = array(
  78. 'title' => t('Author'),
  79. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  80. 'function' => 'ds_render_author_field',
  81. 'properties' => array(
  82. 'formatters' => array(
  83. 'author' => t('Author'),
  84. 'author_linked' => t('Author linked to profile')
  85. ),
  86. ),
  87. );
  88. // Created time.
  89. $format_types = system_get_date_types();
  90. $date_formatters = array();
  91. foreach ($format_types as $formatter) {
  92. $date_formatters['ds_post_date_' . $formatter['type']] = t($formatter['title']);
  93. }
  94. $fields['node']['post_date'] = array(
  95. 'title' => t('Post date'),
  96. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  97. 'function' => 'ds_render_date_field',
  98. 'properties' => array(
  99. 'formatters' => $date_formatters,
  100. 'entity_render_key' => 'created',
  101. ),
  102. );
  103. // Updated time.
  104. $fields['node']['changed_date'] = array(
  105. 'title' => t('Last modified'),
  106. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  107. 'function' => 'ds_render_date_field',
  108. 'properties' => array(
  109. 'formatters' => $date_formatters,
  110. 'entity_render_key' => 'changed',
  111. ),
  112. );
  113. // "Submitted by"-line. Skip this if the "Submitted By" module is used.
  114. if (!module_exists('submitted_by')) {
  115. $date_formatters = array('ds_time_ago' => t('Time ago')) + $date_formatters;
  116. $fields['node']['submitted_by'] = array(
  117. 'title' => t('Submitted by'),
  118. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  119. 'function' => 'ds_render_submitted_by',
  120. 'properties' => array(
  121. 'formatters' => $date_formatters,
  122. ),
  123. );
  124. }
  125. // User picture
  126. if (variable_get('user_pictures', 0)) {
  127. $key = 'user_picture';
  128. $type = DS_FIELD_TYPE_IGNORE;
  129. $picture_formatters = array();
  130. if (module_exists('image')) {
  131. $key = 'ds_user_picture';
  132. $type = DS_FIELD_TYPE_FUNCTION;
  133. $styles = image_styles();
  134. foreach ($styles as $formatter) {
  135. $picture_formatters['ds_picture_' . $formatter['name']] = drupal_ucfirst(str_replace('_', ' ', $formatter['name']));
  136. }
  137. }
  138. else {
  139. $picture_formatters['default'] = t('Default');
  140. }
  141. $fields['node'][$key] = array(
  142. 'title' => t('User picture'),
  143. 'field_type' => $type,
  144. 'properties' => array(
  145. 'formatters' => $picture_formatters,
  146. ),
  147. );
  148. if ($type == DS_FIELD_TYPE_FUNCTION) {
  149. $fields['node'][$key]['function'] = 'ds_render_user_picture';
  150. }
  151. }
  152. /* --------------------------------------------------------------
  153. Book support.
  154. -------------------------------------------------------------- */
  155. if (module_exists('book')) {
  156. $ui_limit = array();
  157. $types = variable_get('book_allowed_types', array('book'));
  158. foreach ($types as $type) {
  159. $ui_limit[] = $type . '|full';
  160. }
  161. if (!empty($ui_limit)) {
  162. $fields['node']['book_navigation'] = array(
  163. 'title' => t('Book navigation'),
  164. 'field_type' => DS_FIELD_TYPE_IGNORE,
  165. 'ui_limit' => $ui_limit,
  166. );
  167. }
  168. }
  169. /* --------------------------------------------------------------
  170. Comment support.
  171. -------------------------------------------------------------- */
  172. if (module_exists('comment')) {
  173. // Comment Links.
  174. $fields['comment']['links'] = array(
  175. 'title' => t('Links'),
  176. 'field_type' => DS_FIELD_TYPE_IGNORE,
  177. );
  178. // Created time.
  179. $format_types = system_get_date_types();
  180. $date_formatters = array();
  181. foreach ($format_types as $formatter) {
  182. $date_formatters['ds_post_date_' . $formatter['type']] = t($formatter['title']);
  183. }
  184. $fields['comment']['post_date'] = array(
  185. 'title' => t('Post date'),
  186. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  187. 'function' => 'ds_render_date_field',
  188. 'properties' => array(
  189. 'formatters' => $date_formatters,
  190. 'entity_render_key' => 'created',
  191. ),
  192. );
  193. // Permalink.
  194. $fields['comment']['permalink'] = array(
  195. 'title' => t('Permalink'),
  196. 'field_type' => DS_FIELD_TYPE_PREPROCESS,
  197. );
  198. // Submitted.
  199. $fields['comment']['submitted'] = array(
  200. 'title' => t('Submitted'),
  201. 'field_type' => DS_FIELD_TYPE_PREPROCESS,
  202. );
  203. // Title.
  204. $fields['comment']['title'] = array(
  205. 'title' => t('Title'),
  206. 'field_type' => DS_FIELD_TYPE_PREPROCESS,
  207. );
  208. // Author.
  209. $fields['comment']['author'] = array(
  210. 'title' => t('Author'),
  211. 'field_type' => DS_FIELD_TYPE_PREPROCESS,
  212. );
  213. // User signature.
  214. if (variable_get('user_signatures', 0)) {
  215. $fields['comment']['signature'] = array(
  216. 'title' => t('User signature'),
  217. 'field_type' => DS_FIELD_TYPE_PREPROCESS,
  218. );
  219. }
  220. // User picture
  221. if (variable_get('user_pictures', 0)) {
  222. $key = 'picture';
  223. $type = DS_FIELD_TYPE_PREPROCESS;
  224. $picture_formatters = array();
  225. if (module_exists('image')) {
  226. $key = 'ds_user_picture';
  227. $type = DS_FIELD_TYPE_FUNCTION;
  228. $styles = image_styles();
  229. foreach ($styles as $formatter) {
  230. $picture_formatters['ds_picture_' . $formatter['name']] = drupal_ucfirst(str_replace('_', ' ', $formatter['name']));
  231. }
  232. }
  233. else {
  234. $picture_formatters['default'] = t('Default');
  235. }
  236. $fields['comment'][$key] = array(
  237. 'title' => t('User picture'),
  238. 'field_type' => $type,
  239. 'properties' => array(
  240. 'formatters' => $picture_formatters,
  241. ),
  242. );
  243. if ($type == DS_FIELD_TYPE_FUNCTION) {
  244. $fields['comment'][$key]['function'] = 'ds_render_user_picture';
  245. }
  246. }
  247. }
  248. /* --------------------------------------------------------------
  249. User support.
  250. -------------------------------------------------------------- */
  251. // Username
  252. $fields['user']['name'] = array(
  253. 'title' => t('Username'),
  254. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  255. 'function' => 'ds_render_field',
  256. 'properties' => array(
  257. 'entity_render_key' => 'name',
  258. 'settings' => array(
  259. 'link' => array('type' => 'select', 'options' => array('no', 'yes')),
  260. 'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
  261. 'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
  262. ),
  263. 'default' => array('wrapper' => 'h2', 'link' => 0, 'class' => ''),
  264. )
  265. );
  266. // User signature
  267. if (variable_get('user_signatures', 0)) {
  268. $fields['user']['user_signature'] = array(
  269. 'title' => t('User signature'),
  270. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  271. 'function' => 'ds_render_markup',
  272. 'properties' => array(
  273. 'key' => 'signature',
  274. 'format' => 'signature_format',
  275. ),
  276. );
  277. }
  278. // User picture
  279. if (variable_get('user_pictures', 0)) {
  280. $key = 'user_picture';
  281. $type = DS_FIELD_TYPE_IGNORE;
  282. $picture_formatters = array();
  283. if (module_exists('image')) {
  284. $key = 'ds_user_picture';
  285. $type = DS_FIELD_TYPE_FUNCTION;
  286. $styles = image_styles();
  287. foreach ($styles as $formatter) {
  288. $picture_formatters['ds_picture_' . $formatter['name']] = drupal_ucfirst(str_replace('_', ' ', $formatter['name']));
  289. }
  290. }
  291. else {
  292. $picture_formatters['default'] = t('Default');
  293. }
  294. $fields['user'][$key] = array(
  295. 'title' => t('User picture'),
  296. 'field_type' => $type,
  297. 'properties' => array(
  298. 'formatters' => $picture_formatters,
  299. ),
  300. );
  301. if ($type == DS_FIELD_TYPE_FUNCTION) {
  302. $fields['user'][$key]['function'] = 'ds_render_user_picture';
  303. }
  304. }
  305. /* --------------------------------------------------------------
  306. Taxonomy support.
  307. -------------------------------------------------------------- */
  308. if (module_exists('taxonomy')) {
  309. // Taxonomy term title.
  310. $fields['taxonomy_term']['title'] = array(
  311. 'title' => t('Title'),
  312. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  313. 'function' => 'ds_render_field',
  314. 'properties' => array(
  315. 'entity_render_key' => 'name',
  316. 'settings' => array(
  317. 'link' => array('type' => 'select', 'options' => array('no', 'yes')),
  318. 'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
  319. 'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
  320. ),
  321. 'default' => array('wrapper' => 'h2', 'link' => 0, 'class' => ''),
  322. )
  323. );
  324. // Taxonomy term link.
  325. $fields['taxonomy_term']['more_link'] = array(
  326. 'title' => t('Read more'),
  327. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  328. 'function' => 'ds_render_field',
  329. 'properties' => array(
  330. 'settings' => array(
  331. 'link text' => array('type' => 'textfield'),
  332. 'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
  333. 'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
  334. ),
  335. 'default' => array('link text' => 'Read more', 'wrapper' => '', 'class' => '', 'link' => 1),
  336. )
  337. );
  338. }
  339. // Support for ECK Entity title
  340. if (module_exists('eck')) {
  341. $entity_info = entity_get_info($entity_type);
  342. if (isset($entity_info['module']) && $entity_info['module'] == 'eck') {
  343. $fields[$entity_type]['title'] = array(
  344. 'title' => t('Title'),
  345. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  346. 'function' => 'ds_render_field',
  347. 'properties' => array(
  348. 'entity_render_key' => 'title',
  349. 'settings' => array(
  350. 'link' => array('type' => 'select', 'options' => array('no', 'yes')),
  351. 'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
  352. 'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
  353. ),
  354. 'default' => array('wrapper' => 'h2', 'link' => 0, 'class' => ''),
  355. )
  356. );
  357. }
  358. }
  359. // Support for fieldable panels panes.
  360. if (module_exists('fieldable_panels_panes')) {
  361. $fields['fieldable_panels_pane']['title_ds'] = array(
  362. 'title' => t('Display Suite Title'),
  363. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  364. 'function' => 'ds_render_field',
  365. 'properties' => array(
  366. 'entity_render_key' => 'title',
  367. 'settings' => array(
  368. 'link' => array('type' => 'select', 'options' => array('no', 'yes')),
  369. 'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
  370. 'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
  371. ),
  372. 'default' => array('wrapper' => 'h2', 'link' => 0, 'class' => ''),
  373. )
  374. );
  375. }
  376. if (isset($fields[$entity_type])) {
  377. return array($entity_type => $fields[$entity_type]);
  378. }
  379. return;
  380. }