Skip to content

Add a language filter for ACF options pages#42

Open
Ririshi wants to merge 6 commits into
rburgst:masterfrom
Ririshi:feat/acf-options-pages-language-filter
Open

Add a language filter for ACF options pages#42
Ririshi wants to merge 6 commits into
rburgst:masterfrom
Ririshi:feat/acf-options-pages-language-filter

Conversation

@Ririshi
Copy link
Copy Markdown

@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
Comment thread acf-compatibility.php
// If WPML is installed
if ($sitepress) {
// Switch the current locale WPML
$sitepress->switch_lang($lang);
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread wp-graphql-wpml.php
global $icl_adjust_id_url_filter_off;
$icl_adjust_id_url_filter_off = true;
$args = $resolver->getArgs();
$args = $resolver->get_args();
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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