You are here

function panelizer_uuid_entity_features_export_render_alter in UUID Features Integration 7

Implements hook_uuid_entity_features_export_render_alter().

File

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

Code

function panelizer_uuid_entity_features_export_render_alter($entity_type, &$export, &$entity, $module) {
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
  $handler = panelizer_entity_plugin_get_handler($entity_type);
  if (!$handler) {
    return;
  }
  if (panelizer_is_panelized($handler, $bundle) && !empty($export->panelizer)) {
    foreach ($export->panelizer as $view_mode => $panelize_settings) {

      // Only deal with the property if the panelizer has uuid support.
      if (!empty($panelize_settings->display->uuid)) {

        // Just export customized displays or bundles with a choice. All other
        // cases are automatically regenerated.
        if ($handler
          ->is_panelized($bundle, $view_mode) && ($handler
          ->has_panel_choice($bundle . '.' . $view_mode) || !empty($panelize_settings->did))) {

          // By default we just store the name of the selected display.
          if (!empty($panelize_settings->name)) {
            $export->panelizer[$view_mode] = array(
              'name' => $panelize_settings->name,
            );
          }
          elseif (!empty($panelize_settings->did)) {

            // This is a modified display, dependency to the configuration
            // should have been added. Now replace the did by it's uuid.
            // @see panelizer_uuid_entity_features_export_alter()
            $export->panelizer[$view_mode]->did_uuid = $panelize_settings->display->uuid;
            unset($export->panelizer[$view_mode]->did, $export->panelizer[$view_mode]->display, $export->panelizer[$view_mode]->entity_id, $export->panelizer[$view_mode]->revision_id);
          }
        }
        else {
          unset($export->panelizer[$view_mode]);
        }
      }
      else {
        unset($export->panelizer[$view_mode]);
      }
    }
  }

  // Remove unnecessary panelizer array.
  if (empty($export->panelizer)) {
    unset($export->panelizer);
  }
}