Using function phptemplate_node_form($form) I can override parts of the default Drupal node add/edit form. (I use this to change things like Groups to Access Groups and to re-order the fieldsets.)

When I override the default node edit/add forms using Panels, is there an equivalent function to phptemplate_node_form for Panels?

Comments

ianchan’s picture

Status: Active » Closed (fixed)

Bad subject line - closing and re-posting... sorry!

pendashteh’s picture

Title: Overrider Panels > General Node Form via template.php » THEME_node_form() is not applied when the form is called whitin a Panel
Version: 5.x-2.0-rc1a » 6.x-3.7
Status: Closed (fixed) » Active

here is the problem:

i have a THEME_them() that makes drupal uses form-node.tpl.php to theme a form. but this does not happen when the form is called from a Panel.

function THEME_theme($existing, $type, $theme, $path) {
	$templates = array(
		'node_form' => array(
			'arguments' => array('form' => NULL),
			'template' => 'form-node',
		),
	);
	return $templates;
}

how could i have a .tpl.php file to theme a form which is called from a Panel?

merlinofchaos’s picture

Status: Active » Closed (works as designed)

You can't. They're not compatible techniques, you cannot use them together.

pendashteh’s picture

Priority: Normal » Major
Status: Closed (works as designed) » Closed (won't fix)

ok, i read the panels.module and ctools.module carefully.
here is what i found about the problem:

assume you have created a panel for replacing node/%/edit pages.
and your panel have got two panes. the first for your node form and the other for a simple block for example.

simple say, Panels renders your form with theme_markup($form); not with theme_node_form($form); nor with whatever you has defined.
then after rendering all panes it renders whole panel with theme_form(); just to wrap the output with form tag

according above:

  • there is no way you could define a theme for your node form because there should be no form tag inside individual panes.
  • make sure there is no form in your other panes; e.g. you should not use a formblock block. because it leads to nested form elements.

final note:

i think the way that Panels handles form pages, wrapping whole panel with form tag, is not a appropriate at all.
it is enough to let the form be rendered inside the pane. or at least let user choose the behaiviour.

i mark this as major priority because the user have no chance to theme the form and this makes node edit panel pages mostly unusable.

feature request

change the behavior of form panels so form renders inside panes. by doing this users may use other forms in other panes and they can have control over form theming and managing fields.

pendashteh’s picture

a trick to take control over the form:

function THEME_markup($el) {
	if (isset($el['#form_context_id'])) {
		$el['#after_build'][] = 'THEME_node_form_after_build';
	}
	return theme_markup($el);
}
function THEME_node_form_after_build($form, &$form_state) {
	// play with fieldgroups, etc.
	return $form;
}
sigent’s picture

no-no, that's misstep.

"theme_markup" works with the fully rendered form and does nothing except this:
"
function theme_markup($element) {
return (isset($element['#value']) ? $element['#value'] : '') . (isset($element['#children']) ? $element['#children'] : '');
}
"

what i do is overriding the function
THEME_panels_render_display_form(&$form)
(originally it's a very tiny function, check panels.module file)

the needed data are deep inside the variable:
form data - $form['#display']->context[argument_node_edit_1]->form;
form id - $form['form_id']['#value']

!!! be careful this function was changed between panels 3.6 and 3.7
(i had to fix it a little too -- re-copy original code from panels.module)

Mark F’s picture

Ok, so I'm stuck! I themed the form with panels disabled for the node/edit page. When I re-enabled panels node/edit page, back to the original form. This is when I stumbled upon your post!

So, in #6, I changed (in template.php) THEME_node_form to THEME_panels_render_display_form, and also changed the hook to the same. I am now back at the point where panels appears to be disabled - no panels formatting. I guess I'm missing something. Any clues?

merlinofchaos’s picture

My response in #3 covers it.

You can't both theme the node form and use Panels, because it uses the theming layer to do its job.

Mark F’s picture

Thanks for wrapping that one up for me! Could have been on for days!

merlinofchaos’s picture

FYI, a lot of what you would normally want to accomplish using theme_node_form you can accomplish with a hook_form_alter instead, I think. Ideally, you use the panel to do most of the actual theming and the form_alter to move stuff around or add it.

For some purposes, you can also create mini content type plugins to handle moving form items around that Panels doesn't know about/support. Look in ctools/content_types/node_form -- mostly it's just a cut & paste job and figuring out what the items are referred to in the form.