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

Add a language filter for ACF options pages #42

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Ririshi
Copy link

@Ririshi Ririshi commented Mar 22, 2023

The main addition of this PR is the addition of a wpmlLanguage argument on ACF options page fields, which controls the language of the query output. By default, ACF options pages only output the default site language on WPGraphQL. This argument allows the user to supply a language code (e.g. "en", or "nl"), very similar to PR #32.

I added a gitignore file to ensure no unnecessary files are added to the repository.

I also took some time to consistently reformat the plugin's code, add use statements to replace FQCNs, remove unused function arguments, replace deprecated function calls, and remove some duplicate and unused code. The exact changes can be found in the first few commits.

The (WIP) commit is an intermediate commit where I failed to get it fully working, you can essentially ignore that, as I moved the code into a separate file in the last commit, while also solving the problem and getting it to function correctly.

@Ririshi Ririshi mentioned this pull request Mar 22, 2023
// If WPML is installed
if ($sitepress) {
// Switch the current locale WPML
$sitepress->switch_lang($lang);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt we switch the locale back to what it was before after this resolver? Otherwise this will cause resolvers further down in the call chain to behave different, no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something that seems to be happening, yes. I'm using it to my advantage by following it up with a query that has no language filter, but it would be better to reset the language to the default. Or maybe even better, save what it was before and set that back.

global $wpgraphqlwpml_prev_language;
global $wpgraphqlwpml_url_filter_off;

$field_name = $resolver->getInfo()->fieldName;
if ($field_name === 'menus') {
global $icl_adjust_id_url_filter_off;
$icl_adjust_id_url_filter_off = true;
$args = $resolver->getArgs();
$args = $resolver->get_args();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getArgs method was deprecated by WP GraphQL. I'm not sure if the new option was already available in older versions of the plugin, so it might be something that should be reverted to ensure compatibility with older versions of WPGQL.

@Ririshi
Copy link
Author

Ririshi commented Apr 11, 2023

I just found out that a GQL debug message is generated with my current code:

You cannot register duplicate fields on the same Type. The field 'websiteSettings' already exists on the type 'RootQuery'. Make sure to give the field a unique name.

I removed the code that first deregisters the fields because everything seemed to work without it, but I think re-adding that code would get rid of this debug message.

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.

2 participants