diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0fda7b..8880f1f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,6 +7,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://npm.pkg.github.com/ + scope: '@platform-coop-toolkit' - name: Cache node modules uses: actions/cache@v1 with: @@ -18,6 +23,7 @@ jobs: npm run build npm test env: + NODE_AUTH_TOKEN: ${{ secrets.PKG_READ_TOKEN }} CI: true - name: Cache Composer packages uses: actions/cache@v1 @@ -34,6 +40,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://npm.pkg.github.com/ + scope: '@platform-coop-toolkit' - name: Cache node modules uses: actions/cache@v1 with: @@ -44,6 +55,7 @@ jobs: npm install npm run build:production env: + NODE_AUTH_TOKEN: ${{ secrets.PKG_READ_TOKEN }} CI: true - name: Cache Composer packages uses: actions/cache@v1 diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..52d1dff --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +registry=https://npm.pkg.github.com/platform-coop-toolkit diff --git a/app/Controllers/App.php b/app/Controllers/App.php index bcec1dd..b224d45 100644 --- a/app/Controllers/App.php +++ b/app/Controllers/App.php @@ -43,17 +43,26 @@ public function languages() public function currentLanguageName() { - return pll_current_language('name'); + if (function_exists('pll_current_language')) { + return pll_current_language('name'); + } + return 'English'; } public function currentLanguageLocale() { - return pll_current_language('locale'); + if (function_exists('pll_current_language')) { + return pll_current_language('locale'); + } + return 'en_US'; } public function currentLanguage() { - return pll_current_language(); + if (function_exists('pll_current_language')) { + return pll_current_language(); + } + return 'en'; } public function foundPosts() diff --git a/app/Controllers/Page.php b/app/Controllers/Page.php index b46c9fc..82657d8 100644 --- a/app/Controllers/Page.php +++ b/app/Controllers/Page.php @@ -10,12 +10,14 @@ public function taxonomy() { global $post; - if (pll_get_post_language($post->ID) === 'en') { - return 'lc_' . rtrim(str_replace('-', '_', $post->post_name), 's'); - } else { - $translations = pll_get_post_translations($post->ID); - $slug = get_post_field('post_name', $translations['en']); - return 'lc_' . rtrim(str_replace('-', '_', $slug), 's'); + if (function_exists('pll_get_post_language') && function_exists('pll_get_post_translations')) { + if (pll_get_post_language($post->ID) !== 'en') { + $translations = pll_get_post_translations($post->ID); + $slug = get_post_field('post_name', $translations['en']); + return 'lc_' . rtrim(str_replace('-', '_', $slug), 's'); + } } + + return 'lc_' . rtrim(str_replace('-', '_', $post->post_name), 's'); } } diff --git a/app/Controllers/Partials/Resource.php b/app/Controllers/Partials/Resource.php index 8ff694e..2e644d3 100644 --- a/app/Controllers/Partials/Resource.php +++ b/app/Controllers/Partials/Resource.php @@ -107,7 +107,11 @@ public static function getLanguage($format = 'slug') { global $post; - return pll_get_post_language($post->ID, $format); + if (function_exists('pll_get_post_language')) { + return pll_get_post_language($post->ID, $format); + } + + return 'en'; } public static function getFormat() diff --git a/app/filters.php b/app/filters.php index 6c16c61..f866aae 100644 --- a/app/filters.php +++ b/app/filters.php @@ -134,3 +134,10 @@ 'class' => 'icon' ]; }); + +add_filter('wp_nav_menu_items', function ($items, $args) { + if ($args->theme_location === 'primary_navigation') { + $items .= template('partials.language-switcher'); + } + return $items; +}, 10, 2); diff --git a/app/helpers.php b/app/helpers.php index aca4a3d..1c62eae 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -139,14 +139,16 @@ function display_sidebar() function maybe_swap_term($term, $lang = false) { - if (!$lang) { - $lang = pll_current_language(); - } - if (pll_get_term_language($term->term_id) !== $lang) { - $localized_term_id = pll_get_term($term->term_id, $lang); - if ($localized_term_id) { - $localized_term = get_term($localized_term_id, $term->taxonomy); - return $localized_term; + if (function_exists('pll_current_language') && function_exists('pll_get_term_language')) { + if (!$lang) { + $lang = pll_current_language(); + } + if (pll_get_term_language($term->term_id) !== $lang) { + $localized_term_id = pll_get_term($term->term_id, $lang); + if ($localized_term_id) { + $localized_term = get_term($localized_term_id, $term->taxonomy); + return $localized_term; + } } } return $term; diff --git a/package-lock.json b/package-lock.json index 75be3f2..22cd8c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1742,9 +1742,9 @@ } }, "@platform-coop-toolkit/pinecone": { - "version": "1.0.0-alpha.4", - "resolved": "https://registry.npmjs.org/@platform-coop-toolkit/pinecone/-/pinecone-1.0.0-alpha.4.tgz", - "integrity": "sha512-53Vq6MHdokaQ69kQs24tHH34ClDyAQaaNelCPSXW9yqSzkbxHCbTv0JvBqRJdPy4TKlGEpMpFnPzRYT/tpJksA==", + "version": "1.0.0-alpha.6", + "resolved": "https://npm.pkg.github.com/download/@platform-coop-toolkit/pinecone/1.0.0-alpha.6/8cefb1b937c40742fb9cb21807c3c2e57e08e423f421481c9d49db1fb971bbc5", + "integrity": "sha512-Tx9WW/TsDNHSnFYyEKu1N6a6xK3cfmBvcyKrMIUPiHZU97w5q9fMe7J/Dlu1HZ0uEnB1nVM3Y9I1hehKFqtIbQ==", "dev": true, "requires": { "popper.js": "^1.16.0", diff --git a/package.json b/package.json index 5a92bcd..788a853 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7", "@commitlint/cli": "^8.3.4", "@commitlint/config-conventional": "^8.3.4", - "@platform-coop-toolkit/pinecone": "^1.0.0-alpha.4", + "@platform-coop-toolkit/pinecone": "^1.0.0-alpha.6", "@wordpress/babel-preset-default": "^4.8.0", "@wordpress/browserslist-config": "^2.6.0", "@wordpress/dependency-extraction-webpack-plugin": "^2.1.0", diff --git a/resources/assets/scripts/routes/archive.js b/resources/assets/scripts/routes/archive.js index 8295854..8b8842e 100644 --- a/resources/assets/scripts/routes/archive.js +++ b/resources/assets/scripts/routes/archive.js @@ -48,6 +48,14 @@ export default { ); } ); + const filterDisclosureLabels = document.querySelectorAll( '.filter-disclosure-label' ); + + if ( filterDisclosureLabels ) { + Array.prototype.forEach.call( filterDisclosureLabels, label => { + new Pinecone.DisclosureButton( label, { buttonVariant: 'button--disc', visuallyHiddenLabel: true } ); + } ); + } + const sortMenuButtonContainer = document.querySelector( '.sort .menu-button' ); if ( sortMenuButtonContainer ) { new Pinecone.MenuButton( sortMenuButtonContainer, { placement: 'bottom' } ); diff --git a/resources/views/partials/filters.blade.php b/resources/views/partials/filters.blade.php index 57439b5..8bd710c 100644 --- a/resources/views/partials/filters.blade.php +++ b/resources/views/partials/filters.blade.php @@ -30,8 +30,8 @@ ) }} /> @if(get_term_children($term->term_id, $tax)) - - + +