You are here

function flexiform_update_7006 in Flexiform 7

Convert forms to the new format.

File

./flexiform.install, line 315
Sets up the base table for our entity and a table to store information about the entity types.

Code

function flexiform_update_7006() {
  $flexiforms = entity_load('flexiform');
  foreach ($flexiforms as $flexiform) {
    if (empty($flexiform->elements)) {
      continue;
    }
    $flexiform_elements = $flexiform->elements;
    $flexiform->elements = array();
    foreach ($flexiform_elements as $entity_namespace => $elements) {
      foreach ($elements as $element_name => $settings) {
        $type = $settings['type'];
        $class_name = 'FlexiformElement' . ucfirst($type);
        unset($settings['type']);
        $settings['element_name'] = $element_name = $type . ':' . $element_name;
        $settings['enitity_namespace'] = $entity_namespace;
        $element = new $class_name($flexiform, $settings);
        $flexiform
          ->addElement($element);
      }
    }
    $flexiform
      ->save();
    if (module_exists('flexiform_element_group')) {
      $groups = field_group_info_groups('flexiform', $flexiform->form, 'form', TRUE);
      foreach ($groups as $group) {
        foreach ($group->children as $key => $element_name) {
          $group->children[$key] = preg_replace('/\\_\\_/', ':', $element_name, 2);
        }
        ctools_export_crud_save('field_group', $group);
      }
    }
  }
}