Skip to content

Commit

Permalink
refactor(layouts): adjust layout matching to new API response (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
mercs600 committed Oct 25, 2019
1 parent eaaf05c commit 531664b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
13 changes: 13 additions & 0 deletions example/layouts/backend/BeSinglecolumn.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>
<strong>Custom 1 column backend layout</strong>
<ce-renderer :content="content.colPos0" />
</div>
</template>
<script>
import BeDefault from '~typo3/layouts/backend/BeDefault'
export default {
functional: false,
extends: BeDefault
}
</script>
3 changes: 3 additions & 0 deletions example/layouts/layout-1.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<nuxt />
</template>
3 changes: 0 additions & 3 deletions example/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ module.exports = {
api: {
baseURL: 'https://api.t3pwa.com'
},
layouts: {
1: 'simple'
},
i18n: {
locales: ['en', 'pl', 'de'],
locale: 'en',
Expand Down
10 changes: 6 additions & 4 deletions example/plugins/layouts.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import Vue from 'vue'
import { registerBackendLayouts } from '~typo3/plugins/layouts'
import BeDefault from '~/layouts/backend/default'
import BeSinglecolumn from '~/layouts/backend/BeSinglecolumn'

const layouts = {
BeDefault,
BeSinglecolumn
// beLayout2Columns,
// example of async use
BeTwoColumns: () =>
import(
/* webpackChunkName: 'layouts/backend/2-columns.vue' */ '~/layouts/backend/2-columns.vue'
)
// BeSinglecolumn: () =>
// import(
// /* webpackChunkName: 'layouts/backend/BeSinglecolumn.vue' */ '~/layouts/backend/BeSinglecolumn.vue'
// )
}

export default ({ app }) => {
Expand Down
6 changes: 1 addition & 5 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ export default {
initialData: '?type=834'
}
},
// map your frontend layouts
// by default TYPO3 returns integer value
layouts: {
0: 'default'
},
layouts: {},
i18n: {
locale: 'en',
fallbackLocale: 'en'
Expand Down
14 changes: 8 additions & 6 deletions lib/templates/lib/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
*/
function getBackendLayout(components, layout) {
const backendLayout = 'default'
if (layout && layout.length && layout.includes('pagets__')) {
const _backendLayout = layout.split('pagets__').pop()
if (layout && layout.length) {
if (
Object.prototype.hasOwnProperty.call(
components,
`Be${_backendLayout[0].toUpperCase() + _backendLayout.slice(1)}`
`Be${layout[0].toUpperCase()}${layout.slice(1)}`
)
) {
return _backendLayout
return layout
}
}
return backendLayout
Expand All @@ -26,8 +25,11 @@ function getBackendLayout(components, layout) {
* @param {Object} layoutList Available list of layouts
* @param {String} layout Name of frontend layout
*/
function getFrontendLayout(layoutList, layout) {
return layoutList[layout] || 'default'
function getFrontendLayout(layout, layoutList) {
if (layoutList && typeof layoutList === 'object' && layoutList[layout]) {
return layoutList[layout]
}
return layout || 'default'
}

export { getBackendLayout, getFrontendLayout }
4 changes: 2 additions & 2 deletions lib/templates/middleware/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ middleware.context = function(context) {
.getPage(path)
.then(resp => {
context.layout = getFrontendLayout(
context.app.$typo3.options.layouts,
resp.data.page.appearance.layout
resp.data.page.appearance.layout,
context.app.$typo3.options.layouts
)
context.backendLayout = getBackendLayout(
context.app.components,
Expand Down

0 comments on commit 531664b

Please sign in to comment.