replaced path+route_load navigation by id nav for articles and thematiques

This commit is contained in:
Bachir Soussi Chiadmi 2021-03-06 16:46:19 +01:00
parent 651315c319
commit 8dadb8d3a5
7 changed files with 62 additions and 68 deletions

View File

@ -99,6 +99,10 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
$registry->addFieldResolver('Query', 'route', $registry->addFieldResolver('Query', 'route',
$builder->compose( $builder->compose(
$builder->callBack(function($parent, $args){
$t="t";
return $parent;
}),
$builder->produce('route_load') $builder->produce('route_load')
->map('path', $builder->fromArgument('path')), ->map('path', $builder->fromArgument('path')),
$builder->callBack(function($parent, $args){ $builder->callBack(function($parent, $args){
@ -548,12 +552,12 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
// |_| // |_|
protected function addThematique(ResolverRegistryInterface $registry, ResolverBuilder $builder) { protected function addThematique(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Query', 'Thematique', $registry->addFieldResolver('Query', 'thematique',
$builder->produce('entity_load') $builder->produce('entity_load')
->map('type', $builder->fromValue('node')) ->map('type', $builder->fromValue('node'))
->map('bundles', $builder->fromValue(['thematique'])) // ->map('bundles', $builder->fromValue(['thematique']))
->map('id', $builder->fromArgument('id')) ->map('id', $builder->fromArgument('id'))
); );
$registry->addFieldResolver('Thematique', 'id', $registry->addFieldResolver('Thematique', 'id',
$builder->produce('entity_id') $builder->produce('entity_id')

File diff suppressed because one or more lines are too long

View File

@ -20,8 +20,6 @@ fragment ThematiqueFields on Thematique {
id id
url url
alt alt
style_cardmedium{ style_cardfull_url
url
}
} }
} }

View File

@ -37,7 +37,7 @@ export default {
console.log('clicked on article', this.alias); console.log('clicked on article', this.alias);
this.$router.push({ this.$router.push({
name:`article`, name:`article`,
params: { alias:this.alias } params: { alias:this.alias, id: this.item.nid }
// query: { nid: this.item.nid } // query: { nid: this.item.nid }
// meta: { uuid:this.item.uuid }, // meta: { uuid:this.item.uuid },
}) })

View File

@ -101,9 +101,9 @@ export default {
console.log('openThematique', e, this.alias); console.log('openThematique', e, this.alias);
this.$router.push({ this.$router.push({
name:`thematique`, name:`thematique`,
params: { alias:this.alias } params: { alias:this.alias, id: this.item.id }
// query: { nid: this.item.nid } // query: { id: this.item.id },
// meta: { uuid:this.item.uuid }, // meta: { id:this.item.id }
}) })
} }
} }

View File

@ -169,33 +169,23 @@ export default {
getPrevNextItems: 'Blabla/getPrevNextItems' getPrevNextItems: 'Blabla/getPrevNextItems'
}), }),
getArticle(){ getArticle(){
console.log(this.$route); console.log('getArticle', this.$route);
// get the article uuid if (this.$route.params.id) {
// if(this.$route.query.nid){
// // we come from internal link with vuejs
// // directly record uuid
// this.nid = this.$route.query.nid
//
// }else if(drupalDecoupled.entity_type == 'node' && drupalDecoupled.entity_bundle == 'article'){
// // we landed in an internal page
// // get the uuid from drupalDeclouped, provided by materio_decoupled.module
// this.nid = drupalDecoupled.entity_id
// }
if (this.$route.path) {
// we come from internal link with vuejs // we come from internal link with vuejs
this.path = this.$route.path // using path to load from route is hasardous
} else { // this.path = this.$route.path
this.id = this.$route.params.id
}else if(drupalDecoupled.entity_type == 'node' && drupalDecoupled.entity_bundle == 'article'){
// we landed in an internal page // we landed in an internal page
this.path = window.location.pathname // get the id from drupalDeclouped, provided by materio_decoupled.module
this.id = drupalDecoupled.entity_id
} }
if(this.path){ if(this.id){
this.loadArticle() this.loadArticle()
}else{ }else{
// if for any reason we dont have the uuid // if for any reason we dont have the id redirect to home
// redirect to home this.$router.replace({name:'home'})
this.$route.replace('home')
} }
}, },
getIndex(){ getIndex(){
@ -213,7 +203,7 @@ export default {
this.loading = true this.loading = true
let ast = gql`{ let ast = gql`{
route(path: "${this.path}", lang: "${drupalDecoupled.lang_code}") { article(id: ${this.id}, lang: "${drupalDecoupled.lang_code}") {
...ArticleFields ...ArticleFields
} }
} }
@ -221,9 +211,9 @@ export default {
` `
MGQ.post('', { query: print(ast) MGQ.post('', { query: print(ast)
}) })
.then(({ data:{data:{route}}}) => { .then(({ data:{data:{article}}}) => {
console.log('loadArticle', route ) console.log('loadArticle', article )
this.parseDataGQL(route) this.parseDataGQL(article)
}) })
.catch(error => { .catch(error => {
console.warn('Issue with loadArticle', error) console.warn('Issue with loadArticle', error)

View File

@ -7,7 +7,7 @@
<div class="col col-left"> <div class="col col-left">
<section class="body" v-html="thematique.body"></section> <section class="body" v-html="thematique.body"></section>
<section class="visuel"> <section class="visuel">
<img :src="image_accroche.style_cardmedium.url" alt=""> <img :src="image_accroche.style_cardfull_url" alt="">
</section> </section>
</div> <!-- //col-left --> </div> <!-- //col-left -->
<div class="col col-right"> <div class="col col-right">
@ -76,50 +76,41 @@ export default {
// }), // }),
getThematique(){ getThematique(){
console.log('getThematique', this.$route); console.log('getThematique', this.$route);
// get the article uuid if (this.$route.params.id) {
// if(this.$route.query.nid){
// // we come from internal link with vuejs
// // directly record uuid
// this.nid = this.$route.query.nid
//
// }else if(drupalDecoupled.entity_type == 'node' && drupalDecoupled.entity_bundle == 'article'){
// // we landed in an internal page
// // get the uuid from drupalDeclouped, provided by materio_decoupled.module
// this.nid = drupalDecoupled.entity_id
// }
if (this.$route.path) {
// we come from internal link with vuejs // we come from internal link with vuejs
this.path = this.$route.path // using path to load from route is hasardous
} else { // this.path = this.$route.path
this.id = this.$route.params.id
}else if(drupalDecoupled.entity_type == 'node' && drupalDecoupled.entity_bundle == 'thematique'){
// we landed in an internal page // we landed in an internal page
this.path = window.location.pathname // get the id from drupalDeclouped, provided by materio_decoupled.module
this.id = drupalDecoupled.entity_id
} }
if(this.path){ if(this.id){
this.loadThematique() this.loadThematique()
}else{ }else{
// if for any reason we dont have the uuid // if for any reason we dont have the id redirect to home
// redirect to home this.$router.replace({name:'home'})
this.$route.replace('home')
} }
}, },
loadThematique(){ loadThematique(){
console.log('loadThematique') console.log('loadThematique')
this.loading = true this.loading = true
//
let ast = gql`{ let ast = gql`{
route(path: "${this.path}", lang: "${drupalDecoupled.lang_code}") { thematique(id: ${this.id}, lang: "${drupalDecoupled.lang_code}") {
...ThematiqueFields ...ThematiqueFields
} }
} }
${ thematiqueFields } ${ thematiqueFields }
` `
// ?XDEBUG_SESSION_START=1
MGQ.post('', { query: print(ast) MGQ.post('', { query: print(ast)
}) })
.then(({ data:{data:{route}}}) => { .then(({ data:{data:{thematique}}}) => {
console.log('loaded Thematique', route) console.log('loaded Thematique', thematique)
this.parseDataGQL(route) this.parseDataGQL(thematique)
}) })
.catch(error => { .catch(error => {
console.warn('Issue with loadThematique', error) console.warn('Issue with loadThematique', error)