Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tkuldeep17’s picture

Yes, You can use panelizer on a field_collection it. Can you please explain, what problem you had faces..?

SocialNicheGuru’s picture

on a content type panelizer option shows on the edit page.
There is no edit tab for a field_collection.
I have a feeling there might be a panelizer admin page that I should be viewing and maybe the field collections will be there

drupalninja99’s picture

I have downloaded 3x dev and I still don't see field collections as an option at /admin/config/content/panelizer. Am I doing something wrong or are field collections not able to be panelized?

DamienMcKenna’s picture

Title: Can I panelize a field_collection? » Panelizer support for field_collection?
Project: Panelizer » Field collection
Version: 7.x-3.x-dev » 7.x-1.x-dev
Category: Support request » Feature request
Issue summary: View changes

Lets move this over to the Field Collection issue queue.

DamienMcKenna’s picture

Take a look at the #1820442: Panelizer for Comments for an example on how integration was built for the Comment entity.

DamienMcKenna’s picture

osopolar’s picture

@tkuldeep17: May you be so kind and describe how to get panelizer work on field-collection? Thanks.

osopolar’s picture

Status: Active » Needs review
FileSize
3.96 KB

Here comes the ctools entity plugin. It took me some hours to get it work, because I overlooked that the entity type is actually field_collection_item.

I still get this warning on the panelizer page (admin/structure/panelizer) in case of Full page override:

Note: "field_collection_item_view" display must be enabled in Page Manager in order for the field_collection_item full page display ("Full page override") to work correctly.

But field_collection_item_view does not yet appear in the Page Manager. I must have missed something, but can't see it right now. EDIT: Now I see, this also would require a task handler to handle the "field_collection_item override task". Hm, this is too much for now and it seems not to be necessary unless someone who needs Full page override.

Any reviews would be greatly appreciated. I guess there is some stuff missing, like determining if revisions are allowed.

osopolar’s picture

Without Page Manager and Revision support.

Status: Needs review » Needs work

The last submitted patch, 9: field_collection-panelizer-integration-2422979-9.patch, failed testing.

osopolar’s picture

Status: Needs work » Needs review
FileSize
3.53 KB

Now the two patches in one.

osopolar’s picture

I added task handler (field_collection_item_view.inc) to the patch.

There is one thing missing which I really need but didn't get to work is a relationship handler for field-collection to host entity. As this is not really necessary to use field-collection with panelizer I will create a follow up issue for that. It would be really cool if these days anybody could help me with that, thanks: #2567585: Ctools relationship plugin to add host entity context to field_collection panels

osopolar’s picture

Title: Panelizer support for field_collection? » Add Panels and Panelizer support for field_collections
osopolar’s picture

FIX variable name to get rid of note:

Note: "field_collection_item_view" display must be enabled in Page Manager in order for the field_collection_item full page display ("Full page override") to work correctly.
maximpodorov’s picture

https://www.drupal.org/project/entity_panels which supports Field Collections can be used also.

NWOM’s picture

Thanks for your work! I'm not sure if I'm using the patch though properly.

Basically my goal was to override the field collection edit form with panelizer, so that when I add the form field to a panelized node edit page, it will display the panelized field collection form, rather than the default. It currently doesn't seem to work. Thanks in advanced for the help!

DamienMcKenna’s picture

Just to mention it, Panelizer isn't designed for customizing entity edit forms, just the view modes, you should be using Panels for the edit form.

NWOM’s picture

@DamienMcKenna: I started only recently working with Panels starting with the Panopoly distribution in combination with Panels Everywhere, Panelizer, and Page Manager Existing Pages. I more than likely didn't realize what was providing what. I appreciate the info :)

osopolar’s picture

In addition to Panelizer support:

In case somebody wants to add lokal tasks (tabs) to edit the host entity while viewing a field-collection item, it could be done with following code in a custom module:


/**
 * Implements hook_menu().
 */
function custom_module_menu() {
  // Add menu paths for viewing/editing/deleting field collection items.
  foreach (field_info_fields() as $field) {
    if ($field['type'] == 'field_collection') {
      $path = field_collection_field_get_path($field);
      $count = count(explode('/', $path));

      $items[$path . '/%field_collection_item/edit-host'] = array(
        'title callback' => 'custom_module_field_collection_host_edit_title',
        'title arguments' => array($count),
        'page callback' => 'custom_module_goto_field_collection_host_edit_page',
        'page arguments' => array($count),
        'access callback' => 'entity_access',
        'access arguments' => array('update', 'field_collection_item', $count),
        'title' => 'Edit Host',
        'type' => MENU_LOCAL_TASK,
        'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
      );
    }
  }

  return $items;
}

/**
 * Menu title callback for edit field_collection host entity.
 *
 * @return string
 *   The menu title
 */
function custom_module_field_collection_host_edit_title($fc_item) {
  $label = '';

  $host_entity_type = $fc_item->hostEntityType();
  $host_entity = $fc_item->hostEntity();
  $host_entity_bundle = $fc_item->hostEntityBundle();

  $info = entity_get_info($host_entity_type);

  // A bundle-specific callback takes precedence over the generic one for the
  // entity type.
  if (isset($info['bundles'][$host_entity_bundle]['label'])) {
    $label = t('Edit @bundle-label', array('@bundle-label' => $info['bundles'][$host_entity_bundle]['label']));
  }
  else {
    $label = t('Edit Host Entity');
  }

  return $label;
}

/**
 * Page callback for edit field_collection host entity.
 *
 * @see entity_uri().
 */
function custom_module_goto_field_collection_host_edit_page($fc_item) {
  $host_entity_type = $fc_item->hostEntityType();
  $host_entity = $fc_item->hostEntity();

  $property_info = entity_get_property_info($host_entity_type);

  $goto_url = '';
  if (isset($property_info['properties']['edit_url']['getter callback'])) {
    $callback = $property_info['properties']['edit_url']['getter callback'];
    if (function_exists($callback)) {
      $goto_url = $callback($host_entity, array(), 'edit_url', $host_entity_type);
    }
  }

  if (!$goto_url) {
    // Fallback if edit url is unknown: At least redirect to host entity,
    // there might be an edit tab.
    $goto_url = entity_uri($host_entity_type, $host_entity);
  }

  if ($goto_url) {
    drupal_goto($goto_url, array('query' => drupal_get_destination()));
  }
  else {
    drupal_not_found();
  }
}

If module maintainer are interested in a patch for field-collection module I could provide that too.

osopolar’s picture

Re-roll patch as if ($module == 'ctools') { was changed to if ($module === 'ctools') {.