Hi,

At the moment, if you're in a custom form_alter hook it's difficult to find out whether a form is being rendered in the block.

I've attached a small patch which adds $form['#formblock'] = TRUE to the form array if it's currently being rendered by formblock.

This means module developers have a much easier way to handle special cases.

Cheers,
Nick

Comments

__mark’s picture

Thanks a million, this functionality makes this module a whole lot more usable for me. However, this is what was returned by applying to the latest dev release:

patching file formblock.module
Hunk #1 succeeded at 28 with fuzz 1 (offset 8 lines).
Hunk #2 FAILED at 63.
Hunk #3 succeeded at 106 (offset 30 lines).
Hunk #4 FAILED at 130.
Hunk #5 FAILED at 144.
3 out of 5 hunks FAILED -- saving rejects to file formblock.module.rej
nicksanta’s picture

StatusFileSize
new3.04 KB

Oh right, silly me. That patch was against the latest stable release. I'll try rolling it again.

__mark’s picture

Awesome, thanks. I tried manually applying the patch before you posted this, but got an error.

Patch doesn't work for me. formblock_current_form() is returning type instead of type_node_form in the form_alter. I'll post what else I find...

__mark’s picture

I've only tried this for one node form so far, but this is a fix that added the #formblock attribute to my form:

line 31 was:

  if (formblock_current_form() == $form_id) { 
   // Let other modules know this form is being displayed in a block.
    $form['#formblock'] = TRUE;
  }

line 31 after:

$node_type = formblock_current_form();
  	if ($node_type.'_node_form' == $form_id) { 
   // Let other modules know this form is being displayed in a block.
    $form['#formblock'] = TRUE;
  }
nicksanta’s picture

Status: Active » Needs review
StatusFileSize
new3.09 KB

Try this one. I didn't realise the block delta was just the node type rather than the full form_id.

Against latest dev snapshot.

greg boggs’s picture

I needed a way to attach created nodes to the node they were created from in D7... this code can be modified with your content type names and field name to do it.

/**
 * Implements node_presave to attach the current node's nid as an entity reference in the node being saved in a block form.
 * This code requires 'journal_entry' form to be embedded on a 'course' with the formblock module and the journal_entry type must     
 * have an entity reference field called 'field_course_reference'
 */
function ugc_node_presave($node) {
 
  $journal_wrapper = entity_metadata_wrapper('node', $node);
  if($journal_wrapper->getBundle() == 'journal_entry') {
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $course_node = node_load(arg(1));
      $course_wrapper =  entity_metadata_wrapper('node', $course_node);
      if($course_wrapper->getBundle() == 'course') {
        $course_nid = intval($course_wrapper->nid->value());
        $journal_wrapper->field_course_reference->set($course_nid);
      }
    }
  }
 
  return $node;
}
mikey_p’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

I haven't seen any interest on this issue in awhile and it's filed against 6.x which is currently unsupported, so I'm closing this for now.