When I enable a new menu in Drupal (for example, mymodule), Drupal should be able to get the menu items from mymodule_menu (hook_menu), process the items and insert the menu items to menu_router and menu_links table.
However, my Drupal fails to do so. Each time I enable a module (written by me or modules contributed by others, or core modules), Drupal does not seem to get the new information. The menu items defined in the newly enabled module are not processed and inserted to Drupal's menu system. That means the newly enabled module has no chance to work-- because it's inaccessible.
I did fix this by manually insert the menu item information for the new module into the menu_router and menu_links table and the new menu started working. But this is a nightmare if I have to do this each time I enable a module.
Any one has ever had the same problem? How to fix this?
Thank you in advance.
I would not use any SQL to interact with the menu tables, something nasty could happen if you edit the wrong record.
You must have an error in your hook_menu code. Can you paste it?
Also, if you are developing a module that has menu entries, I find that its handy to call these two functions inside of mymodule_init() when adding/removing links:
cache_clear_all()
menu_router_build()
That will flush all cache and rebuild the menu and anything invoking hook_menu. If it doesn't appear after that, then your code has a bug. I'd like to see it.
You didn't report which Drupal version are you using, but in Drupal 6, the implementations of hook_menu() are not invoked, if not in some occasions (when a module is installed, or when modules updates are executed, in example).
If your module changed the menu callbacks, but it has not an update to execute, you can add an update function containing the following code:
// Change the name of the function to match the module name.
// Change the update number to the correct one for your case.
function custom_module_update_6201() {
if (!variable_get('menu_rebuild_needed', FALSE)) {
variable_set('menu_rebuild_needed', TRUE);
}
}
The variable is checked from index.php, and if its value is TRUE, then Drupal will automatically rebuild the menus.
Related
This may be an odd question. I'm working on a website someone else built in WordPress. My understanding of the left navigation within the dashboard is that there are some default items that are there upon install like [pages], [posts], [plugins], and to get additional items to show up here you need to install a new plugin.
This site I'm working on has a few options in the left navigation [team members], [services] which do not appear to be tied to any particular 3rd party plugin.
In fact, it looks like they've used the plugin "Advanced Custom Fields" to create their own functionality so their users could easily add/remove team members from a custom built slider.
My Question
How do you get your own tab to show up in the dashboard's left navigation? Can you do this within a child theme, or do you need to modify the core WP files? Is there a particular folder or some documentation anyone could direct me to where I might learn more about how this is being connected behind the scenes?
Thank you kindly in advance.
I'll preface this by saying:
Never ever ever modify Core Files!
Whew! Now that that's out of the way, there may be a few plugins that do this for you, but I'm ultimately unfamiliar with any. The typical way to add Admin Items is with the add_menu_page() and add_submenu_page() functions. They're relatively straight forward to use.
Also, as a side note, when you add a Custom Post Type with register_post_type() (like what ACF does) there are options to add it to the menu, as well as what you want the labels and menu names to be.
If you're adding a Custom Post Type (like Team Members, Books, etc.) you'll almost certainly want to make use of the labels and show_in_menu arguments when you call register_post_type() to get the admin menu to show up. However, if you need to link to arbitrary URLs or custom dashboard pages, you'll want to make use of the add_menu/submenu_page functions above.
For instance, here's a simple snippet that will add a Stack Overflow link to the menu, you can drop this into a child theme, plugin, Must-Use plugin, etc:
function stack_overflow_admin_link(){
echo '<script>window.location.href = 'https://stackoverflow.com'; </script>';
}
add_menu_page( 'Stack Overflow', 'Stack Overflow', 'subscriber', 'stack-overflow', 'stack_overflow_admin_link', 'dashicons-external' );
Hope this helps!
Also I'll elaborate a little bit on my warning! Never ever modify core WordPress files. They will be overwritten with each and every WordPress update. WordPress is relatively well thought out and has countless Action Hooks and Filters that let you inject, modify, remove, and otherwise manipulate data and the user experience without ever touching core files.
As an example, take a look at this screenshot:
I'm currently rebuilding a software suite from the ground-up using WordPress, but the standard WP Admin interface doesn't make sense in many of the contexts we need it, so our interface (a work in progress) looks like this, and it's all handled by a Must-Use plugin and touches absolutely no core files, it just uses clever manipulation of the hooks and filters available throughout WordPress
So I was going through the settings in the Views Module and hit a checkbox and clicked save. This unfortunately transformed the entire Views UI into my custom theme's homepage. And trying to go into settings does not allow me to see anything except my custom homepage. I've tried uninstalling the module and deleting EVERYTHING but nothing seems to work. How can I manually undo check whatever box I had checked.
it needs a little bit of debugging.
go into views source code, look for .module files and search for
hook_menu() implementation
find there an URL where you have checked that checkbox
go into page callback function
check for submit callback function and go to that function
look for update queries or variables settings, anything that have a machine name of your checkbox, look for the mysql table and field
go into database and update that field to your needs
you can also use a fresh drupal install to perform this, it will be easier to just copy the value from one database field into another
Links require SDL Live Content login.
We can choose default schema (and a mandatory option) in folder properties. New components in these folders will have the schema selected with appropriate fields filled out.
We can choose default page template for structure group (SG) properties. New pages in these SG will have the page template selected.
Do we have a similar option for page metadata such that in a given SG, author gets both page template and predetermined page metadata (fields) for either:
page creation
page template selection
We can do this easily with Inline Editing (SiteEdit) and page prototypes. But how would you configure or implement this type of requirement with the Content Manager Explorer?
I'd say there are a number of ways to achieve this:
1) Using the UI 'Page Types' - If the page you are using as the page type this should keep that same metadata. *I've not tested this!!! maybe you could confirm?
2) GUI extension - When a page template is selected a page metadata is selected based on the page template.
3) Event system. I'm not sure how well this would work as it would likely have to be on the creation of the page (checking if a default template is used) or on save if a template is used and a metadata schema isn't selected... but then if there is mandatory metadata etc etc.
4) The page template. This will set the metadata (on publish or preview) - or warn a user that a specific metadata should be set for this given page template.
Hope this helps.
Thanks
John
Very interesting question and I can see the benefits of this functionality for Editors. I don't have the answer for you. But AFAIK, even event system might not be relevant here since there are no events fired when you start creating a page unless we save the page. GUI Extension a possibility?
When you create a new item, this takes place via the GetNewitem() method in the API (or GetNewObject() in old money). I always thought there should have been separate events system hooks for this activity than for that of modifying an existing item. I once suggested this on ideas.sdltridion.com with regard to Components, however someone referred me to the OnSchemaGetInstanceDataPost event hook, and the discussion was over.
So in the case of a new component, the schema is automatically queried, and via the hook, you can interfere with the default data. So far so good, but I still believe that it would be generically useful to be able to modify the default data of any item type when first created.
I have quite a few content types, but I need to change the available menus for a specific one.
No matter what I try, any changes to the available menus do not seem to save.
I have a suggestion for you.
Do you have a multi-site installation ? If you have multiple Domains, check under
Site-Information. (Normally there should be a message box with an info like "You may submit changes to the current domain at admin/structure/domain/view/3/config.")
Click admin/structure/domain/view/3/config
enable the menus for the appropriate content type in the Tabs at the end of the page
Possible solution: Change machine name of this Content Type to something different. This will probably involve updating some views etc. where you use this content type.
Ideally you'll need to find what is causing the lock of available menus so check all modules you've installed
By default on a page I have the following menu:
Profile /profile
Albums /album
Awards /awards
Going to any of those pages will load the page default.
If I go to a page on my site such as /mycontent/1 I wish to change a the menu to be the following.
Profile /profile/1
Albums /album/1
Awards /awards/1
I want to pass the argument (nid) to the menu. Is this possible?
Update
The selected answer does do what I asked. I however have changed how I am doing things to use Panels to display the content. I am then using some CSS and JavaScript to hide and show content. With views caching it seems to be working well.
Yes,use arg(0),arg(1), or arg(2) depending on which variable you want to use. It will use the path like the indexes of an array (0/1/2/3/4/etc...). Drupal will send you these variables as they were before the path was aliased if that is something that has been applied to it. Why are you passing the variable? There is probably a better way to do it the "Drupal" way..
Actually I am working on this same problem currently where I need to translate an aliased path: dept/profile/1 to load node/1223/profile/1 where 1 is the ID of the profile to show.
What I am using now is the URL Alter module and implementing the hook it gives to enable this feature. If you are interested in this maybe we can see if it is possible to get module out with a GUI.
My thread on this that is active now: Using module: url_alter and it's hook: hook_url_outbound_alter()
I am using a node that houses a panel which has a view inside it, for reasons that are site specific.