Closed pocockn closed 7 years ago
I wanted to label this as 'Help Needed' but it wouldn't let me 👎
You can create an adapter for menu, let it extend the wordpress adapter and override the urlForFindAll method. https://emberjs.com/api/data/classes/DS.RESTAdapter.html#method_urlForFindAll But if you are just fetching one menu and its menu items, I would consider just using simple AJAX.
To extend the wordpress adapter, could you possibly show me the basic code? I see in the WordPress adapter export default DS.RESTAdapter.extend , so In my adapter what do I extend?
Sure:)
// /app/adapters/menu.js
import WordpressAadapter from 'ember-wordpress/adapters/wordpress';
export default WordpressAadapter.extend({
urlForFindAll(){
return 'foo';
}
Ah thank you
I've tried this and I got the error findAll is undefined, can you see where I am going wrong?
import WordPressAdapter from 'ember-wordpress/adapters/wordpress';
export default WordPressAdapter.extend({
urlForFindAll() {
return '/ember-wp/wp-json/wp-api-menus/v2/';
}
});
// my route
import Ember from 'ember';
import MenuAdapter from '../adapters/menu-adapter';
export default Ember.Route.extend({
model() {
return Ember.RSVP.hash({
project: this.store.findAll('project'),
menu: MenuAdapter.store.findAll('menu/2')
});
}
});
There's no need to import adapter and call it like this. Ember-data will look up the menu adapter itself if the modelName is 'menu'
findAll('menu/2')
does not seem right as you probably have no model with name menu/2
are you trying to fetch menu with id 2? that would be this.store.findRecord('menu', 2)
. You'd have to also provide urlForFindRecord then on your adapter.
Maybe it's really easier to just AJAX the menu. It depends on the use-case... :)
Not sure i'm being stupid but i couldn't get it to work, posted the full example here : http://stackoverflow.com/questions/43287804/custom-adapter-override-find-single-record
@pocockn it looks like it's not reading your menu
adapter, since the endpoint isn't changed when you request the menu. What is the exact file location of your menu adapter? I believe it should be app/adapters/menu.js
.
Thanks for helping @MartinMalinda!
It's in
app/adapters/menu-adapter.js
do I need to rename to just menu.js?
@pocockn yes, believe so.
I can see in
the namespace: wp-json/wp/v2.
I want to be able to fetch the menu items in WordPress using the WP REST API Menus plugin, this exposes an end point like this:
wp-json/wp-api-menus/v2/
Is it possible to make this namespace dynamic when I do a fetch in my route? So in my route where my navigation is I can do:
this.store.findAll('menu');
Where it will hit this end point
wp-json/wp-api-menus/v2/menu
As opposed to if I do the findAll currently it will hit (i assume this end point)
wp-json/wp/v2
And give me the list of menu items.
Is this possible?
Thanks