0

Node add forms show some paper size options no matter who the user is, even regular authenticated users. It seems to be part of the Printer, email and PDF versions module.

I added the following code to my helper (let's call it my_helper) module, as suggested here:

/**
 * Implements hook_form_alter().
 */
function my_helper_form_alter(&$form, &$form_state, $form_id) {
  // Hiding the print fields that print.module puts into the node form.
  if (strpos($form_id, '_node_form') !== FALSE && !empty($form['print']['print_pdf'])) {
    foreach ($form['print']['print_pdf'] as &$print_field) {
      $print_field['#access'] = FALSE;
    }
  }
}

I am also using the Simplify module to hide certain form elements but this isn't coming up as an option there.

enter image description here

Edit: I looked at the system table in MySQL to see that the weight of the module was 0, so I added a .install file to change the weight to 10. But still not seeing an affect.

   function my_helper_update_7100() {
        db_update('system')
        ->fields(array('weight' => 10))
        ->condition('name', 'my_helper', '=')
        ->execute();
    }
8
  • Are you able to debug and see that the form structure was actually updated? Or that this code is being hit?
    – Kevin
    Aug 12 '17 at 0:37
  • I checked the module weight in MySQL after running the install and it's still set to 0. I think if I can get it to 10, it might work. But the .install just isn't doing it.
    – Christia
    Aug 12 '17 at 0:50
  • That is not effective - you need to know that the code is being hit, the condition is being entered, and that the form is updated. Without that, it is not worth checking on the weight of the module. Start with devel, dump the form before the end of the function and inspect the print items to see that they were actually set to FALSE
    – Kevin
    Aug 12 '17 at 0:51
  • I think this uses dpm() function somewhere right?
    – Christia
    Aug 12 '17 at 0:57
  • Yes, that is one of the functions
    – Kevin
    Aug 12 '17 at 0:59
0

Cross-posting my answer from drupal.org as these two pages are the first results in google. https://www.drupal.org/project/print/issues/2714635

I just fixed this on my works web site. The form alter code needs to be added in an #after_build callback as the paper size and orientation fields don't exist yet in the form array in using hook_form_alter. Here is a complete example.

/**
 * Implements hook_form_alter().
 */
function my_module_form_alter(&$form, &$form_state, $form_id) {

  // Hiding the print fields that print.module puts into the node form.
  if (strpos($form_id, '_node_form') !== FALSE) {
    $form['#after_build'][] = 'mhfa_pdf_form_alter_after_build_remove_print';
  }
}

/**
 * Remove pdf print controls.
 */
function my_module_form_alter_after_build_remove_print($form, &$form_state) {
  unset($form['print']);
  return $form;
}

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.