Skip to content

Commit

Permalink
The duplicating in Options Builder works incorrectly - fixed issue #200
Browse files Browse the repository at this point in the history
  • Loading branch information
alexxgermann committed Oct 13, 2016
1 parent e2c8b31 commit 2ce9b6c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runway-framework/framework/includes/load-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1400,4 +1400,4 @@ function get_runway_wp_filesystem( $url = null ) {
endif;

// Uncomment this filter if wish to use 'direct' filesystem method within framework and extensions
//add_filter( 'rf_use_direct_filesystem_method', '__return_true' );
add_filter( 'rf_use_direct_filesystem_method', '__return_true' );
27 changes: 27 additions & 0 deletions runway-framework/framework/includes/options-builder/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,33 @@ function get_copy_alias( $alias ) {
$page->settings->alias = $alias_;

$page_json = json_encode( $page );

foreach ( $page->elements as $element ) {
// replace indexes
if ( is_object( $element ) && property_exists( $element, 'index' ) ) {
$old_index = $element->index;
$new_index = $apm->make_ID();
$page_json = str_replace( '"' . $old_index . '"', '"' . $new_index . '"', $page_json );

// replace aliases
if ( $element->template === 'field' ) {
$old_el_alias = $element->alias;
$new_el_alias = $old_el_alias . '-copy';
$page_json = str_replace(
array(
'"alias":"' . $old_el_alias . '"',
'"conditionalAlias":"' . $old_el_alias . '"'
),
array(
'"alias":"' . $new_el_alias . '"',
'"conditionalAlias":"' . $new_el_alias . '"'
),
$page_json
);
}
}
}

$wp_filesystem->put_contents(
runway_prepare_path( $pages_dir . $page->settings->page_id . '.json' ),
$page_json,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,19 @@ public function inputs_decode( $page ) {

}

// create field ID's. This is an analog of the function 'make_ID' from formsbuilder.js
public function make_ID() {

$result = '';
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$length = strlen( $chars );

for ( $i = 12; $i > 0; --$i ) {
$result .= $chars[ mt_rand( 0, $length - 1 ) ];
}

return $result;

}

}

0 comments on commit 2ce9b6c

Please sign in to comment.