3

I have some custom PHP code that I would like to use as a selection rule for about 30 different variants. In the future, I may need to update this code, so rather than add the code 30 times, once for each variant, I would rather add it in code via a custom module so that I can more easily maintain it.

Is there a hook, etc. for adding Panels selection rules?

3

What you want is internally called an "Access plugin".

Check my example on How does one create a new Ctools plugin?.

The advantage of this approach is that you can get rid of the evil eval.

4

You can add Panels selection rules.

However, in your case, have you tried just calling a module function instead in your PHP code for the selection rule?

e.g, call a function defined in a module:

return my_module_selection_rule('foo');

instead of all the raw code there.

That way, it can be updated once in the module codebase.

I use that technique a lot for views php contextual filter handling code.

If so inclined, see

  • panels/plugins/task_handlers/panel_context.inc

for the default selection rules plugin definition. and

for the default form builder function for the selection rules.

  • nice recommendations! – Ehsan Mar 4 '15 at 14:13
0

You can make this by calling the function in your custom module. Lets say function is checkCondition() so you will have your code for selection rules return checkCondition(); and in the function you can set your condition to return true or false.

You can also do this for your content pane by adding visibility rule to it. Use php code for the same and call your checkCondition() function for it.

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.