From 86d0303488d61b83beb06f6138084da8763c6217 Mon Sep 17 00:00:00 2001 From: Esa-Matti Suuronen Date: Tue, 21 May 2024 12:54:15 +0300 Subject: [PATCH 1/5] Add .gitremote --- .gitremote | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitremote diff --git a/.gitremote b/.gitremote new file mode 100644 index 0000000..790dc22 --- /dev/null +++ b/.gitremote @@ -0,0 +1 @@ +origin git@github.com:valu-digital/wp-graphql-polylang.git From 9dba3e9db34bbdefce7e8a9a71808493c0fc280b Mon Sep 17 00:00:00 2001 From: Esa-Matti Suuronen Date: Tue, 21 May 2024 12:55:08 +0300 Subject: [PATCH 2/5] Fix menuItems language filtering For wp-graphql v1.26 and later --- src/MenuItem.php | 57 ++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/src/MenuItem.php b/src/MenuItem.php index 3e790c2..13c2b91 100644 --- a/src/MenuItem.php +++ b/src/MenuItem.php @@ -7,18 +7,6 @@ class MenuItem { - /** - * Convert menu location to match the one generated by Polylang - * - * Ex. TOP_MENU -> TOP_MENU___fi - */ - static function translate_menu_location( - string $location, - string $language - ): string { - return "${location}___${language}"; - } - function init() { $this->create_nav_menu_locations(); @@ -30,52 +18,39 @@ function init() 0 ); + // https://github.com/wp-graphql/wp-graphql/blob/release/v1.26.0/src/Data/Connection/MenuItemConnectionResolver.php#L107 add_filter( - 'graphql_connection_query_args', - [$this, '__filter_graphql_connection_query_args'], + 'graphql_menu_item_connection_args', + [$this, '__filter_graphql_menu_item_connection_args'], 10, 2 ); } - function __filter_graphql_connection_query_args( - array $query_args, - AbstractConnectionResolver $resolver + function __filter_graphql_menu_item_connection_args( + array $args, + $unfiltered ) { - if (!($resolver instanceof MenuItemConnectionResolver)) { - return $query_args; + if (!isset($args['where']['location'])) { + return $args; } - $args = $resolver->getArgs(); + $lang = $args['where']['language'] ?? null; - if (!isset($args['where']['language'])) { - return $query_args; - } - - if (!isset($args['where']['location'])) { - return $query_args; + if (!$lang) { + return $args; } // Required only when using other than the default language because the // menu location for the default language is the original location - if (pll_default_language('slug') === $args['where']['language']) { - return $query_args; + if (pll_default_language('slug') === $lang) { + return $args; } - // Update the 'location' arg to use translated location - $args['where']['location'] = self::translate_menu_location( - $args['where']['location'], - $args['where']['language'] - ); - - // XXX. This is a hack. Modify the protected "args" so we can re-execute - // the get_query_args method with the new "location" arg - $ref = new \ReflectionObject($resolver); - $args_prop = $ref->getProperty('args'); - $args_prop->setAccessible(true); - $args_prop->setValue($resolver, $args); + // Ex. TOP_MENU -> TOP_MENU___fi + $args['where']['location'] .= '___' . $lang; - return $resolver->get_query_args(); + return $args; } /** From 6c21ee491fc227aa52ac64577d0056088628d24b Mon Sep 17 00:00:00 2001 From: Esa-Matti Suuronen Date: Tue, 21 May 2024 12:56:47 +0300 Subject: [PATCH 3/5] upgrade wp-graphql for tests --- composer.wp-install.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.wp-install.json b/composer.wp-install.json index 22a5079..66fa6fb 100644 --- a/composer.wp-install.json +++ b/composer.wp-install.json @@ -10,7 +10,7 @@ ], "require": { "composer/installers": "^1.0", - "wp-graphql/wp-graphql": "1.6.5", + "wp-graphql/wp-graphql": "1.26.0", "wpackagist-plugin/polylang": "3.1.1" }, "extra": { From 64549c97d3c5294143706e12e35f3832789cbcee Mon Sep 17 00:00:00 2001 From: Esa-Matti Suuronen Date: Tue, 21 May 2024 12:59:56 +0300 Subject: [PATCH 4/5] Fix mariadb service in gh actions --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 67c597f..6ac7700 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,8 +10,8 @@ jobs: ports: - 3306:3306 env: - MYSQL_ROOT_PASSWORD: root - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + MARIADB_ROOT_PASSWORD: root + options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3 runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 From 1ec2fbaada076e170087be7b97717244d8e81a17 Mon Sep 17 00:00:00 2001 From: Esa-Matti Suuronen Date: Tue, 21 May 2024 13:27:01 +0300 Subject: [PATCH 5/5] fix test --- tests/wpunit/SanityTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/wpunit/SanityTest.php b/tests/wpunit/SanityTest.php index 06d5a48..6eabe26 100644 --- a/tests/wpunit/SanityTest.php +++ b/tests/wpunit/SanityTest.php @@ -69,7 +69,9 @@ public function testCanUsePolylang() $this->assertTrue(defined('POLYLANG_VERSION')); $langs = pll_languages_list(['fields' => 'slug']); - $this->assertEquals($langs, ['en', 'fr', 'fi', 'de', 'es']); + asort($langs); + + $this->assertEquals($langs, ['es', 'en', 'fr', 'fi', 'de']); } public function testPluginIsActivated()