Skip to content

Commit

Permalink
Merge pull request #2766 from pods-framework/feature/2755-fix-related…
Browse files Browse the repository at this point in the history
…-display

Fix related field display
  • Loading branch information
sc0ttkclark committed Mar 1, 2015
2 parents 117c066 + c387b62 commit dbe852d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
33 changes: 17 additions & 16 deletions classes/Pods.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,15 @@ public function display ( $name, $single = null ) {
$value = $this->field( $params );

if ( is_array( $value ) ) {
$fields = $this->fields;

if ( isset( $this->pod_data[ 'object_fields' ] ) ) {
$fields = array_merge( $fields, $this->pod_data[ 'object_fields' ] );
}

$serial_params = array(
'field' => $params->name,
'fields' => $this->fields
'fields' => $fields
);

if ( !empty( $params->serial_params ) && is_array( $params->serial_params ) )
Expand Down Expand Up @@ -750,7 +756,7 @@ public function field ( $name, $single = null, $raw = false ) {
$value = get_comment_link( $this->id() );
}

$field_data = false;
$field_data = $last_field_data = false;
$field_type = false;

$first_field = explode( '.', $params->name );
Expand Down Expand Up @@ -1145,32 +1151,26 @@ public function field ( $name, $single = null, $raw = false ) {

// Tableless handler
if ( $field_exists && ( !in_array( $all_fields[ $pod ][ $field ][ 'type' ], array( 'pick', 'taxonomy' ) ) || !$simple ) ) {

$type = $all_fields[ $pod ][ $field ][ 'type' ];
$pick_object = $all_fields[ $pod ][ $field ][ 'pick_object' ];
$pick_val = $all_fields[ $pod ][ $field ][ 'pick_val' ];

if ( 'table' == $pick_object ) {

$pick_val = pods_v( 'pick_table', $all_fields[ $pod ][ $field ][ 'options' ], $pick_val, true );
}
elseif ( '__current__' == $pick_val ) {

$pick_val = $pod;
}

$last_limit = 0;

if ( in_array( $type, $tableless_field_types ) ) {

$single_multi = pods_v( "{$type}_format_type", $all_fields[ $pod ][ $field ][ 'options' ], 'single' );

if ( 'multi' == $single_multi ) {

$last_limit = (int) pods_v( "{$type}_limit", $all_fields[ $pod ][ $field ][ 'options' ], 0 );
}
else {

$last_limit = 1;
}
}
Expand All @@ -1185,11 +1185,10 @@ public function field ( $name, $single = null, $raw = false ) {

// Get related IDs
if ( !isset( $all_fields[ $pod ][ $field ][ 'pod_id' ] ) ) {

$all_fields[ $pod ][ $field ][ 'pod_id' ] = 0;
}
if ( isset( $all_fields[ $pod ][ $field ][ 'id' ] ) ) {

if ( isset( $all_fields[ $pod ][ $field ][ 'id' ] ) ) {
$ids = $this->api->lookup_related_items(
$all_fields[ $pod ][ $field ][ 'id' ],
$all_fields[ $pod ][ $field ][ 'pod_id' ],
Expand All @@ -1200,27 +1199,21 @@ public function field ( $name, $single = null, $raw = false ) {

// No items found
if ( empty( $ids ) ) {

return false;
} // @todo This should return array() if not $params->single
elseif ( 0 < $last_limit ) {

$ids = array_slice( $ids, 0, $last_limit );
}

// Get $pod if related to a Pod
if ( !empty( $pick_object ) && ( !empty( $pick_val ) || in_array( $pick_object, array( 'user', 'media', 'comment' ) ) ) ) {

if ( 'pod' == $pick_object ) {

$pod = $pick_val;
}
else {

$check = $this->api->get_table_info( $pick_object, $pick_val );

if ( !empty( $check ) && !empty( $check[ 'pod' ] ) ) {

$pod = $check[ 'pod' ][ 'name' ];
}
}
Expand Down Expand Up @@ -1533,6 +1526,10 @@ public function field ( $name, $single = null, $raw = false ) {
$value = current( $value );
}

if ( $last_options ) {
$last_field_data = $last_options;
}

break;
}
}
Expand All @@ -1555,6 +1552,10 @@ public function field ( $name, $single = null, $raw = false ) {
if ( $params->single && is_array( $value ) && 1 == count( $value ) )
$value = current( $value );

if ( ! empty( $last_field_data ) ) {
$field_data = $last_field_data;
}

// @todo Expand this into traversed fields too
if ( !empty( $field_data ) && ( $params->display || !$params->raw ) && !$params->in_form && !$params->raw_display ) {
if ( $params->display || ( ( $params->get_meta || $params->deprecated ) && !in_array( $field_data[ 'type' ], $tableless_field_types ) ) ) {
Expand Down
17 changes: 13 additions & 4 deletions classes/fields/pick.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,19 @@ public function schema ( $options = null ) {
public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
$fields = null;

if ( is_object( $pod ) && isset( $pod->fields ) && isset( $pod->pod_data[ 'object_fields' ] ) )
$fields = array_merge( $pod->fields, $pod->pod_data[ 'object_fields' ] );
elseif ( is_array( $pod ) && isset( $pod[ 'fields' ] ) )
$fields = array_merge( $pod[ 'fields' ], $pod[ 'object_fields' ] );
if ( is_object( $pod ) && isset( $pod->fields ) ) {
$fields = $pod->fields;

if ( ! empty( $pod->pod_data[ 'object_fields' ] ) ) {
$fields = array_merge( $fields, $pod->pod_data[ 'object_fields' ] );
}
} elseif ( is_array( $pod ) && isset( $pod[ 'fields' ] ) ) {
$fields = $pod[ 'fields' ];

if ( ! empty( $pod[ 'object_fields' ] ) ) {
$fields = array_merge( $fields, $pod[ 'object_fields' ] );
}
}

return pods_serial_comma( $value, array( 'field' => $name, 'fields' => $fields ) );
}
Expand Down

0 comments on commit dbe852d

Please sign in to comment.