summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Starbow2009-01-13 00:14:49 (GMT)
committerTao Starbow2009-01-13 00:14:49 (GMT)
commit32a48eb1386ece3395e2e8d2970a0464820cf90f (patch)
tree9152774b464c12bcbcd4e2597e3a30529c499ef6
parent0d43882ef55ee1d92d094e863bc5fc4fd73dc2f4 (diff)
* Getting collapsable fieldsets working for in autofill popups.
* http://drupal.org/node/345353: Getting autofill working w/out page refresh.
-rw-r--r--CHANGELOG.txt6
-rw-r--r--popups_reference.module87
2 files changed, 54 insertions, 39 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
new file mode 100644
index 0000000..14663cb
--- /dev/null
+++ b/CHANGELOG.txt
@@ -0,0 +1,6 @@
+5.x-1.0-beta2
+Bug Fixes
+ * Getting collapsable fieldsets working for in autofill popups.
+ * http://drupal.org/node/345353: Getting autofill working w/out page refresh.
+Notes
+ * Needs Popups API 1.0-beta2 or better. \ No newline at end of file
diff --git a/popups_reference.module b/popups_reference.module
index c6cf7de..6df01eb 100644
--- a/popups_reference.module
+++ b/popups_reference.module
@@ -6,39 +6,6 @@
* Modify the Node Reference widget to use a popup to add a new node.
*/
-function _popups_reference_counter() {
- static $count = 0;
- return $count++;
-}
-
-/**
- * Generates 'Add new...' link
- * for each allowed content type
- */
-function _popups_reference_links($field, $src_type, $id=null) {
- if ($id) { // Creating link to select box.
- $pclass = $id;
- // Target just the select box for replacing.
- popups_add_popups(array('.'.$pclass=>array(
- 'targetSelectors'=>array('#'.$id),
- 'behaviors' => array("Drupal.popups.collapsibleBehavior"),
- )));
- }
- else { // Creating link to autofill box.
- $pclass = 'popups';
- popups_add_popups();
- }
- $links = array();
- $all_types = node_get_types();
- foreach ($field['referenceable_types'] as $type => $value) {
- if (!empty($value) && user_access("create $type content")) {
- $path = "node/add/$type";
- $links[] = l("Add $type", $path, array('class' => $pclass), "destination=node/add/$src_type");
- }
- }
- return $links;
-}
-
/**
* Implementation of hook_form_alter().
*/
@@ -46,13 +13,14 @@ function popups_reference_form_alter($form_id, &$form) {
if (isset($form['type'])) {
$node = $form['#node'];
if ($form['type']['#value'] .'_node_form' == $form_id) {
-//firep($form_id, 'form_id');
+//dsm($form_id, 'form_id');
$fields = content_fields();
+// dsm($form);
foreach ($form as $key => $item) {
//firep($key);
if (is_array($item)) {
- // firep($item['#type'], $key);
$type = $item['#type'];
+// dsm("$key, $type");
if ($type == 'fieldset') { // loop through all the subitems.
// firep($item, $key);
foreach ($form[$key] as $subkey => $subitem) {
@@ -71,12 +39,13 @@ function popups_reference_form_alter($form_id, &$form) {
function popups_reference_alter_item(&$form, $key, $item, $fields) {
-//firep($key .', '. $field_name .', '. $fields[$field_name] .', '. $fields[$field_name]['type']);
$field_name = strstr($key, 'field_');
+//dsm($key .', '. $field_name .', '. $fields[$field_name] .', '. $fields[$$field_name]['type']);
+//dsm($key .', '. $field_name .', '. $fields[$field_name] .', '. $fields[$field_name]['type']);
if (isset($fields[$field_name]) && $fields[$field_name]['type'] == 'nodereference') {
$type = $form['type']['#value'];
$field = content_fields($field_name, $form['type']['#value']);
-//firep($field['widget']['type']);
+//dsm($key .', '. $field['widget']['type']);
if ($field['widget']['type'] == 'nodereference_select') {
$id = 'popups-reference-' . _popups_reference_counter();
@@ -87,11 +56,51 @@ function popups_reference_alter_item(&$form, $key, $item, $fields) {
}
else if ($field['widget']['type'] == 'nodereference_autocomplete') {
- $links = _popups_reference_links($field, $type, $id);
+ $links = _popups_reference_links($field, $type);
$form[$key]['#suffix'] = '<div>Add New: ' . implode(', ', $links) .'</div>';
}
}
}
-
+/**
+ * Generates 'Add new...' link
+ * for each allowed content type
+ */
+function _popups_reference_links($field, $src_type, $id=null) {
+ if ($id) { // Creating link to select box.
+ $pclass = $id;
+ // Target just the select box for replacing.
+ popups_add_popups(
+ array('.'.$pclass=>array(
+ 'targetSelectors' => array('#'.$id), // Only reload the select box element.
+ 'behaviors' => array("Drupal.popups.collapsibleBehavior"),
+ ))
+ );
+ }
+ else { // Creating link to autofill box.
+// $pclass = 'popups';
+// popups_add_popups();
+ $pclass = 'popups-reference-autofill';
+ popups_add_popups(
+ array('.'.$pclass=>array(
+ 'noReload' => TRUE, // Don't refresh the original page.
+ 'behaviors' => array("Drupal.popups.collapsibleBehavior"),
+ ))
+ );
+ }
+ $links = array();
+ $all_types = node_get_types();
+ foreach ($field['referenceable_types'] as $type => $value) {
+ if (!empty($value) && user_access("create $type content")) {
+ $path = "node/add/$type";
+ $links[] = l("Add $type", $path, array('class' => $pclass), "destination=node/add/$src_type");
+ }
+ }
+ return $links;
+}
+
+function _popups_reference_counter() {
+ static $count = 0;
+ return $count++;
+}