Browse files

Handle field_groups using exportables instead of save/delete.

  • Loading branch information...
1 parent 553d61a commit 1fd4fbf72f810a7df0fa44236ceb5314ca101d4e @boombatower committed May 29, 2012
View
2 coder/drupal_coder.install
@@ -12,7 +12,6 @@
function drupal_coder_install() {
conduit_install_node_type('conduit_job_drupal_coder');
field_helper_install_all('drupal_coder');
- conduit_drupal_install_group('conduit_job_drupal_coder');
}
/**
@@ -22,7 +21,6 @@ function drupal_coder_uninstall() {
module_load_install('conduit');
conduit_uninstall_node_type('conduit_job_drupal_coder');
field_helper_uninstall_all('drupal_coder');
- conduit_drupal_uninstall_group('conduit_job_drupal_coder');
}
/**
View
54 conduit_drupal.field_group.inc
@@ -0,0 +1,54 @@
+<?php
+/**
+ * @file
+ * Provide field_group definitions.
+ */
+
+/**
+ * Implements hook_field_group_info().
+ */
+function conduit_drupal_field_group_info() {
+ $field_groups = array();
+
+ // Create a result views for each conduit_drupal node type.
+ foreach (array('drupal_coder', 'drupal_plumber', 'drupal_scan') as $module) { // @TODO Detect the modules using an info hook, etc.
+ if (!module_exists($module)) {
+ continue;
+ }
+
+ $type = 'conduit_job_' . $module;
+ $info = conduit_job_info($type);
+
+ $field_group = new stdClass();
+ $field_group->api_version = 1;
+ $field_group->group_name = $info['module'] . '_result';
+ $field_group->identifier = $field_group->group_name . '|node|' . $type . '|default';
+ $field_group->entity_type = 'node';
+ $field_group->bundle = $type;
+ $field_group->mode = 'default';
+ $field_group->parent_name = '';
+ $field_group->data = array(
+ 'label' => 'Result',
+ 'weight' => '10',
+ 'format_type' => 'view',
+ 'format_settings' => array(
+ 'instance_settings' => array(
+ 'primary_field' => $module == 'drupal_scan' ? 'conduit_result_drupal_scan_list' : 'conduit_result_drupal_summary',
+ 'field_suppress' => 'always',
+ ),
+ ),
+ );
+
+ // List all the conduit_result fields as children.
+ module_load_install($info['module']);
+ foreach (module_invoke($info['module'], 'install_instances') as $instance) {
+ if (strpos($instance['field_name'], 'conduit_result') === 0 && field_info_instance($instance['entity_type'], $instance['field_name'], $instance['bundle'])) {
+ $field_group->data['children'][] = $instance['field_name'];
+ }
+ }
+
+ $field_groups[$field_group->identifier] = $field_group;
+ }
+
+ return $field_groups;
+}
View
57 conduit_drupal.install
@@ -21,63 +21,6 @@ function conduit_drupal_uninstall() {
}
/**
- * Create result field group for node type.
- *
- * @param $type
- * Node type.
- * @param $primary_field
- * (Optional) Primary field for the result view.
- */
-function conduit_drupal_install_group($type, $primary_field = NULL) {
- $info = conduit_job_info($type);
- $group = array(
- 'group_name' => $info['module'] . '_result',
- 'entity_type' => 'node',
- 'bundle' => $type,
- 'mode' => 'default',
- 'parent_name' => '',
- 'label' => 'Result',
- 'weight' => 10,
- 'children' => array_keys(module_invoke($info['module'], 'install_instances')),
- 'format_type' => 'view',
- 'format_settings' => array(
- 'instance_settings' => array(
- 'primary_field' => $primary_field ? $primary_field : 'conduit_result_drupal_summary',
- 'field_suppress' => 'always',
- ),
- ),
- );
- $group = (object) $group;
-
- // Only include drupal result fields.
- foreach ($group->children as $key => &$child) {
- if (strpos($child, 'job_conduit_result_drupal') === 0) {
- $child = substr($child, 4);
- }
- else {
- unset($group->children[$key]);
- }
- }
- field_group_save($group);
-}
-
-/**
- * Remove result field group for node type.
- *
- * @param $type
- * Node type.
- */
-function conduit_drupal_uninstall_group($type) {
- $info = conduit_job_info($type);
- $groups = field_group_read_groups(array(
- 'group_name' => $name = $info['module'] . '_result',
- ));
- if ($groups && ($group = $groups['node'][$type]['default'][$name])) {
- field_group_delete_field_group($group, $group->mode);
- }
-}
-
-/**
* Implements hook_install_fields().
*/
function conduit_drupal_install_fields() {
View
9 conduit_drupal.module
@@ -191,3 +191,12 @@ function conduit_drupal_views_revision($view) {
return $view;
}
+
+/**
+ * Implements hook_ctools_plugin_api().
+ */
+function conduit_drupal_ctools_plugin_api($module, $api) {
+ if ($module == 'field_group' && $api == 'field_group') {
+ return array('version' => 1);
+ }
+}
View
2 plumber/drupal_plumber.install
@@ -12,7 +12,6 @@
function drupal_plumber_install() {
conduit_install_node_type('conduit_job_drupal_plumber');
field_helper_install_all('drupal_plumber');
- conduit_drupal_install_group('conduit_job_drupal_plumber');
}
/**
@@ -22,7 +21,6 @@ function drupal_plumber_uninstall() {
module_load_install('conduit');
conduit_uninstall_node_type('conduit_job_drupal_plumber');
field_helper_uninstall_all('drupal_plumber');
- conduit_drupal_uninstall_group('conduit_job_drupal_plumber');
}
/**
View
2 scan/drupal_scan.install
@@ -12,7 +12,6 @@
function drupal_scan_install() {
conduit_install_node_type('conduit_job_drupal_scan');
field_helper_install_all('drupal_scan');
- conduit_drupal_install_group('conduit_job_drupal_scan', 'conduit_result_drupal_scan_list');
}
/**
@@ -22,7 +21,6 @@ function drupal_scan_uninstall() {
module_load_install('conduit');
conduit_uninstall_node_type('conduit_job_drupal_scan');
field_helper_uninstall_all('drupal_scan');
- conduit_drupal_uninstall_group('conduit_job_drupal_scan');
}
/**

0 comments on commit 1fd4fbf

Please sign in to comment.