2

For a new project I'm starting, Panels+Panelizer seems a very good fit, but I'm still figuring out how to do some advanced things with it.

I like the fact that you can define the default layout and content panes for a certain node type, and allow the editor to override the default panes per node.

In some cases I want the layout and content panes to be dependent on certain conditions. For instance, if the date field on a node is not empty, I want a calendar pane in the right column; otherwise I want a 'related news' pane.

I have read about visibility rules, but the options seem rather limited (eg. there is no "not empty" condition for fields) and it does not allow you to change the layout completely. Which other methods exist make the default layout and content panes depend on certain conditions (other than the node type)?

2

Visibility rules are the way to go.

Granted the built in ones are not always as sophisticated as one might like at times, but on the other hand, access plugins are among the easiest to do on your own, allowing you arbitrary conditions.

See What are Ctools plugin (content type, access, etc), and how does one create them? for a example of how to implement one.

It can also be worthwhile checking the Ctools issue queue for a plugin that matches your requirements. Development of Ctools has almost gone away with all the active contributors working on D8 instead, but I have found useful patches in the queue.

  • That's a great link, thank you. I'll search the issue queue and report back if it brings something useful. – marcvangend Dec 4 '14 at 10:08
  • Also: you can get extra 'conditions' by adding contexts. – Darvanen Dec 4 '14 at 12:45
1
+50

To change the layout, you need to add multiple layout under :

Admin > Structure > Types > Manage > Content Type > Panelizer > page_manager

It will look like :

enter image description here

And you need to create custom access callback plugin as per Letharion's answer.

  • Thanks, I missed the fact that there are access rules on the level of a panel. I experimented with multiple panels with access rules and it seems very useful. The only problem with this approach, is that I cannot control the order in which the multiple panels (and their access rules) are processed. For this to be reliable, I need to control which panel is considered first, which comes second/third/etc, and which one is the fallback. Is there a way to control the order? – marcvangend Dec 4 '14 at 10:07
  • Dont know if there is way in panelizer. – Sumit Madan Dec 4 '14 at 10:17
  • May be by the order in which u add. – Sumit Madan Dec 4 '14 at 10:19
0

Although the answers given by Letharion and Sumit Madan did help me understand how panels and panelizer work, I did not manage to solve my problems using access/visibility rules.

Once you enable multiple panelizer displays for a certain node type, you get to choose which display you want to use on the node edit form. It seems that the access rules have no effect after this, because the choice made on the node edit form takes precedence.

I ended up solving this with a hook_node_validate() implementation which analyzes the form values to decide which panelizer display must be used to display the node. The correct display is then set on the form like this:

form_set_value($form['panelizer']['page_manager']['name'], 'node:news:pressrelease', $form_state);

An additional form alter makes sure that editors can no longer edit this setting:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mymodule_form_news_node_form_alter(&$form, &$form_state, $form_id) {
  $form['panelizer']['page_manager']['name']['#disabled'] = TRUE;
  $form['panelizer']['#weight'] = 200;
  $form['panelizer']['page_manager']['name']['#description'] = t('The panelizer display will be chosen automatically, based on the selected News Type.');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.