You are here

function panopoly_magic_render_fieldable_panels_pane_preview in Panopoly Magic 7

Renders previews for fieldable_panels_pane content types.

1 string reference to 'panopoly_magic_render_fieldable_panels_pane_preview'
panopoly_magic_form_alter in ./panopoly_magic.module
Implements hook_form_alter()

File

./panopoly_magic.module, line 777

Code

function panopoly_magic_render_fieldable_panels_pane_preview($type, $subtype, $conf, $keywords, $args, $context, $extra) {
  $entity = $extra['fieldable_panels_pane'];

  // Prevents PHP notice when not admin user (see issue #2463389).
  if (!isset($entity->view_access)) {
    $entity->view_access = NULL;
  }
  if ($entity && fieldable_panels_panes_access('view', $entity)) {
    $settings = field_bundle_settings('fieldable_panels_pane', $entity->bundle);
    $block = new stdClass();
    $block->type = $type;
    $block->subtype = $subtype;
    $block->title = '';
    if (empty($settings['extra_fields']['display']) || !empty($settings['extra_fields']['display']['title']['default']['visible'])) {
      if (!empty($entity->title)) {
        $block->title = filter_xss_admin($entity->title);
      }
    }

    // Necessary to allow 'tablefield' to work per Issue #2479569, but it breaks
    // the Spotlight widget per Issue #2533064. So, for now, only run on the
    // Table widget.
    if ($entity->bundle == 'table') {
      _field_invoke('presave', 'fieldable_panels_pane', $entity);
    }

    // Some magic necessary to make sure fields are in the same state they
    // would be in if they were loaded from the database. Found this by looking
    // at how node generates it's previews in node_preview().
    _field_invoke_multiple('load', 'fieldable_panels_pane', array(
      $entity->fpid => $entity,
    ));
    $view_mode = isset($conf['view_mode']) ? $conf['view_mode'] : 'full';
    $block->content = fieldable_panels_panes_view($entity, $view_mode);
    return $block;
  }
}