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 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 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": { 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; } /** 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()