You are here

function uuid_fpp_features_rebuild in UUID Features Integration 7

Implements hook_features_rebuild().

Rebuilds terms based on UUID from code defaults.

1 call to uuid_fpp_features_rebuild()
uuid_fpp_features_revert in includes/uuid_fpp.features.inc
Implements hook_features_revert().

File

includes/uuid_fpp.features.inc, line 130
Features hooks for the uuid_fpp features component.

Code

function uuid_fpp_features_rebuild($module) {
  $fpps = features_get_default('uuid_fpp', $module);
  if (!empty($fpps)) {

    // Get info about current FPP types available in system.
    $entity_info = entity_get_info('fieldable_panels_pane');
    $entity_type = 'fieldable_panels_pane';

    // Loop through the export.
    foreach ($fpps as $data) {

      // Double-check that FPP can be created/reverted.
      if (!isset($entity_info['bundles'][$data['bundle']])) {
        drupal_set_message('Bundle not found for fieldable panels pane of type ' . $data['bundle'] . '. Fieldable panels pane was not created/reverted.', 'warning');
      }
      else {

        // If this is an update, there will be a by-UUID matching FPP.
        $existing = entity_get_id_by_uuid('fieldable_panels_pane', array(
          $data['uuid'],
        ));
        if (!empty($existing)) {
          $fpp = entity_load_single('fieldable_panels_pane', $existing[$data['uuid']]);
          foreach ($data as $key => $value) {
            $fpp->{$key} = $value;
          }
        }
        else {

          // Create a new FPP.
          $fpp = entity_create('fieldable_panels_pane', $data);
        }
        drupal_alter('uuid_entity_features_rebuild', $entity_type, $fpp, $data, $module);
        uuid_features_file_field_import($fpp, 'fieldable_panels_pane');
        if (!fieldable_panels_panes_save($fpp)) {
          drupal_set_message('Failed to create ' . $data['bundle'] . ' fieldable panels pane ' . $data['label'], 'error');
        }
      }
    }
    module_invoke_all('uuid_entity_features_rebuild_complete', $entity_type, $fpps, $module);
  }
}