3

I have a content type A How can I add custom theme to edit page of that content type A in drupal 7 only for specific role ?
In my module,

function hook_form_alter(&$form,&$form_state,$form_id) {
if (form_id == 'content_type_a') {
global $user;

if (in_array('rad',$user->roles)) {
$form['#theme'][] = 'custom_content_type_a_node_form';
}
}
}

In my template.php file I have the following code

function hook_theme() {
  return array(
    'custom_content_type_a_node_form' => array(
      'variables' => array('form' => NULL),
    );
  );
}

function THEMENAME_custom_content_type_a_node_form($form) {
// When I check here for $form I get an empty value 
// I want to get the $form value derived from the form_alter function's $form //variable . How can I achieve it?




}

How can I retrieve the $form value from the hook_form_alter's $form variable?

3

Try something like this:

function hook_theme() {
  return array(
    'custom_content_type_a_node_form' => array(
      'render element' => 'form',
    );
  );
}

function THEMENAME_custom_content_type_a_node_form($variables) {
  dpm($variables);
}
  • but will it give me $form from hook_form_alter ? – harshal Dec 26 '13 at 12:45
  • the above code using 'render element' does not work . The problem which occurs is th node edit page does not load and keeps on loading – harshal Dec 26 '13 at 12:59
  • 1
    @harshal This is correct - you'll find the render element (the form) in $variables['form'] – Clive Dec 26 '13 at 13:04
  • 2
    You'll get the form that you attached the theme function to, so yes – Clive Dec 26 '13 at 13:06
  • 1
    @harshal I figured out.. You need to call #theme like this: array_unshift($form['#theme'], 'custom_content_type_a_node_form') – xurshid29 Dec 26 '13 at 13:10

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.