Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Advanced Custom Fields: Gravityforms Add-on #143

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from

Conversation

Twansparant
Copy link

@Twansparant Twansparant commented May 19, 2020

This will add support for the ACF Gravityforms add-on plugin when the following plugins are both installed and activated:
GravityForms 2.+
Advanced Custom Fields: Gravityforms Add-on

When selecting Form ID as output value, an integer will be returned in your query:

{
  post( id: "acf-example-test" idType: URI ) {
    acfDocs {
      myGravityForm
    }
  }
}

Will return:

{
  "data": {
    "post": {
       "acfDocs": {
         "myGravityForm": 1
       }
    }
  }
}

When selecting Form ID as output value and enabling Multiple selections, an array of integers will be returned in your query:

{
  post( id: "acf-example-test" idType: URI ) {
    acfDocs {
      myGravityForm
    }
  }
}

This will return:

{
  "data": {
    "post": {
       "acfDocs": {
         "myGravityForm": [1, 2]
       }
    }
  }
}

When selecting Form Object as output value, you will need an additional plugin to be installed and activated in order to get a full GraphQL Form type object:
WPGraphQL for Gravity Forms with dev-master branch.

Note: At the moment WPGraphQL for Gravity Forms only works with WPGraphQL versions up to 0.7.1. See issue.

When selecting Form Object as output value, a Gravity Form object will be returned in your query:

{
  post( id: "acf-example-test" idType: URI ) {
    acfDocs {
      myGravityForm {
        id
        title
        formId
        description
        fields(first: 300) {
          nodes {
          ... on TextField {
            type
            id
            label
            cssClass
            cssClassList
          }
          ... on TextAreaField {
            type
            id
            label
            cssClass
            cssClassList
          }
          ... on SelectField {
            type
            id
            label
            cssClass
            cssClassList
          }
        }
      }
    }
  }
}

See the WPGraphQL for Gravity Forms documentation for more query examples.

When selecting Form Object as output value and enabling Multiple selections, an array of Gravity Form Objects will be returned in your query.

Note: I can understand if you don't feel comfortable adding an extra 3rd party plugin as dependency to yours, but I thought I gave it a try anyway!

@ridgehkr
Copy link

It appears that this PR has fallen through the cracks. Is there a chance we can get this reviewed and merged in?

@marekmiotelka
Copy link

Hi! Any updates on this?

@Ebeldev
Copy link

Ebeldev commented Dec 15, 2021

Any news on this issue?

@justlevine
Copy link

For those following this, the PR relies on an old release of WPGraphQL for Gravity Forms, which is why its not working for y'all.
On the bright side, once v0.10.0 is released, implementing this functionality yourself will only require a short add_filter(). Will come back to share the code snippet once it's out.

@Ebeldev
Copy link

Ebeldev commented Dec 15, 2021

@justlevine Thank you for the follow up. Do you have any idea for a relase date for the v0.10.0 ?

We are building a site that would need this functionnality.

@justlevine
Copy link

At the current pace, I'm guessing ~ 3 weeks.

@MatteoAlberghini
Copy link

Is there any updates on this?

@derek36
Copy link

derek36 commented Sep 21, 2022

@justlevine really hoping to get that add_filter snippet at some point

@justlevine
Copy link

justlevine commented Sep 21, 2022

@derek36 check out this doc, and this slack thread for an acf example.

@derek36
Copy link

derek36 commented Sep 22, 2022

Thanks a lot! For anybody else who finds this in their searches and doesn't want to join the Slack channel, here's what I added to the WP functions.php file in order to get the ACF GF add-on select's value to show up on the wp-graphql side as a full fledged form:

`// inspired by: https://github.com/NicholasRowe/wp-graphql-acf-gf-picker
function add_form_to_graphql($field_config, $type_name, $field_name, $config) {
$acf_field = isset($config['acf_field']) ? $config['acf_field'] : null;
$acf_type = isset($acf_field['type']) ? $acf_field['type'] : null;

// ignore all other field types
if (!$acf_field || $acf_type !== 'forms') {
    return $field_config;
}

$field_config['type'] = 'GfForm';
$field_config['resolve'] = function($root, $args, \WPGraphQL\AppContext $context, $info) use ($acf_field) {
    // check what root actually is this way:
    // wp_send_json( [  $root ] );

    if (isset($root[$acf_field['key']]["0"])) {
        $value = $root[$acf_field['key']]["0"];
    }

    if (!empty($value)) {
        $form = $context->get_loader(\WPGraphQL\GF\Data\Loader\FormsLoader::$name)->load_deferred($value);
    }

    return !empty($form) ? $form : null;
};
return $field_config;

}
add_filter( 'wpgraphql_acf_register_graphql_field', 'add_form_to_graphql', 10, 4);`

@marek-miotelka
Copy link

Support for Form Object, FormID and multiple selection:

https://gist.github.com/marek-miotelka/f4e90c12ce62f7fbe023814d10591f81

@Ririshi
Copy link

Ririshi commented Apr 11, 2023

The gist linked above works partially. It does not take into account that the $root->databaseId might be missing in the case of options pages. A simple fix is to add $root->databaseId ?? 'options' instead, but this will not work if you are using a custom options page with different post_id (see this ACF docs page).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants