field_collection.pages.inc

  1. cis7 sites/all/modules/ulmus/field_collection/field_collection.pages.inc
  2. cle7 sites/all/modules/ulmus/field_collection/field_collection.pages.inc
  3. ecd7 sites/all/modules/ulmus/field_collection/field_collection.pages.inc
  4. elmsmedia7 sites/all/modules/ulmus/field_collection/field_collection.pages.inc
  5. harmony7 sites/all/modules/ulmus/field_collection/field_collection.pages.inc
  6. icor7 sites/all/modules/ulmus/field_collection/field_collection.pages.inc
  7. meedjum_blog7 sites/all/modules/ulmus/field_collection/field_collection.pages.inc
  8. mooc7 sites/all/modules/ulmus/field_collection/field_collection.pages.inc

Provides the field collection item view / edit / delete pages.

Functions

Namesort descending Description
field_collection_item_add Add a new field collection item.
field_collection_item_delete_confirm Form for deleting a field collection item.
field_collection_item_delete_confirm_submit Submit callback for deleting a field collection item.
field_collection_item_form Form for editing a field collection item. @todo implement hook_forms().
field_collection_item_form_submit Submit callback that permanently saves the changes to the entity.
field_collection_item_form_submit_build_field_collection Submit builder. Extracts the form values and updates the entity.
field_collection_item_form_validate Validation callback.
field_collection_item_page_view Field collection item view page.

File

sites/all/modules/ulmus/field_collection/field_collection.pages.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Provides the field collection item view / edit / delete pages.
  5. */
  6. // TODO: fix being embedded in a host with revisions.
  7. /**
  8. * Field collection item view page.
  9. */
  10. function field_collection_item_page_view($field_collection_item) {
  11. // @todo: Set breadcrumb including the host.
  12. drupal_set_title($field_collection_item->label());
  13. return $field_collection_item->view('full', NULL, TRUE);
  14. }
  15. /**
  16. * Form for editing a field collection item.
  17. * @todo implement hook_forms().
  18. */
  19. function field_collection_item_form($form, &$form_state, $field_collection_item) {
  20. if (!isset($field_collection_item->is_new)) {
  21. drupal_set_title($field_collection_item->label());
  22. }
  23. $form_state += array('field_collection_item' => $field_collection_item);
  24. // Hack: entity_form_field_validate() needs the bundle to be set.
  25. // @todo: Fix core and remove the hack.
  26. $form['field_name'] = array('#type' => 'value', '#value' => $field_collection_item->field_name);
  27. field_attach_form('field_collection_item', $field_collection_item, $form, $form_state);
  28. $form['actions'] = array('#type' => 'actions', '#weight' => 50);
  29. $form['actions']['submit'] = array(
  30. '#type' => 'submit',
  31. '#value' => t('Save'),
  32. '#weight' => 5,
  33. );
  34. return $form;
  35. }
  36. /**
  37. * Validation callback.
  38. */
  39. function field_collection_item_form_validate($form, &$form_state) {
  40. entity_form_field_validate('field_collection_item', $form, $form_state);
  41. }
  42. /**
  43. * Submit builder. Extracts the form values and updates the entity.
  44. */
  45. function field_collection_item_form_submit_build_field_collection($form, $form_state) {
  46. entity_form_submit_build_entity('field_collection_item', $form_state['field_collection_item'], $form, $form_state);
  47. return $form_state['field_collection_item'];
  48. }
  49. /**
  50. * Submit callback that permanently saves the changes to the entity.
  51. */
  52. function field_collection_item_form_submit($form, &$form_state) {
  53. $field_collection_item = field_collection_item_form_submit_build_field_collection($form, $form_state);
  54. $field_collection_item->save();
  55. drupal_set_message(t('The changes have been saved.'));
  56. $form_state['redirect'] = $field_collection_item->path();
  57. }
  58. /**
  59. * Form for deleting a field collection item.
  60. */
  61. function field_collection_item_delete_confirm($form, &$form_state, $field_collection_item) {
  62. $form_state += array('field_collection_item' => $field_collection_item);
  63. return confirm_form($form,
  64. t('Are you sure you want to delete %label?', array('%label' => $field_collection_item->label())),
  65. $field_collection_item->path(),
  66. t('This action cannot be undone.'),
  67. t('Delete'),
  68. t('Cancel')
  69. );
  70. }
  71. /**
  72. * Submit callback for deleting a field collection item.
  73. */
  74. function field_collection_item_delete_confirm_submit($form, &$form_state) {
  75. $field_collection_item = $form_state['field_collection_item'];
  76. $field_collection_item->deleteRevision();
  77. drupal_set_message(t('%label has been deleted.', array('%label' => drupal_ucfirst($field_collection_item->label()))));
  78. $form_state['redirect'] = '<front>';
  79. }
  80. /**
  81. * Add a new field collection item.
  82. *
  83. * @todo: Support optionally passing in the revision_id and langcode parameters.
  84. */
  85. function field_collection_item_add($field_name, $entity_type, $entity_id, $revision_id = NULL, $langcode = NULL) {
  86. $info = entity_get_info();
  87. if (!isset($info[$entity_type])) {
  88. return MENU_NOT_FOUND;
  89. }
  90. $result = entity_load($entity_type, array($entity_id));
  91. $entity = reset($result);
  92. if (!$entity) {
  93. return MENU_NOT_FOUND;
  94. }
  95. // Ensure the given entity is of a bundle that has an instance of the field.
  96. list($id, $rev_id, $bundle) = entity_extract_ids($entity_type, $entity);
  97. $instance = field_info_instance($entity_type, $field_name, $bundle);
  98. if (!$instance) {
  99. return MENU_NOT_FOUND;
  100. }
  101. // Check field cardinality.
  102. $field = field_info_field($field_name);
  103. $langcode = LANGUAGE_NONE;
  104. if (!($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || !isset($entity->{$field_name}[$langcode]) || count($entity->{$field_name}[$langcode]) < $field['cardinality'])) {
  105. drupal_set_message(t('Too many items.'), 'error');
  106. return '';
  107. }
  108. $field_collection_item = entity_create('field_collection_item', array('field_name' => $field_name));
  109. // Do not link the field collection item with the host entity at this point,
  110. // as during the form-workflow we have multiple field collection item entity
  111. // instances, which we don't want link all with the host.
  112. // That way the link is going to be created when the item is saved.
  113. $field_collection_item->setHostEntity($entity_type, $entity, LANGUAGE_NONE, FALSE);
  114. $title = ($field['cardinality'] == 1) ? $instance['label'] : t('Add new !instance_label', array('!instance_label' => $field_collection_item->translatedInstanceLabel()));
  115. drupal_set_title($title);
  116. // Make sure the current user has access to create a field collection item.
  117. if (!field_collection_item_access('create', $field_collection_item)) {
  118. return MENU_ACCESS_DENIED;
  119. }
  120. return drupal_get_form('field_collection_item_form', $field_collection_item);
  121. }
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.