Replace the node-edit menu in Drupal - drupal

How can I change (unset or add) a new button in my edit-node menu? In this case, I would like to diable the 'Settings'-menu and add a new menu... I looked in the $form and the $form_state, but no luck there. At least, that's what I think...
EDIT
Module name: publication
Install: publication.install
File: publication.module
function publication_menu_alter(&$items) {
unset($items['node/%node/edit']);
}
EDIT 2
function publication_menu() {
$items['node/add/fiche'] = array(
'title' => 'New linked fiche',
'type' => MENU_LOCAL_TASK
);
return $items;
}
EDIT 3
What I'm trying to do is to allow my users to add some more content to existing content. So they are not allowed to edit the current content, only to add some details. So I thought, I delete the edit-button and replace it with an add-button and the add-button links to a page where he can create more content. That's it :)

You should use hook_menu_alter to unset menu.
function publication_menu_alter(&$items) {
// print_r($items);
// Find path you want to unset then unset it.
// Should be something like:
unset($items['your/menu/path']);
}
And hook_menu for defining new one. In your case I believe it should be menu type MENU_LOCAL_TASK since you want to add a new tab. Isn't it?
function publication_menu() {
$items['node/%node/something_else'] = array(
'title' => 'My title',
'page callback' => 'mymodule_abc_view',
'page arguments' => array(1),
'access arguments' => array('access content'),
'type' => MENU_LOCAL_TASK
);
return $items;
}
function mymodule_abc_view($nid = NULL) {
return 'This node ID is '. $nid;
}

Related

How to display table result on custom page webform in Drupal 7?

