diff --git a/field_group.module b/field_group.module index c084c32..43c1e4e 100644 --- a/field_group.module +++ b/field_group.module @@ -176,6 +176,17 @@ function field_group_ctools_plugin_api($owner, $api) { } /** + * Implementation of hook_ctools_plugin_directory(). + * + * Panels integration. + */ +function field_group_ctools_plugin_directory($module, $plugin) { + if (in_array($module, array('panels', 'ctools', 'page_manager'))) { + return 'plugins/' . $plugin; + } +} + +/** * Implements hook_theme(). */ function field_group_theme() { @@ -2275,13 +2286,3 @@ function field_group_field_group_to_hook_code($data, $module) { $code .= "}\n"; return $code; } - -/** - * Implementation of hook_ctools_plugin_directory(). - * Panels integration - */ -function field_group_ctools_plugin_directory($module, $plugin) { - if (module_exists('entity') && in_array($module, array('panels', 'ctools', 'page_manager'))) { - return 'plugins/' . $plugin; - } -} diff --git a/plugins/content_types/entity_form_field_group.inc b/plugins/content_types/entity_form_field_group.inc deleted file mode 100644 index 0414cab..0000000 --- a/plugins/content_types/entity_form_field_group.inc +++ /dev/null @@ -1,167 +0,0 @@ - t('Entity field group'), - 'defaults' => array('label' => '', 'formatter' => ''), - 'content type' => 'field_group_entity_form_field_group_content_type_content_type', -); - -/** - * Just one subtype. - * - * Ordinarily this function is meant to get just one subtype. However, we are - * using it to deal with the fact that we have changed the subtype names. This - * lets us translate the name properly. - */ -function field_group_entity_form_field_group_content_type_content_type($subtype) { - $types = field_group_entity_form_field_group_content_type_content_types(); - if (isset($types[$subtype])) { - return $types[$subtype]; - } -} - -/** - * return all field group content types availible - */ -function field_group_entity_form_field_group_content_type_content_types() { - $groups = field_group_read_groups(); - $types = array(); - $content_types = array(); - - foreach ($groups as $entity_type => $bundles) { - foreach ($bundles as $bundle => $modes) { - foreach ($modes as $mode => $fieldgroups) { - foreach ($fieldgroups as $group_name => $field_group) { - // Only use form field groups - if ($field_group->mode == 'form') { - $types[$entity_type . ':' . $group_name] = array( - 'title' => t('Field Group Form: @widget_label', array( - '@widget_label' => t($field_group->label), - )), - 'category' => t('Form'), - ); - $content_types[$entity_type . ':' . $group_name]['types'][$bundle] = $bundle; - } - } - } - } - } - // Create the required context for each field related to the bundle types. - foreach ($types as $key => $field_content_type) { - list($entity_type, $group_name) = explode(':', $key, 2); - $types[$key]['required context'] = new ctools_context_required(t(ucfirst($entity_type)), $entity_type, array( - 'form' => array('form'), - 'type' => $content_types[$key]['types'], - )); - unset($content_types[$key]['types']); - } - return $types; -} - -/** - * Render the custom content type. - */ -function field_group_entity_form_field_group_content_type_render($subtype, $conf, $panel_args, $context) { - if (empty($context) || empty($context->data)) { - return; - } - - // Get a shortcut to the entity. - $entity = $context->data; - list($entity_type, $group_name) = explode(':', $subtype, 2); - - // Load the entity type's information where the fieldgroup is placed - $ids = entity_extract_ids($entity_type, $entity); - $bundle = $entity->type; - - $list = field_group_read_groups(array('bundle' => $bundle, 'entity_type' => $entity_type, 'mode' => 'form')); - - $group = $list[$entity_type][$bundle]['form'][$group_name]; - - // Do not render if the entity type does not have this fieldgroup. - if (empty($group)) { - return; - } - - if (isset($context->form)) { - - if (isset($context->form['#pre_render'])) { - foreach ($context->form['#pre_render'] as $function) { - if (function_exists($function)) { - $context->form = $function($context->form); - } - } - unset($context->form['#pre_render']); - } - if (!empty($context->form[$group_name])) { - $block->content[$group_name] = $context->form[$group_name]; - if (!empty($conf['disable_children'])) { - foreach ($conf['disable_children'] as $field) { - if (!empty($block->content[$group_name][$field])) { - $block->content[$group_name][$field]['#access'] = FALSE; - } - } - } - unset($context->form[$group_name]); - } - } - else { - $block->content = ''; - } - return $block; -} - -/** - * Returns the administrative title for a type. - */ -function field_group_entity_form_field_group_content_type_admin_title($subtype, $conf, $context) { - list($entity_type, $group_name) = explode(':', $subtype, 2); - return t('"@s" @group_name', array('@s' => $context->identifier, '@group_name' => $group_name)); -} - -function field_group_entity_form_field_group_content_type_edit_form($form, &$form_state) { - list($entity_type, $group_name) = explode(':', $form_state['subtype_name'], 2); - $bundle = !empty($form_state['subtype']['required context']->restrictions['type']) && count($form_state['subtype']['required context']->restrictions['type']) == 1 ? current($form_state['subtype']['required context']->restrictions['type']) : NULL; - $groups = field_group_info_groups(); - if ($bundle) { - if (!empty($groups[$entity_type][$bundle]['form'][$group_name]->children)) { - $fields = $groups[$entity_type][$bundle]['form'][$group_name]->children; - } - } - else { - $fields = array(); - foreach ($groups[$entity_type] as $bundle => $groups) { - if (!empty($groups['form'][$group_name]->children)) { - $fields = array_merge($groups['form'][$group_name]->children, $fields); - } - } - } - if ($fields) { - $options = array(); - foreach ($fields as $field) { - if ($field_data = field_info_field($field)) { - $options[$field] = check_plain($field['label']); - } - else { - $options[$field] = check_plain($field); - } - } - $form['disable_children'] = array( - '#title' => t('Disable fields'), - '#type' => 'checkboxes', - '#options' => $options, - '#default_value' => !empty($form_state['conf']['disable_children']) ? $form_state['conf']['disable_children'] : array(), - ); - } - return $form; -} - -function field_group_entity_form_field_group_content_type_edit_form_submit($form, &$form_state) { - foreach (array('disable_children') as $key) { - $form_state['conf'][$key] = !empty($form_state['values'][$key]) ? $form_state['values'][$key] : array(); - } -} diff --git a/plugins/content_types/field_group.inc b/plugins/content_types/field_group.inc index e869543..298faad 100644 --- a/plugins/content_types/field_group.inc +++ b/plugins/content_types/field_group.inc @@ -6,8 +6,7 @@ */ $plugin = array( 'title' => t('Field Group'), - // Probably not the best category to find this? - 'category' => 'Miscellaneous', + 'category' => t('Field Groups'), 'content type' => 'field_group_field_group_content_type', 'required context' => new ctools_context_required(t('entity'), 'entity'), ); @@ -38,13 +37,6 @@ function field_group_field_group_content_type_edit_form($form, &$form_state) { $entity_type = $context->type[2]; $entity_info = entity_get_info($entity_type); - // TODO: Trying to handle arguments like nids. - if ($entity_type == 'node' && !empty($context->argument)) { - $bundle_key = $entity_info['entity keys']['bundle']; - $entity_id = $context->argument; - $bundle = $context->data->$bundle_key; - } - // Reading all field_groups. $groups = field_group_read_groups(array('entity_type' => $entity_type)); @@ -61,7 +53,7 @@ function field_group_field_group_content_type_edit_form($form, &$form_state) { '#type' => 'select', '#description' => t('Select a bundle for this @entity_type.', array('@entity_type' => $entity_info['label'])), '#options' => $bundles, - '#default_value' => $conf['bundle'], + '#default_value' => !empty($conf['bundle']) ? $conf['bundle'] : NULL, '#ajax' => array( 'event' => 'change', 'wrapper' => 'field-group-build-mode-container', @@ -85,10 +77,9 @@ function field_group_field_group_content_type_edit_form($form, &$form_state) { '#type' => 'select', '#description' => t('Select a build mode for this @entity_type.', array('@entity_type' => $entity_info['label'])), '#options' => $build_mode_options, - '#default_value' => $conf['build_mode'], + '#default_value' => !empty($conf['build_mode']) ? $conf['build_mode'] : NULL, '#ajax' => array( 'event' => 'change', -// 'path' => 'ctools/content/ajax', 'wrapper' => 'field-group-field-group-container', 'callback' => 'field_group_avalible_field_groups_callback' ), @@ -97,7 +88,7 @@ function field_group_field_group_content_type_edit_form($form, &$form_state) { ); // if build_mode exists in the options, it's kept as selected, otherwise the first value will be set - $build_mode = in_array($conf['build_mode'], $form['build_mode']['#options']) ? $conf['build_mode'] : reset($form['build_mode']['#options']); + $build_mode = !empty($conf['build_mode']) && in_array($conf['build_mode'], $form['build_mode']['#options']) ? $conf['build_mode'] : reset($form['build_mode']['#options']); // Get all field_groups for the current selectin of mode + bundle + entity_type. $field_groups = array(); @@ -108,7 +99,7 @@ function field_group_field_group_content_type_edit_form($form, &$form_state) { $form['field_group'] = array( '#type' => 'select', '#options' => $field_groups, - '#default_value' => $conf['field_group'], + '#default_value' => !empty($conf['field_group']) ? $conf['field_group'] : NULL, '#title' => t('Select Field Group'), ); @@ -195,7 +186,9 @@ function field_group_avalible_field_groups_callback($form, &$form_state) { */ function field_group_field_group_content_type_edit_form_submit($form, &$form_state) { foreach (array('context', 'build_mode', 'field_group', 'bundle') as $key) { - $form_state['conf'][$key] = $form_state['values'][$key]; + if (!empty($form_state['values'][$key])) { + $form_state['conf'][$key] = $form_state['values'][$key]; + } } } @@ -216,7 +209,6 @@ function field_group_field_group_content_type_render($subtype, $conf, $panel_arg // Load the entitys $entitys = entity_get_info($entity_type); $entity_key = $entitys['entity keys']['id']; - $bundle_key = $entitys['bundle keys']['bundle']; // pickup the right entity $entity = isset($context->data) ? clone($context->data) : NULL;