Skip to content

Commit

Permalink
Merge commit '556000203b8ef94b08a112b586488ba01936c4b1' into release/…
Browse files Browse the repository at this point in the history
…v2.0.0-beta.3.1.0
  • Loading branch information
jasonbahl committed Jul 6, 2023
2 parents 8634620 + 5560002 commit 7dfd6a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 33 deletions.
34 changes: 17 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions src/AcfGraphQLFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,16 @@ public function get_admin_field_settings( array $field, Settings $settings ) {
],
];

$graphql_field_name = '';

// If there's a graphql_field_name value, use it, allowing underscores
if ( ! empty( $field['graphql_field_name'] ) ) {
$graphql_field_name = \WPGraphQL\Utils\Utils::format_field_name( $field['graphql_field_name'], true );

// Else, use the field's name, if it's not "new_field" and format it without underscores
} elseif ( ! empty( $field['name'] ) && 'new_field' !== $field['name'] ) {
$graphql_field_name = \WPGraphQL\Utils\Utils::format_field_name( $field['name'], false );
}


$default_admin_settings['graphql_field_name'] = [
'label' => __( 'GraphQL Field Name', 'wp-graphql-acf' ),
'instructions' => __( 'The name of the field in the GraphQL Schema. Should only contain numbers and letters. Must start with a letter. Recommended format is "snakeCase".', 'wp-graphql-acf' ),
'name' => 'graphql_field_name',
'type' => 'text',
'ui' => true,
'required' => true,
'required' => false,
// we don't allow underscores if the value is auto formatted
'placeholder' => __( 'newFieldName', 'wp-graphql-acf' ),
'default_value' => '',
// allow underscores if the user enters the value with underscores
'value' => $graphql_field_name,
'conditions' => [
'field' => 'show_in_graphql',
'operator' => '==',
Expand Down
6 changes: 5 additions & 1 deletion src/assets/admin/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $j(document).ready(function () {
var graphqlFieldSettings = new acf.Model({
actions: {
'change_field_name': 'updateGraphqlFieldName',
'render_field_settings': 'updateGraphqlFieldName',
},
updateGraphqlFieldName: function( $el ) {

Expand All @@ -16,16 +17,19 @@ $j(document).ready(function () {

// when a field is emptied, we'll do nothing
if ( '' === $nameField || undefined === $nameField ) {
field.prop( 'graphql_field_name', '' );
return;
}

if ( undefined === $nameField?.getValue() ) {
field.prop( 'graphql_field_name', '' );
return;
}

var name = $nameField?.getValue() ?? null;

if ( '' === name ) {
field.prop( 'graphql_field_name', '' );
return;
}

Expand All @@ -36,7 +40,7 @@ $j(document).ready(function () {
var sanitizedGraphqlFieldName = acf.strCamelCase( acf.strSanitize(name) );
field.prop( 'graphql_field_name', sanitizedGraphqlFieldName );
}
}
},
})

var GraphqlLocationManager = new acf.Model({
Expand Down

0 comments on commit 7dfd6a6

Please sign in to comment.