123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- <?php
- function field_group_schema() {
- $schema['field_group'] = array(
- 'description' => t('Table that contains field group entries and settings.'),
-
- 'export' => array(
- 'key' => 'identifier',
- 'identifier' => 'field_group',
- 'default hook' => 'field_group_info',
- 'load callback' => 'field_group_group_load_by_identifier',
- 'save callback' => 'field_group_group_save',
- 'delete callback' => 'field_group_group_export_delete',
- 'can disable' => TRUE,
- 'api' => array(
- 'owner' => 'field_group',
- 'api' => 'field_group',
- 'minimum_version' => 1,
- 'current_version' => 1,
- ),
- ),
- 'fields' => array(
- 'id' => array(
- 'type' => 'serial',
- 'not null' => TRUE,
- 'description' => 'The primary identifier for a group',
- 'no export' => TRUE,
- ),
- 'identifier' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The unique string 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' => ''
- ),
-
-
-
- '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'),
- ),
- 'unique keys' => array(
- 'identifier' => array('identifier'),
- ),
- );
- return $schema;
- }
- function _field_group_install_read_groups() {
- $groups = array();
- if (db_table_exists('content_group')) {
- $query = db_select('content_group', 'cg', array('fetch' => PDO::FETCH_ASSOC))
- ->fields('cg')
-
- ->condition('group_type', 'standard');
- foreach ($query->execute() as $record) {
- $record['settings'] = unserialize($record['settings']);
- $groups[$record['group_name'] . '-' . $record['type_name']] = $record;
- }
- foreach ($groups as $key => $group) {
- $query2 = db_select('content_group_fields', 'cgf', array('fetch' => PDO::FETCH_ASSOC))
- ->fields('cgf')
- ->condition('group_name', $group['group_name']);
- foreach ($query2->execute() as $field) {
- $groups[$field['group_name'] . '-' . $field['type_name']]['children'][] = $field;
- }
- }
- }
- return $groups;
- }
- function field_group_install() {
- $groups = _field_group_install_read_groups();
- module_load_include('module', 'field_group');
- if (!empty($groups)) {
- module_load_include('module', 'ctools');
- ctools_include('export');
- foreach ($groups as $group) {
- $group = (object) $group;
- $new = new stdClass();
- $new->group_name = $group->group_name;
- $new->entity_type = 'node';
- $new->bundle = $group->type_name;
- $new->label = $group->label;
- $new->parent_name = '';
- $new->children = array();
- foreach ($group->children as $child) {
- $new->children[] = $child['field_name'];
- }
-
- $new->id = NULL;
- $new->weight = $group->weight;
- $new->mode = 'form';
- $new->format_type = 'fieldset';
- $new->format_settings = array(
- 'formatter' => preg_match("/fieldset/", $group->settings['form']['style']) ? 'collapsible' : 'collapsed',
- 'instance_settings' => array(),
- );
- $new->identifier = $new->group_name . '|' . $new->entity_type . '|' . $new->bundle . '|' . $new->mode;
- ctools_export_crud_save('field_group', $new);
-
- $new->id = NULL;
- $new->weight = $group->weight;
- $new->mode = 'default';
- $new->format_type = $group->settings['display']['full']['format'];
- $new->format_settings = array(
- 'formatter' => 'collapsible',
- 'instance_settings' => array(),
- );
- $new->identifier = $new->group_name . '|' . $new->entity_type . '|' . $new->bundle . '|' . $new->mode;
- ctools_export_crud_save('field_group', $new);
-
- $new->id = NULL;
- $new->weight = $group->weight;
- $new->mode = 'teaser';
- $new->format_type = $group->settings['display']['teaser']['format'];
- $new->format_settings = array(
- 'formatter' => 'collapsible',
- 'instance_settings' => array(),
- );
- $new->identifier = $new->group_name . '|' . $new->entity_type . '|' . $new->bundle . '|' . $new->mode;
- ctools_export_crud_save('field_group', $new);
- }
- }
-
- db_update('system')
- ->fields(array('weight' => 1))
- ->condition('name', 'field_group')
- ->execute();
- }
- function field_group_update_7001() {
- if (!db_field_exists('field_group', 'identifier')) {
-
- db_add_field('field_group', 'identifier', array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The unique string identifier for a group.',
- ));
-
- drupal_get_schema('field_group', TRUE);
- module_load_include('module', 'field_group');
- _field_group_recreate_identifiers();
- }
- db_update('system')
- ->fields(array('weight' => 1))
- ->condition('name', 'field_group')
- ->execute();
-
- field_group_info_groups(NULL, NULL, NULL, TRUE);
- }
- function field_group_update_7002() {
- module_load_include('module', 'field_group');
-
-
-
-
-
-
- _field_group_recreate_identifiers();
-
- field_group_info_groups(NULL, NULL, NULL, TRUE);
- }
- function field_group_update_7003() {
- module_load_include('module', 'field_group');
- _field_group_recreate_identifiers();
-
- field_group_info_groups(NULL, NULL, NULL, TRUE);
- }
- function field_group_update_7004() {
- db_drop_unique_key('field_group', 'identifier');
- db_add_unique_key('field_group', 'identifier', array('identifier'));
- }
- function field_group_update_7005() {
-
- $result = db_select('field_group', 'fg')
- ->fields('fg')
- ->execute();
- $rows = array();
- foreach($result as $row) {
-
- $row->data = unserialize($row->data);
- $classes = explode(" ", $row->data['format_settings']['instance_settings']['classes']);
- $optional_classes = array(str_replace("_", "-", $row->group_name), 'field-group-' . $row->data['format_type']);
- foreach ($optional_classes as $optional_class) {
- if (!in_array($optional_class, $classes)) {
- $classes[] = $optional_class;
- }
- }
- $row->data['format_settings']['instance_settings']['classes'] = implode(" ", $classes);
- $rows[] = $row;
- }
- foreach ($rows as $row) {
- drupal_write_record('field_group', $row, array('id'));
- }
-
- field_group_info_groups(NULL, NULL, NULL, TRUE);
- }
- function field_group_update_7006() {
- ctools_include("export");
-
- $field_groups = ctools_export_load_object("field_group");
- foreach ($field_groups as $row) {
-
-
- if ($row->export_type == EXPORT_IN_CODE) {
- $classes = array();
- if (isset($row->data['format_settings'], $row->data['format_settings']['instance_settings'], $row->data['format_settings']['instance_settings']['classes'])) {
- $classes = explode(" ", $row->data['format_settings']['instance_settings']['classes']);
- }
- $optional_classes = array(str_replace("_", "-", $row->group_name), 'field-group-' . $row->data['format_type']);
- foreach ($optional_classes as $optional_class) {
- if (!in_array($optional_class, $classes)) {
- $classes[] = $optional_class;
- }
- }
- $row->data['format_settings']['instance_settings']['classes'] = implode(" ", $classes);
- unset($row->id);
- drupal_write_record('field_group', $row);
- }
- }
-
- field_group_info_groups(NULL, NULL, NULL, TRUE);
- }
- function field_group_update_7007() {
- ctools_include("export");
-
- $field_groups = ctools_export_load_object("field_group");
- foreach ($field_groups as $row) {
-
- $populate_id_setting = array(
- 'html-element',
- 'div',
- 'html5',
- 'fieldset',
- 'tabs',
- 'htabs',
- 'accordion',
- );
- if (in_array($row->data['format_type'], $populate_id_setting)) {
-
- $view_mode = $row->mode == 'default' ? 'full' : $row->mode;
- $id = $row->entity_type . '_' . $row->bundle . '_' . $view_mode . '_' . $row->group_name;
- $row->data['format_settings']['instance_settings']['id'] = $id;
- }
- if ($row->export_type == EXPORT_IN_CODE) {
- unset($row->id);
- drupal_write_record('field_group', $row);
- }
- else {
- drupal_write_record('field_group', $row, array('id'));
- }
- }
-
- field_group_info_groups(NULL, NULL, NULL, TRUE);
- }
- function field_group_update_7008() {
- drupal_flush_all_caches();
- }
|