Commit 140d02b7 authored by KarenS's avatar KarenS
Browse files

#824812, by yched, Add yched's new fieldgroup module to repository.

parent d0b71397
Early version of fieldgroup module for D7.
Highly experimental code - has storage, but needs a lot of work still
Testing the manage display screen requires the core patch in
http://drupal.org/node/616240
<?php
// $Id$
/**
* @file
* Field group administrative functions.
*/
function field_group_edit_form($form, &$form_state, $group) {
$output = array();
return $output;
}
/**
* Menu callback; present a form for removing a group.
*/
function field_group_delete_form($form, &$form_state, $group) {
// @todo broken - see field_group_menu_load().
$form['#group'] = $group;
// @todo this shouldn't redirect to fields - this can be display too.
$admin_path = _field_ui_bundle_admin_path($group->entity_type, $group->bundle);
$output = confirm_form($form,
t('Are you sure you want to delete the group %group?', array('%group' => $group->label)),
$admin_path . '/fields',
t('This action cannot be undone.'),
t('Delete'), t('Cancel'),
'confirm'
);
return $output;
}
/**
* Remove group from bundle.
*
* @todo we'll have to reset all view mode settings - that will be fun :)
*/
function field_group_delete_form_submit($form, &$form_state) {
$group = $form['#group'];
$bundle = $group->bundle;
$entity_type = $group->entity_type;
$bundles = field_info_bundles();
$bundle_label = $bundles[$entity_type][$bundle]['label'];
db_delete('field_group')->condition('id', $group->id)->execute();
drupal_set_message(t('The group %group has been deleted from the %type content type.', array('%group' => $group->label, '%type' => $bundle_label)));
cache_clear_all('field_groups', 'cache_field');
// @todo this shouldn't redirect to fields - this can be display too.
$admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
$form_state['redirect'] = array($admin_path . '/fields');
}
<?php
// @todo Implement a real CRUD API, and store in a real db table...
function field_group_get_groups($entity_type = NULL, $bundle = NULL, $mode = NULL) {
$groups = variable_get('field_group_groups', _field_groups_default_groups());
if (!isset($entity_type)) {
return $groups;
}
else {
if (isset($groups[$entity_type][$bundle][$mode])) {
return $groups[$entity_type][$bundle][$mode];
}
else {
return array();
}
}
}
function field_group_save_group($entity_type, $bundle, $mode, $group) {
$groups = variable_get('field_group_groups', _field_groups_default_groups());
$groups[$entity_type][$bundle][$mode][$group['name']] = $group;
variable_set('field_group_groups', $groups);
}
// @todo temporary, dev only.
function _field_groups_default_groups() {
return array(
'node' => array(
'article' => array(
'default' => array(
'group_1' => array(
'name' => 'group_1',
'label' => 'Group 1',
'weight' => 0,
'visible' => TRUE,
// Having the parent list its children is unusual.
// It's because potential children don't know they have parents
// (no 'parent' column incore field_config_instances table).
'children' => array('group_2'),
),
'group_2' => array(
'name' => 'group_2',
'label' => 'Group 2',
'weight' => 1,
'visible' => TRUE,
'children' => array('body'),
),
),
),
'page' => array(
'default' => array(
'group_1' => array(
'name' => 'group_1',
'label' => 'Group 1',
'weight' => 0,
'visible' => TRUE,
'children' => array('group_2'),
),
'group_2' => array(
'name' => 'group_2',
'label' => 'Group 2',
'weight' => 1,
'visible' => TRUE,
'children' => array('body'),
),
),
),
),
);
}
\ No newline at end of file
/* $Id$ */
#field-overview tr.field-group .group-label,#field-display-overview tr.field-group .group-label
{
font-weight: bold;
}
\ No newline at end of file
; $Id$
name = Fieldgroup
description = Fieldgroup
package = Fields
dependencies[] = field
core = 7.x
files[] = field_group.module
files[] = field_group.install
files[] = field_group.test
files[] = field_group.admin.inc
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Fieldgroup module install file.
*/
/**
* Implements hook_schema().
*/
function field_group_schema() {
$schema['field_group'] = array(
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'The primary identifier for a group',
),
'group_name' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The name of this group.',
),
'entity_type' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'bundle' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
'mode' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
// @todo 'parent_name' is redundant with the data in the 'children'
// entry, brings a risk of inconsistent data. This should be removed from
// the schema and pre-computed it if needed in field_group_get_groups().
'parent_name' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The parent name for a group',
),
'data' => array(
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'description' => 'Serialized data containing the group properties that do not warrant a dedicated column.',
),
),
'primary key' => array('id'),
'indexes' => array(
'group_name' => array('group_name'),
),
);
return $schema;
}
// $Id$
(function($) {
/**
* Row handlers for the 'Manage display' screen.
*/
Drupal.fieldUIDisplayOverview = Drupal.fieldUIDisplayOverview || {};
Drupal.fieldUIDisplayOverview.group = function(row, data) {
this.row = row;
this.name = data.name;
this.region = data.region;
this.tableDrag = data.tableDrag;
// Attach change listener to the 'group format' select.
this.$formatSelect = $('select.field-group-type', row);
this.$formatSelect.change(Drupal.fieldUIOverview.onChange);
return this;
};
Drupal.fieldUIDisplayOverview.group.prototype = {
getRegion: function () {
return (this.$formatSelect.val() == 'hidden') ? 'hidden' : 'visible';
},
regionChange: function (region, recurse) {
$.debug(this.region + ' --> ' + region, this.name);
// Default recurse to true.
recurse = (recurse == undefined) || recurse;
// When triggered by a row drag, the 'format' select needs to be adjusted to
// the new region.
var currentValue = this.$formatSelect.val();
switch (region) {
case 'visible':
if (currentValue == 'hidden') {
// Restore the group format back to 'fieldset'.
var value = 'fieldset';
}
break;
default:
var value = 'hidden';
break;
}
if (value != undefined) {
this.$formatSelect.val(value);
}
var refreshRows = {};
refreshRows[this.name] = this.$formatSelect.get(0);
if (recurse) {
// Create a new tabledrag rowObject, that will compute the group's child
// rows for us.
var tableDrag = this.tableDrag;
rowObject = new tableDrag.row(this.row, 'mouse', true);
// Skip the main row, we handled it above.
rowObject.group.shift();
// Let child rows handlers deal with the region change - without recursing
// on nested group rows, we are handling them all here.
$.each(rowObject.group, function() {
var childRow = this;
var childRowHandler = $(childRow).data('fieldUIRowHandler');
$.extend(refreshRows, childRowHandler.regionChange(region, false));
});
}
return refreshRows;
},
};
})(jQuery);
\ No newline at end of file
This diff is collapsed.
<?php
// $Id$
/**
* @file
* Unit test file for groups.
*/
/**
* Group UI tests.
*/
class GroupUITestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Group UI tests',
'description' => 'Test the group UI functionality.',
'group' => 'Field group',
);
}
function setUp() {
parent::setUp('field_test', 'field_group');
// Create test user.
$admin_user = $this->drupalCreateUser(array('administer content types'));
$this->drupalLogin($admin_user);
// Create random group name.
$this->group_label = $this->randomName(8);
$this->group_name_input = strtolower($this->randomName(8));
$this->group_name = 'group_'. $this->group_name_input;
}
/**
* Main entry point for the group CRUD tests.
*
* In order to act on the same groups, and not create the groups over and over
* again the following tests create, update and delete the same groups.
*/
function testCRUDGroups() {
$this->createGroup();
}
/**
* Test adding a new group.
*/
function createGroup() {
// Create a test groupp.
$edit = array(
'_add_new_group[label]' => $this->group_label,
'_add_new_group[group_name]' => $this->group_name_input,
);
$label = $edit['_add_new_group[label]'];
$field_name = $edit['_add_new_group[group_name]'];
// 'Add new group' on the 'Manage fields' page.
$this->drupalPost('admin/structure/types/manage/article/fields', $edit, t('Save'));
$this->assertRaw(t('New group %label succesfully created.', array('%label' => $label)), t('Group succesfully saved.'));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment