diff --git a/modules/rh_field_collection/rh_field_collection.info b/modules/rh_field_collection/rh_field_collection.info new file mode 100644 index 0000000..9f40349 --- /dev/null +++ b/modules/rh_field_collection/rh_field_collection.info @@ -0,0 +1,5 @@ +name = Rabbit Hole field collections +description = Adds Rabbit Hole functionality for field collections. +core = 7.x +dependencies[] = rabbit_hole +dependencies[] = field_collection diff --git a/modules/rh_field_collection/rh_field_collection.module b/modules/rh_field_collection/rh_field_collection.module new file mode 100644 index 0000000..1b32df6 --- /dev/null +++ b/modules/rh_field_collection/rh_field_collection.module @@ -0,0 +1,87 @@ + array( + 'entity type' => 'field_collection_item', + 'base table' => 'field_collection_item', + 'view path' => 'field-collection/%/view', + ), + ); +} + +/** + * Implements hook_form_FORM_ID_alter(). + * + * This will add Rabbit Hole options to the field collection form. The user will + * be able to override the default Rabbit Hole options. + */ +function rh_field_collection_form_field_collection_item_form_alter(&$form, $form_state) { + rabbit_hole_form($form, 'field_collection_item', $form['#bundle'], 'rh_field_collection', $form['#entity']); +} + +/** + * Implements hook_form_FORM_ID_alter(). + * + * This will add Rabbit Hole options to the edit field form. These settings will + * be used as default for every field collection item. + */ +function rh_field_collection_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) { + + if (isset($form['#field']) && isset($form['#field']['type']) && $form['#field']['type'] == 'field_collection') { + rabbit_hole_form($form, 'field_collection_item', $form['#field']['field_name'], 'rh_field_collection'); + } +} + +/** + * Submit callback for the bundle form. + * + * This will set the values of the variables. + */ +function rh_field_collection_bundle_form_submit($form, $form_state) { + + $values = $form_state['values']; + $bundle = $values['instance']['field_name']; + + variable_set('rh_field_collection_item_override_' . $bundle, $values['rh_field_collection_item_override']); + variable_set('rh_field_collection_item_action_' . $bundle, $values['rh_field_collection_item_action']); + variable_set('rh_field_collection_item_redirect_' . $bundle, $values['rh_field_collection_item_redirect']); + variable_set('rh_field_collection_item_redirect_response_' . $bundle, $values['rh_field_collection_item_redirect_response']); +} + +/** + * Implements hook_field_collection_item_view(). + */ +function rh_field_collection_field_collection_item_view($field_collection_item, $view_mode, $langcode) { + + // Execute Rabbit Hole, if the field collection item is being viewed at its + // own page using the full view mode, and the current user isn't able to + // override Rabbit Hole. + $item_page = menu_get_object('field_collection_item', 2); + $is_page = $item_page ? ($item_page->item_id == $field_collection_item->item_id) : FALSE; + + if ($is_page && $view_mode == 'full' && !user_access('bypass rh_field_collection')) { + rabbit_hole_execute('field_collection_item', $field_collection_item); + } +} + +/** + * Implements hook_field_delete_field(). + */ +function rh_field_collection_field_delete_field($field) { + if ($field['type'] == 'field_collection') { + + // Delete variables connected to this field collection. + rabbit_hole_delete_variables('field_collection_item', $field['field_name']); + } +}