Skip to content
Browse files

loop through connection types and existing connections instead of thr…

…ough POST data directly. fixes #49
  • Loading branch information...
1 parent bf07cd5 commit 7b20588d95632b4b4120552ff8e2d738d6f16376 @scribu committed
Showing with 14 additions and 8 deletions.
  1. +7 −3 admin/base.php
  2. +2 −1 admin/box.php
  3. +2 −3 admin/fields.php
  4. +2 −0 admin/templates/box.html
  5. +1 −1 scb
View
10 admin/base.php
@@ -79,13 +79,17 @@ static function save_post( $post_id, $post ) {
return;
// Custom fields
- if ( isset( $_POST['p2p_meta'] ) ) {
- foreach ( $_POST['p2p_meta'] as $ctype_id => $data ) {
+ if ( isset( $_POST['p2p_ctypes'] ) ) {
+
+ foreach ( $_POST['p2p_ctypes'] as $ctype_id ) {
$ctype = p2p_type( $ctype_id );
if ( !$ctype )
continue;
- foreach ( $data as $p2p_id => $data ) {
+ foreach ( $ctype->get_connected( $post_id )->posts as $post ) {
+ $p2p_id = $post->p2p_id;
+ $data = scbForms::get_value( array( 'p2p_meta', $p2p_id ), $_POST, array() );
+
foreach ( $ctype->_metabox_args->fields as $key => $field_args ) {
if ( 'checkbox' == $field_args['type'] ) {
if ( isset( $data[$key] ) )
View
3 admin/box.php
@@ -56,7 +56,7 @@ protected function init_columns() {
);
foreach ( $this->args->fields as $key => $data ) {
- $this->columns[ $key ] = new P2P_Field_Generic( $data, $this->ctype->id );
+ $this->columns[ $key ] = new P2P_Field_Generic( $data );
}
if ( method_exists( $this->ctype, 'get_orderby_key' ) ) {
@@ -71,6 +71,7 @@ function render( $post ) {
$this->connected_posts = $this->ctype->get_connected( $post->ID, $qv )->posts;
$data = array(
+ 'ctype-id' => $this->ctype->id,
'attributes' => $this->render_data_attributes(),
'connections' => $this->render_connections_table( $post ),
'create-connections' => $this->render_create_connections( $post ),
View
5 admin/fields.php
@@ -109,8 +109,7 @@ class P2P_Field_Generic implements P2P_Field {
protected $data;
- function __construct( $data, $ctype_id ) {
- $this->ctype_id = $ctype_id;
+ function __construct( $data ) {
$this->data = $data;
}
@@ -131,7 +130,7 @@ function render( $key, $p2p_id, $post_id ) {
$form = new scbForm(
array( $key => p2p_get_meta( $p2p_id, $key, $single_value ) ),
- array( 'p2p_meta', $this->ctype_id, $p2p_id )
+ array( 'p2p_meta', $p2p_id )
);
return $form->input( $args );
View
2 admin/templates/box.html
@@ -1,3 +1,5 @@
+<input type="hidden" name="p2p_ctypes[]" value="{{ctype-id}}" />
+
<div class="p2p-box" {{attributes}}>
{{#connections}}
<table class="p2p-connections" {{{hide}}}>
2 scb
@@ -1 +1 @@
-Subproject commit 4037d8dc09c7d44164f426d68515a30c5d65b845
+Subproject commit 7267fe5a7c6cf409bad8cead7a7190b04ac6355d

0 comments on commit 7b20588

Please sign in to comment.
Something went wrong with that request. Please try again.