Skip to content

Commit

Permalink
[FIX][W2439] Complex fields can now handle missing containers.
Browse files Browse the repository at this point in the history
  • Loading branch information
RadoslavGeorgiev committed May 15, 2018
1 parent 093822c commit e9ac277
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
4 changes: 4 additions & 0 deletions core/assets/sass/field/_complex.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@
.uf-boxed-fields .uf-complex-fields > .uf-fields-layout-rows {
margin-bottom: -1px;;
}

.uf-complex-group-missing {
padding: 0 10px;
}
8 changes: 8 additions & 0 deletions core/assets/sass/field/_wysiwyg.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@
display: block;
}
}

.uf-overlay-open .mce-menu {
z-index: 160011 !important; // Because of inline styles
}

.uf-overlay-open .media-modal {
z-index: 160011 !important; // Because of inline styles
}
37 changes: 28 additions & 9 deletions core/classes/Field/Complex.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ public function get_group() {
$group = new Complex_Group( 'complex_group' );
}

$group->set_layout( $this->layout );
if( ! $group ) {
return $this->group = false;
}

$group->set_layout( $this->layout );
return $this->group = $group;
}

Expand All @@ -196,7 +199,13 @@ public function get_group() {
*/
public function export_field() {
$settings = parent::export_field();
$settings[ 'group' ] = $this->get_group()->export_settings();

$group = $this->get_group();
if( $group ) {
$settings[ 'group' ] = $group->export_settings();
} else {
$settings[ 'group' ] = false;
}

return $settings;
}
Expand Down Expand Up @@ -268,9 +277,11 @@ public function save( $source ) {
$datastore = $this->get_internal_datastore();

# Put the values into a datastore
foreach( $this->get_group()->get_fields() as $field ) {
$field->set_datastore( $datastore );
$field->save( $source );
if( $this->get_group() ) {
foreach( $this->get_group()->get_fields() as $field ) {
$field->set_datastore( $datastore );
$field->save( $source );
}
}

# Save
Expand All @@ -289,9 +300,12 @@ public function export_data() {

# Go through fields and gather values
$data = array();
foreach( $this->group->get_fields() as $field ) {
$field->set_datastore( $datastore );
$data = array_merge( $data, $field->export_data() );

if( $this->group ) {
foreach( $this->group->get_fields() as $field ) {
$field->set_datastore( $datastore );
$data = array_merge( $data, $field->export_data() );
}
}

return array(
Expand Down Expand Up @@ -366,7 +380,12 @@ public function set_layout( $layout ) {
* @since 3.0
*/
public function enqueue_scripts() {
$this->get_group()->enqueue_scripts();
if( $this->get_group() ) {
$this->get_group()->enqueue_scripts();
} else {
ultimate_fields()->localize( 'complex-no-group', __( 'The group with the sub-fields of this field is missing.', 'ultimate-fields' ) );
}

wp_enqueue_script( 'uf-field-complex' );
}

Expand Down
35 changes: 30 additions & 5 deletions core/js/field/complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
});

// Generate the model
model = new UltimateFields.Container.Group.Model( this.get( 'group' ) );
model.setDatastore( this.values );

// Save a handle
this.set( 'groupModel', model );
if( this.get( 'group' ) ) {
model = new UltimateFields.Container.Group.Model( this.get( 'group' ) );
model.setDatastore( this.values );

// Save a handle
this.set( 'groupModel', model );
} else {
this.set( 'groupModel', false );
}
},

/**
Expand All @@ -40,6 +44,11 @@
validate: function() {
var errors, message;

// Check for a model
if( ! this.get( 'groupModel' ) ) {
return;
}

if( ! ( errors = this.get( 'groupModel' ).validate() ) ) {
return;
}
Expand All @@ -57,6 +66,10 @@
var values = [],
group = this.get( 'groupModel' );

if( ! group ) {
return '';
}

group.get( 'fields' ).each(function( field ) {
var value = field.getSEOValue();

Expand All @@ -77,6 +90,10 @@
// Do the standard initialization
field.View.prototype.initialize.apply( this, arguments );

if( ! this.model.get( 'groupModel' ) ) {
return;
}

// Listen for replacements
this.model.datastore.on( 'value-replaced', function( name ) {
if( name != that.model.get( 'name' ) ) {
Expand All @@ -98,6 +115,14 @@
// Create a group model
model = this.model.get( 'groupModel' );

if( ! model ) {
var $p = $( '<p />' );
$p.addClass( 'uf-complex-group-missing' );
$p.text( UltimateFields.L10N.localize( 'complex-no-group' ) );
this.$el.append( $p );
return;
}

// Create a view for the group and get the fields
view = new UltimateFields.Container.Group.ComplexView({
model: model
Expand Down

0 comments on commit e9ac277

Please sign in to comment.