How to display table result in webform on custom page? Only result page for custom role.
Create custom module and code in it :
create a hook menu with role authorisation :
function MYMODULENAME_menu(){
$items['my/custom/path'] = array(
'title' => t('Results'),
'page callback' => 'mycallback',
'access arguments' => array('role_name'), // 'access callback' => user_has_role('role_name'),
'type' => MENU_CALLBACK
);
return $items;
}
create callback :
function mycallback(){
// get your data from database or what you want
// your code ... $datas = [...]
// construct lines
$rows = array();
foreach($datas as $data){
$rows[] = array($data['title1'], $data['title2']);
}
return theme('table',
array(
'header' => array('Title 1','Title 2'),
'rows' => $rows
));
}
Annexes :
https://www.drupal.org/docs/7/creating-custom-modules
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7.x
Use views module:
https://www.drupal.org/project/views
When you are creating the view for "Show" option select "Webform submissions" instead of default "Content" value. Then you can tune your view as usual - create page view or block view, what ever you need.
And later, when you continue editing that view for "Format" option select "Table" (if it's not already set, as default value).

Drupal - custom module - Generate dynamic URL alias

I have a custom drupal module. I have a demo pages for different APIs I have. (Like, host.com/demo/abc or host.com/demo/bcd or host.com/demo/def ...)
hook_menu()
$items['demo/%'] = array(
'page callback' => 'xxx',
'page arguments' => array(1),
'access callback' => 'xxx',
....
);
I want to change the URL to host.com/abc/demo for all the demo pages. Since I cannot a wild card at the beginning of the hook (Like %/demo) I am considering URL alias. But how can I generate url alias dynamically for all the demo pages?
The best solution :
http://www.zyxware.com/articles/3636/drupal-how-to-create-url-alias-for-custom-menu-implementation-of-hook-pathauto
Otherwise :
Before you need to know that all dynamical solution available is not totally safe , take care before using it.
With url_alias you can try this, but you have to restrict by defined path to avoid flood insertion :
function mymodule_menu(){
$items= array();
$items['demo/%'] = array(
'page callback' => 'xxx',
'page arguments' => array(1),
'access callback' => 'xxx',
);
return $items;
}
function mymodule_init(){
global $language;
$path_allowed = array(
'abc',
'dbe'
); // restrict to avoid flood
if(arg(1) == 'demo' && in_array(arg(0), $path_allowed)) { // detect demo mode
$path = arg(1).'/'.arg(0);
$alias = arg(0).'/'.arg(1);
$a = db_query('SELECT alias FROM url_alias WHERE source = :source AND alias = :alias', array(':source' => $path, ':alias' => $alias))->fetchField();
if($a == null) ) {
db_insert('url_alias')->fields(array(
'source' => $path,
'alias' => $alias,
'language' => $language->language
))->execute();
}
}
}
Otherwise, I'm not sure but you can try this too , you can handle it from hook_init but it can cause some issue form all module loading init
function mymodule_init(){
if(arg(1) == 'demo') { // detect demo mode
$mycallbacks = array( // define your callback related
'abc' => 'mymodule_callback1',
'dbe' => 'mymodule_callback2',
);
if(isset($mycallbacks[arg(0)]) && function_exists($mycallbacks[arg(0)])) { // if callback is available
call_user_func($mycallbacks[arg(0)]); // call it
}
}
}
function mymodule_callback1(){ //do what you want }
function mymodule_callback2(){ //do what you want }
So , mysite.com/abc/demo will execute mymodule_callback1() and mysite.com/dbe/demo will execute mymodule_callback2()
Etc..
Clear all caches and see :)

Custom Drupal 6 Module with multiple pages

I am trying to write my first Drupal custom module (using drupal 6). I got the basic module working but I would like to add another page to the project. For example, right now my module's path looks like this: www.mysite.com/my_custom_module. I would like to add another page like this: www.mysite.com/my_custom_module/my_sub_page. I've tried adding a new .module and .info file but this does not work. I've also tried adding new items to the menu hook, like this:
my_custom_module.module:
function my_custom_module_menu(){
$items = array();
$items['my_custom_module'] = array(
'title' => "My Custom Module",
'page callback' => "my_custom_module_info",
'access callback' => true,
'type' => MENU_NORMAL_ITEM,
);
$items['my_custom_module/my_sub_page'] = array(
'title' => "My Sub Page",
'page callback' => "my_custom_module_sub_page_info",
'access callback' => true,
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function my_custom_module_info(){
$result = 'My Page URL was hit';
return $result;
}
function my_custom_module_sub_page_info(){
$result = 'My Sub Page URL was hit';
return $result;
}
In this example, if I go to .../my_custom_module it works fine. But, if I go to .../my_custom_module/my_sub_page, it still load, and displays my_custom_module. When I debug with a break point in each function, only my_custom_module_info is hit. Not the sub page. What am I doing wrong? I this even the correct way to create multi pages in a module? Just an FYI, each of these pages will have different audiences. The first page is to allow a user to submit some form data. The second is to allow an elevated user view the data.
Thanks
jason

Drupal 6: how to display node with its local tasks tabs in menu item

In my case each user has a gallery. Gallery is a node. I'd like to hide default "Create content" menu and add custom menu link that links to user gallery.
function custom_menu() {
$items = array();
$items['galleries/editgallery'] = array(
'title' => 'Edit gallery',
'description' => 'edit gallery',
'page callback' => 'custom_edit_gallery',
'access callback' => 'custom_access_editgallery',
);
return $items;
}
function custom_edit_gallery (){
global $user;
$node = node_load ($user->gallerynid);
return node_page_view ($node);
}
But it doesn't show local tasks tabs(like "Edit" tab).
You would need to add them yourself.
With normal theming, you could create a custom template file or overwrite a theme function etc to add the tabs you want.
You could also do this within hook_menu, by using MENU_LOCAL_TASK and MENU_DEFAULT_LOCAL_TASK, see the api.

drupal hook_menu_alter() for adding tabs

I want to add some tabs in the "node/%/edit" page from my module called "cssswitch".
When I click "Rebuild Menus", the two new tabs are displayed, but they are displayed for ALL nodes when editing them, not just for the node "cssswitch". I want these new tabs to be displayed only when editing node of type "cssswitch".
The other problem is when I clear all cache, the tabs completely dissapear from all edit pages. Below is the code I wrote.
function cssswitch_menu_alter(&$items) {
$node = menu_get_object();
//print_r($node);
//echo $node->type; //exit();
if ($node->type == 'cssswitch') {
$items['node/%/edit/schedulenew'] = array(
'title' => 'Schedule1',
'access callback'=>'user_access',
'access arguments'=>array('view cssswitch'),
'page callback' => 'cssswitch_schedule',
'page arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight'=>4,
);
$items['node/%/edit/schedulenew2'] = array(
'title' => 'Schedule2',
'access callback'=>'user_access',
'access arguments'=>array('view cssswitch'),
'page callback' => 'cssswitch_test2',
'page arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight'=>3,
);
}
}
function cssswitch_test(){
return 'test';
}
function cssswitch_test2(){
return 'test2';
}
Thanks for any help.
hook_menu_alter() is only called during the menu building process, so you can't do dynamic node type checks within that function.
However, to achieve what you want, you can do this with a custom access callback as follows:
// Note, I replaced the '%' in your original code with '%node'. See hook_menu() for details on this.
$items['node/%node/edit/schedulenew2'] = array(
...
'access callback'=>'cssswitch_schedulenew_access',
// This passes in the $node object as the argument.
'access arguments'=>array(1),
...
);
Then, in your new custom access callback:
function cssswitch_schedulenew_access($node) {
// Check that node is the proper type, and that the user has the proper permission.
return $node->type == 'cssswitch' && user_access('view cssswitch');
}
For other node types, this function will return false, thus denying access, and thus removing the tab.

Resources