Skip to content

Commit

Permalink
Merge pull request pods-framework#3437 from pods-framework/feature/su…
Browse files Browse the repository at this point in the history
…pport-pods-fields-object-fields

Support object fields when using Pods::field() with a specific $field and $option
  • Loading branch information
sc0ttkclark committed Mar 4, 2016
2 parents 81d493a + c7044b5 commit a6e3e9d
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions classes/Pods.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,29 +483,37 @@ public function input( $field, $input_name = null, $value = '__null' ) {
* @since 2.0
*/
public function fields ( $field = null, $option = null ) {
// No fields found
if ( empty( $this->fields ) )

$field_data = null;

if ( empty( $this->fields ) ) {
// No fields found
$field_data = array();
// Return all fields
elseif ( empty( $field ) )
} elseif ( empty( $field ) ) {
// Return all fields
$field_data = (array) $this->fields;
// Field not found
elseif ( !isset( $this->fields[ $field ] ) )
} elseif ( ! isset( $this->fields[ $field ] ) && ! isset( $this->pod_data['object_fields'][ $field ] ) ) {
// Field not found
$field_data = array();
// Return all field data
elseif ( empty( $option ) )
$field_data = $this->fields[ $field ];
else {
} elseif ( empty( $option ) ) {
// Return all field data
if ( isset( $this->fields[ $field ] ) ) {
$field_data = $this->fields[ $field ];
} elseif ( isset( $this->pod_data['object_fields'] ) ) {
$field_data = $this->pod_data['object_fields'][ $field ];
}
} else {
// Merge options
$options = array_merge( $this->fields[ $field ], $this->fields[ $field ][ 'options' ] );

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

// Get a list of available items from a relationship field
if ( 'data' == $option && in_array( pods_var_raw( 'type', $options ), PodsForm::tableless_field_types() ) ) {
$field_data = PodsForm::field_method( 'pick', 'get_field_data', $options );
}
// Return option
} // Return option
elseif ( isset( $options[ $option ] ) ) {
$field_data = $options[ $option ];
}
Expand Down

0 comments on commit a6e3e9d

Please sign in to comment.