You are here

function fe_paths_update_7002 in File Entity Paths 7.2

Implements hook_update_7002();

Fix existing saved configuration because of new field based structure.

File

./fe_paths.install, line 229
Install, update and uninstall functions for the File Entity Paths module. @todo: Figure out, how should this work with Filefield Paths. Now, the filefield_paths has partial media + File Entity support

Code

function fe_paths_update_7002() {
  $configs = fe_paths_config_load_multiple();
  foreach ($configs as $config) {
    if (!empty($config->data['entity'])) {
      if (isset($config->data['bundle']) && !is_array($config->data['bundle']) && $config->data['bundle'] != 'global') {
        $fields = fe_paths_get_available_fields($config->data['entity'], $config->data['bundle']);
        $bundle = $config->data['bundle'];
        $config->data['bundle'] = array();
        foreach ($fields as $field_name => $field) {
          $config->data['bundle'][$bundle][$field_name] = 1;
        }
      }
      else {
        $bundles = fe_paths_get_bundle_names($config->data['entity']);
        $config->data['bundle'] = array();
        foreach ($bundles as $bundle => $value) {
          $fields = fe_paths_get_available_fields($config->data['entity'], $bundle);
          foreach ($fields as $field_name => $field) {
            $config->data['bundle'][$bundle][$field_name] = 1;
          }
        }
      }
      fe_paths_config_save($config);
    }
  }
}