Skip to content

Commit

Permalink
feat(#417): add default region with prefix fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Apr 27, 2022
1 parent 210b20e commit dfaf2ec
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
22 changes: 0 additions & 22 deletions components/druxt/block-region/BannerTop.vue

This file was deleted.

46 changes: 46 additions & 0 deletions components/druxt/block-region/Default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<template>
<div>
<template v-for="key of Object.keys($scopedSlots)">
<slot v-if="isVisible(key)" :name="key" />
</template>
</div>
</template>

<script>
import { mapState } from 'vuex'
import { DruxtBlocksRegionMixin } from 'druxt-blocks'
export default {
mixins: [DruxtBlocksRegionMixin],
computed: {
...mapState({
route: (state) => state.druxtRouter.route,
}),
},
methods: {
isVisible(key) {
const block = this.blocks.find((o) => o.attributes.drupal_internal__id === key) || {}
// Request path visibility conditions.
if (((block.attributes || {}).visibility || {}).request_path) {
let visible = false
const { negate } = block.attributes.visibility.request_path
const pages = block.attributes.visibility.request_path.pages.split(/\r?\n/).filter(i => i)
const route = this.route
// Remove the language prefix from the resolved path.
// @see https://github.com/druxt/demo.druxtjs.org/issues/417
route.resolvedPath = route.resolvedPath.replace('/en', '')
if (pages.includes('<front>') && (route.isHomePath || (!route.isHomePath && negate))) {
visible = true
}
if (pages.includes(route.resolvedPath) || (!pages.includes(route.resolvedPath) && negate)) {
visible = true
}
return visible
}
return false
}
}
}
</script>

0 comments on commit dfaf2ec

Please sign in to comment.