entity_field.inc

  1. cis7 sites/all/modules/ulmus/ctools/plugins/content_types/entity_context/entity_field.inc
  2. cle7 sites/all/modules/ulmus/ctools/plugins/content_types/entity_context/entity_field.inc
  3. ecd7 sites/all/modules/ulmus/ctools/plugins/content_types/entity_context/entity_field.inc
  4. elmsmedia7 sites/all/modules/ulmus/ctools/plugins/content_types/entity_context/entity_field.inc
  5. harmony7 sites/all/modules/ulmus/ctools/plugins/content_types/entity_context/entity_field.inc
  6. icor7 sites/all/modules/ulmus/ctools/plugins/content_types/entity_context/entity_field.inc
  7. meedjum_blog7 sites/all/modules/ulmus/ctools/plugins/content_types/entity_context/entity_field.inc
  8. mooc7 sites/all/modules/ulmus/ctools/plugins/content_types/entity_context/entity_field.inc

Handle rendering entity fields as panes.

Functions

File

sites/all/modules/ulmus/ctools/plugins/content_types/entity_context/entity_field.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Handle rendering entity fields as panes.
  5. */
  6. $plugin = array(
  7. 'title' => t('Entity field'),
  8. 'defaults' => array('label' => 'title', 'formatter' => '', 'delta_limit' => 0, 'delta_offset' => '0', 'delta_reversed' => FALSE),
  9. 'content type' => 'ctools_entity_field_content_type_content_type',
  10. );
  11. /**
  12. * Just one subtype.
  13. *
  14. * Ordinarily this function is meant to get just one subtype. However, we are
  15. * using it to deal with the fact that we have changed the subtype names. This
  16. * lets us translate the name properly.
  17. */
  18. function ctools_entity_field_content_type_content_type($subtype) {
  19. $types = ctools_entity_field_content_type_content_types();
  20. if (isset($types[$subtype])) {
  21. return $types[$subtype];
  22. }
  23. }
  24. /**
  25. * Return all field content types available.
  26. */
  27. function ctools_entity_field_content_type_content_types() {
  28. $types = &drupal_static(__FUNCTION__, array());
  29. if (!empty($types)) {
  30. return $types;
  31. }
  32. // This will hold all the individual field content types.
  33. $context_types = array();
  34. $entities = entity_get_info();
  35. $description = t('Field on the referenced entity.');
  36. $styles = t('Formatter Styles');
  37. $categories = array();
  38. foreach ($entities as $entity_type => $entity) {
  39. $category = t(ucfirst($entity_type));
  40. $categories[$entity_type] = $category;
  41. foreach ($entity['bundles'] as $type => $bundle) {
  42. foreach (field_info_instances($entity_type, $type) as $field_name => $field) {
  43. if (!isset($types[$entity_type . ':' . $field_name])) {
  44. $label = t($field['label']);
  45. $types[$entity_type . ':' . $field_name] = array(
  46. 'category' => $category,
  47. 'icon' => 'icon_field.png',
  48. 'title' => t('Field: @widget_label (@field_name)', array(
  49. '@widget_label' => $label,
  50. '@field_name' => $field_name,
  51. )),
  52. 'description' => $description,
  53. 'edit form' => array(
  54. 'ctools_entity_field_content_type_formatter_options' => array(
  55. 'default' => TRUE,
  56. 'title' => t('Formatter options for: @widget_label (@field_name)', array(
  57. '@widget_label' => $label,
  58. '@field_name' => $field_name,
  59. )),
  60. ),
  61. 'ctools_entity_field_content_type_formatter_styles' => $styles,
  62. ),
  63. );
  64. }
  65. $context_types[$entity_type . ':' . $field_name]['types'][$type] = $bundle['label'];
  66. }
  67. }
  68. }
  69. // Create the required context for each field related to the bundle types.
  70. foreach ($types as $key => $field_content_type) {
  71. list($entity_type, $field_name) = explode(':', $key, 2);
  72. $types[$key]['required context'] = new ctools_context_required($categories[$entity_type], $entity_type, array(
  73. 'type' => array_keys($context_types[$key]['types']),
  74. ));
  75. unset($context_types[$key]['types']);
  76. }
  77. return $types;
  78. }
  79. /**
  80. * Render the custom content type.
  81. */
  82. function ctools_entity_field_content_type_render($subtype, $conf, $panel_args, $context) {
  83. if (empty($context) || empty($context->data)) {
  84. return;
  85. }
  86. // Get a shortcut to the entity.
  87. $entity = $context->data;
  88. list($entity_type, $field_name) = explode(':', $subtype, 2);
  89. // Load the entity type's information for this field.
  90. $ids = entity_extract_ids($entity_type, $entity);
  91. $field = field_info_instance($entity_type, $field_name, $ids[2]);
  92. // Do not render if the entity type does not have this field.
  93. if (empty($field)) {
  94. return;
  95. }
  96. $language = field_language($entity_type, $entity, $field_name);
  97. if (empty($conf['label']) || $conf['label'] == 'title') {
  98. $label = 'hidden';
  99. $conf['label'] = 'title';
  100. }
  101. else {
  102. $label = $conf['label'];
  103. }
  104. $field_settings = array(
  105. 'label' => $label,
  106. 'type' => $conf['formatter'],
  107. );
  108. // Get the field output, and the title.
  109. if (!empty($conf['formatter_settings'])) {
  110. $field_settings['settings'] = $conf['formatter_settings'];
  111. }
  112. $all_values = field_get_items($entity_type, $entity, $field_name, $language);
  113. if (!is_array($all_values)) {
  114. $all_values = array();
  115. }
  116. // Reverse values.
  117. if (isset($conf['delta_reversed']) && $conf['delta_reversed']) {
  118. $all_values = array_reverse($all_values);
  119. }
  120. if (isset($conf['delta_limit'])) {
  121. $delta_limit = $conf['delta_limit'];
  122. $offset = intval($conf['delta_offset']);
  123. $total = count($all_values);
  124. if ($delta_limit == 0) {
  125. $delta_limit = $total - $offset;
  126. }
  127. $new_values = array();
  128. for ($i = 0; $i < $delta_limit; $i++) {
  129. $new_delta = $offset + $i;
  130. if (isset($all_values[$new_delta])) {
  131. $new_values[] = $all_values[$new_delta];
  132. }
  133. }
  134. $all_values = $new_values;
  135. }
  136. $clone = clone $entity;
  137. $clone->{$field_name}[$language] = $all_values;
  138. $field_output = field_view_field($entity_type, $clone, $field_name, $field_settings, $language);
  139. if (!empty($field_output) && !empty($conf['override_title'])) {
  140. $field_output['#title'] = filter_xss_admin($conf['override_title_text']);
  141. }
  142. // Build the content type block.
  143. $block = new stdClass();
  144. $block->module = 'entity_field';
  145. if ($conf['label'] == 'title' && isset($field_output['#title'])) {
  146. $block->title = $field_output['#title'];
  147. }
  148. $block->content = $field_output;
  149. $block->delta = $ids[0];
  150. return $block;
  151. }
  152. /**
  153. * Returns an edit form for custom type settings.
  154. */
  155. function ctools_entity_field_content_type_formatter_options($form, &$form_state) {
  156. if (empty($form_state['conf']['formatter_settings'])) {
  157. $form_state['conf']['formatter_settings'] = array();
  158. }
  159. $conf = $form_state['conf'];
  160. $subtype = $form_state['subtype_name'];
  161. list($entity_type, $field_name) = explode(':', $subtype, 2);
  162. $field = field_info_field($field_name);
  163. module_load_include('inc', 'field_ui', 'field_ui.admin');
  164. $formatter_options = field_ui_formatter_options($field['type']);
  165. $field_label_options = array(
  166. 'title' => t('Pane title'),
  167. 'above' => t('Above'),
  168. 'inline' => t('Inline'),
  169. 'hidden' => t('Hidden'),
  170. );
  171. $form['label'] = array(
  172. '#type' => 'select',
  173. '#title' => t('Label'),
  174. '#options' => $field_label_options,
  175. '#default_value' => $conf['label'],
  176. );
  177. $form['formatter'] = array(
  178. '#type' => 'select',
  179. '#title' => t('Select a formatter'),
  180. '#options' => $formatter_options,
  181. '#default_value' => $conf['formatter'],
  182. );
  183. return $form;
  184. }
  185. function ctools_entity_field_content_type_formatter_options_submit($form, &$form_state) {
  186. $form_state['conf']['formatter'] = $form_state['values']['formatter'];
  187. $form_state['conf']['label'] = $form_state['values']['label'];
  188. }
  189. function ctools_entity_field_content_type_formatter_styles($form, &$form_state) {
  190. if (!$form_state['conf']['formatter_settings']) {
  191. $form_state['conf']['formatter_settings'] = array();
  192. }
  193. $conf = $form_state['conf'];
  194. $subtype = $form_state['subtype_name'];
  195. list($entity_type, $field_name) = explode(':', $subtype, 2);
  196. $field = field_info_field($field_name);
  197. ctools_form_include($form_state, 'field_ui.admin', 'field_ui', '');
  198. ctools_form_include($form_state, 'fields');
  199. $form['ctools_field_list'] = array(
  200. '#type' => 'value',
  201. '#value' => array(),
  202. );
  203. ctools_fields_get_field_formatter_settings_form($field, $conf['formatter'], $form, $form_state);
  204. return $form;
  205. }
  206. function ctools_entity_field_content_type_formatter_styles_submit($form, &$form_state) {
  207. $fields = $form_state['values']['ctools_field_list'];
  208. $formatter_info = ctools_fields_get_field_formatter_info($fields);
  209. foreach ($formatter_info as $info) {
  210. if (!empty($info['settings'])) {
  211. foreach ($info['settings'] as $field_name => $value) {
  212. if (isset($form_state['values'][$field_name])) {
  213. $form_state['conf']['formatter_settings'][$field_name] = $form_state['values'][$field_name];
  214. }
  215. }
  216. }
  217. }
  218. if (isset($form_state['values']['delta_limit'])) {
  219. $form_state['conf']['delta_limit'] = $form_state['values']['delta_limit'];
  220. $form_state['conf']['delta_offset'] = $form_state['values']['delta_offset'];
  221. $form_state['conf']['delta_reversed'] = $form_state['values']['delta_reversed'];
  222. }
  223. }
  224. /**
  225. * Returns the administrative title for a type.
  226. */
  227. function ctools_entity_field_content_type_admin_title($subtype, $conf, $context) {
  228. list($bundle, $field_name) = explode(':', $subtype);
  229. ctools_include('fields');
  230. return t('"@s" @field', array('@s' => $context->identifier, '@field' => ctools_field_label($field_name)));
  231. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.