You are here

function panelizer_uuid_entity_features_rebuild_alter in UUID Features Integration 7

Implements hook_uuid_entity_features_rebuild_alter().

File

includes/modules/panelizer.inc, line 107
uuid features hooks on behalf of the panelizer module.

Code

function panelizer_uuid_entity_features_rebuild_alter($entity_type, &$entity, $data, $module) {
  static $modified_displays_rebuilt;
  if (!empty($entity->panelizer)) {
    foreach ($entity->panelizer as $view_mode => $panelizer_settings) {

      // This was an modified display. Ensure those are imported.
      if (!empty($panelizer_settings['did_uuid'])) {
        if (empty($modified_displays_rebuilt)) {
          $modified_displays_rebuilt = TRUE;
          uuid_panelizer_features_rebuild($module);
        }

        // Fetch display and set it.
        $did = db_query("SELECT did FROM {panels_display} WHERE uuid = :uuid", array(
          ':uuid' => $panelizer_settings['did_uuid'],
        ))
          ->fetchField();
        if ($did) {
          $entity->panelizer[$view_mode] = (object) $entity->panelizer[$view_mode];
          $entity->panelizer[$view_mode]->did = $did;
          $entity->panelizer[$view_mode]->display = panels_load_display($did);
        }
      }
      elseif (count($panelizer_settings['name']) == 1 && !empty($panelizer_settings['name'])) {

        // This uses a the default panelizer configuration restore it.
        list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
        $handler = panelizer_entity_plugin_get_handler($entity_type);
        $entity->panelizer[$view_mode] = $handler
          ->get_default_panelizer_object($bundle . '.' . $view_mode, $panelizer_settings['name']);
        $entity->panelizer[$view_mode]->did = NULL;
        list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);

        // Ensure these variables are set - if not panelizer will try to insert
        // instead update in certain cases.
        $entity->panelizer[$view_mode]->entity_id = $entity_id;
        $entity->panelizer[$view_mode]->revision_id = $revision_id;
      }
    }
  }
}