Skip to content

Commit

Permalink
WiP Some more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DDEV User committed Oct 10, 2024
1 parent 6173070 commit 9e55384
Showing 1 changed file with 54 additions and 15 deletions.
69 changes: 54 additions & 15 deletions plugins/wp2grav-post_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function wp2grav_export_post_types() {
$blueprint = Yaml::parseFile( $blueprint_component );
$blueprint['title'] = $post_type;

// Reset new_fields;
// Reset new_fields.
$new_fields = null;
$new_acf_fields = null;

Expand Down Expand Up @@ -101,23 +101,43 @@ function wp2grav_export_post_types() {
// Iterate through fields, porting the WP field to the Grav admin blueprint form fields.
foreach ( $post_type_features as $field_type => $value ) {
switch ( $field_type ) {
case 'author':
$new_fields['header.wp.post.author'] = array(
'help' => 'WP Post author',
'label' => $field_type,
'type' => 'text',
);
break;

case 'autosave':
// Skip autosave field.
break;

case 'comments':
// Do nothing for now.
// Todo: Process comments.
break;

case 'revisions':
// Do nothing for now.
case 'editor':
// Skip editor field.
break;

case 'excerpt':
$new_fields['header.wp.post.excerpt'] = array(
'help' => 'WP Post excerpt',
'label' => $field_type,
'type' => 'text',
);
break;

case 'image':
$new_fields[ 'header.' . $field_name ] = array(
'label' => $field_name,
'type' => 'file',
'help' => strip_tags( $field['description'] ) . ' | Available file types: ' . $field['settings']['file_extensions'],
'help' => wp_strip_all_tags( $field['description'] ) . ' | Available file types: ' . $field['settings']['file_extensions'],
'destination' => 'user/data/' . $field['settings']['file_directory'],
'accept' => array( 'image/*' ),
);
if ( $field_info['cardinality'] != 1 ) {
if ( 1 !== $field_info['cardinality'] ) {
$new_fields[ 'header.' . $field_name ]['multiple'] = true;
} else {
$new_fields[ 'header.' . $field_name ]['multiple'] = false;
Expand All @@ -137,6 +157,18 @@ function wp2grav_export_post_types() {
}
break;

case 'revisions':
// Grav doesn't really have a concept of revisions. Skip for now.
break;

case 'title':
$new_fields['header.title'] = array(
'help' => 'Page Title',
'label' => 'Title',
'type' => 'text',
);
break;

default:
// Assume a text field.
$new_fields[ 'header.' . $field_type ] = array(
Expand Down Expand Up @@ -177,10 +209,8 @@ function wp2grav_export_post_types() {
/**
* Converts an advanced-custom-fields to a Grav's admin form field.
*
* @param array $acf_field
* acf field.
* @param WP_Post $post
* WordPress post.
* @param array $acf_field Advanced Custom Field.
* @param WP_Post $post WordPress post.
* @return array
* Converted field data.
*/
Expand All @@ -196,6 +226,16 @@ function convert_acf_field_data_to_grav_admin( $acf_field, $post ) {
);
break;

case 'image':
$grav_field = array(
'type' => 'filepicker',
'folder' => 'user://data/wp-content/upload',
'label' => $acf_field['label'],
'preview_images' => true,
'accept' => array( 'image/*' ),
);
break;

case 'range':
$grav_field = array(
'help' => $acf_field['instructions'],
Expand All @@ -208,14 +248,13 @@ function convert_acf_field_data_to_grav_admin( $acf_field, $post ) {

break;

// default:
// $grav_field['error'] = 'Missing field definition: ' . $acf_field['type'];
// $grav_field['debug'] = $acf_field;

default:
$grav_field['error'] = 'Missing field definition: ' . $acf_field['type'];
$grav_field['debug'] = $acf_field;
}

// Generic field options.
if ( $acf_field['required'] == '1' ) {
if ( 1 === $acf_field['required'] ) {
$grav_field['validate']['required'] = true;
} else {
$grav_field['validate']['required'] = false;
Expand Down

0 comments on commit 9e55384

Please sign in to comment.