Skip to content

Commit

Permalink
Merge pull request #3156 from pods-framework/feature/3155
Browse files Browse the repository at this point in the history
Fix related_act.permalink calls
  • Loading branch information
sc0ttkclark committed Nov 24, 2015
2 parents bf99b39 + 87fe822 commit 85a35e5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 38 deletions.
26 changes: 13 additions & 13 deletions classes/Pods.php
Expand Up @@ -1416,7 +1416,19 @@ public function field ( $name, $single = null, $raw = false ) {
// $field is 123x123, needs to be _src.123x123
$full_field = implode( '.', array_splice( $params->traverse, $key ) );

if ( ( ( false !== strpos( $full_field, '_src' ) || 'guid' == $field ) && ( in_array( $table[ 'type' ], array( 'attachment', 'media' ) ) || in_array( $last_type, PodsForm::file_field_types() ) ) ) || ( in_array( $field, array( '_link', 'detail_url' ) ) || in_array( $field, array( 'permalink', 'the_permalink' ) ) && in_array( $last_type, PodsForm::file_field_types() ) ) ) {
if ( is_array( $item ) && isset( $item[ $field ] ) ) {
if ( $table[ 'field_id' ] == $field )
$value[] = (int) $item[ $field ];
else
$value[] = $item[ $field ];
}
elseif ( is_object( $item ) && isset( $item->{$field} ) ) {
if ( $table[ 'field_id' ] == $field )
$value[] = (int) $item->{$field};
else
$value[] = $item->{$field};
}
elseif ( ( ( false !== strpos( $full_field, '_src' ) || 'guid' == $field ) && ( in_array( $table[ 'type' ], array( 'attachment', 'media' ) ) || in_array( $last_type, PodsForm::file_field_types() ) ) ) || ( in_array( $field, array( '_link', 'detail_url' ) ) || in_array( $field, array( 'permalink', 'the_permalink' ) ) && in_array( $last_type, PodsForm::file_field_types() ) ) ) {
$size = 'full';

if ( false !== strpos( $full_field, '_src.' ) && 5 < strlen( $full_field ) )
Expand Down Expand Up @@ -1473,18 +1485,6 @@ public function field ( $name, $single = null, $raw = false ) {

$params->raw_display = true;
}
elseif ( is_array( $item ) && isset( $item[ $field ] ) ) {
if ( $table[ 'field_id' ] == $field )
$value[] = (int) $item[ $field ];
else
$value[] = $item[ $field ];
}
elseif ( is_object( $item ) && isset( $item->{$field} ) ) {
if ( $table[ 'field_id' ] == $field )
$value[] = (int) $item->{$field};
else
$value[] = $item->{$field};
}
elseif ( in_array( $object_type, array( 'post', 'taxonomy', 'user', 'comment' ) ) ) {
$metadata_object_id = $item_id;

Expand Down
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Expand Up @@ -35,6 +35,10 @@ function _manually_load_plugin() {
add_filter( 'pods_error_die', '__return_false' );
add_filter( 'pods_error_exception', '__return_false' );

// Disable e-mails
add_filter( 'send_password_change_email', '__return_false' );
add_filter( 'send_email_change_email', '__return_false' );

require PODS_TEST_PLUGIN_FILE;
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
Expand Down
92 changes: 67 additions & 25 deletions tests/includes/testcase.php
Expand Up @@ -105,7 +105,8 @@ class Pods_UnitTestCase extends \WP_UnitTestCase {
),
'pod' => array(
'object' => array(
'%d'
'%d',
'test_act',
),
'storage' => array(
'table'
Expand All @@ -115,14 +116,25 @@ class Pods_UnitTestCase extends \WP_UnitTestCase {
'name' => 'name',
'type' => 'text'
),
array(
'name' => 'permalink',
'type' => 'slug'
),
array(
'name' => 'test_text_field',
'type' => 'test'
),
array(
'name' => 'author',
'type' => 'pick',
'pick_object' => 'user',
'pick_val' => '',
'pick_format_type' => 'single'
)
)
),
'data' => array(
'permalink' => 'test-slug-%s'
),
)
);

Expand Down Expand Up @@ -175,6 +187,13 @@ class Pods_UnitTestCase extends \WP_UnitTestCase {
'pick_val' => '',
'pick_format_type' => 'single'
),
array(
'name' => 'test_rel_act',
'type' => 'pick',
'pick_object' => 'pod',
'pick_val' => 'test_act',
'pick_format_type' => 'single'
),
array(
'name' => 'test_text_field',
'type' => 'text'
Expand Down Expand Up @@ -277,6 +296,18 @@ class Pods_UnitTestCase extends \WP_UnitTestCase {
'test_text_field' => 'Test related comment text field'
)
),
'test_rel_act' => array(
'pod' => 'test_act',
'id' => 0,
'field_index' => 'name',
'field_id' => 'id',
'field_author' => 'author',
'data' => array(
'name' => 'Related pod item',
'permalink' => 'related-pod-item',
'test_text_field' => 'Test related pod text field'
)
),
'avatar' => array(
'pod' => 'media',
'id' => 0,
Expand Down Expand Up @@ -595,9 +626,9 @@ public static function _initialize_data() {

// @todo In 3.x, we should be able to use pods() on any taxonomy outside of Pods


$related_author = 0;
$related_media = 0;
$related_avatar = 0;

// Get and store sample image for use later
$sample_image = pods_attachment_import( 'https://en.gravatar.com/userimage/3291122/028049e6b4e179bdc7deb878bbfced8f.jpg?size=200' );
Expand Down Expand Up @@ -633,7 +664,9 @@ public static function _initialize_data() {

// Add term id for the Non-Pod Taxonomy field
if ( 'post_type' == $p->pod_data[ 'type' ] ) {
$item_data[ 'data' ][ 'test_non_pod_ct' ] = self::$related_items[ 'test_non_pod_ct' ][ 'id' ];
$item_data[ 'data' ][ 'test_non_pod_ct' ] = (int) self::$related_items[ 'test_non_pod_ct' ][ 'id' ];
} elseif ( 'pod' == $p->pod_data[ 'type' ] ) {
$item_data[ 'data' ][ 'author' ] = $related_author;
}

if ( 'media' == $item_data[ 'pod' ] ) {
Expand Down Expand Up @@ -680,6 +713,9 @@ public static function _initialize_data() {
elseif ( 'test_rel_media' == $item ) {
$related_media = $id;
}
elseif ( 'avatar' == $item ) {
$related_avatar = $id;
}

$item_data[ 'id' ] = $id;

Expand Down Expand Up @@ -748,19 +784,19 @@ public static function _initialize_data() {
if ( in_array( $pod_type, array( 'post_type', 'media' ) ) ) {
$pod_item_data[ 'data' ][ 'post_author' ] = $related_author;
}
elseif ( 'user' == $pod_type ) {
$pod_item_data[ 'data' ][ 'post_author' ] = $related_author;
}
elseif ( 'comment' == $pod_type ) {
$pod_item_data[ 'data' ][ 'user_id' ] = $related_author;
}
elseif ( 'user' == $pod_type ) {
$pod_item_data[ 'data' ][ 'avatar' ] = $related_avatar;
}
elseif ( 'pod' == $pod_type ) {
$pod_item_data[ 'data' ][ 'author' ] = $related_author;
}

// Add term id for the Non-Pod Taxonomy field
if ( 'post_type' == $pod_type ) {
$pod_item_data[ 'data' ][ 'test_non_pod_ct' ] = self::$related_items[ 'test_non_pod_ct' ][ 'id' ];
$pod_item_data[ 'data' ][ 'test_non_pod_ct' ] = (int) self::$related_items[ 'test_non_pod_ct' ][ 'id' ];
}

$id = $p->add( $pod_item_data[ 'data' ] );
Expand All @@ -784,31 +820,37 @@ public static function _initialize_data() {
continue;
}

if ( is_array( $r_item_data[ 'id' ] ) ) {
foreach ( $r_item_data[ 'id' ] as $item_id ) {
$p = pods( $r_item_data[ 'pod' ], $item_id );
$r_item_data[ 'id' ] = (array) $r_item_data[ 'id' ];

$save_data = array_merge( $r_item_data[ 'sub_data' ][ $item_id ], $r_item_data[ 'sub_rel_data' ] );
$p = pods( $r_item_data['pod'] );

// Add term id for the Non-Pod Taxonomy field
// @todo This should be working on it's own
if ( 'post_type' == $p->pod_data[ 'type' ] ) {
$save_data[ 'test_non_pod_ct' ] = (int) self::$related_items[ 'test_non_pod_ct' ][ 'id' ];
}
foreach ( $r_item_data[ 'id' ] as $item_id ) {
$item_id = (int) $item_id;

$sub = false;

$p->save( $save_data );
if ( ! empty( $r_item_data[ 'sub_data' ][ $item_id ] ) ) {
$sub = true;

$save_data = array_merge( $r_item_data['sub_data'][ $item_id ], $r_item_data['sub_rel_data'] );
} else {
$save_data = $r_item_data['data'];
}
}
else {
$p = pods( $r_item_data[ 'pod' ], $r_item_data[ 'id' ] );

// Add term id for the Non-Pod Taxonomy field
// @todo This should be working on it's own
if ( 'post_type' == $p->pod_data[ 'type' ] ) {
$r_item_data[ 'data' ][ 'test_non_pod_ct' ] = (int) self::$related_items[ 'test_non_pod_ct' ][ 'id' ];
// Add term id for the Non-Pod Taxonomy field
// @todo This should be working on it's own
$save_data[ 'test_non_pod_ct' ] = (int) self::$related_items[ 'test_non_pod_ct' ][ 'id' ];
} elseif ( 'user' == $p->pod_data[ 'type' ] ) {
// Avatar gets added after user is added, have to add it back
$save_data[ 'avatar' ] = (int) self::$related_items[ 'avatar' ][ 'id' ];
}

if ( ! $sub ) {
self::$related_items[ $r_item ][ 'data' ] = array_merge( self::$related_items[ $r_item ][ 'data' ], $save_data );
}

$p->save( $r_item_data[ 'data' ] );
$p->save( $save_data, null, $item_id );
}
}

Expand Down

0 comments on commit 85a35e5

Please sign in to comment.