Drupal - page route - content profile - drupal

I can't seem to get the page route module to move to the next page, after it creates the profile page.
1. I created a route called Registration
2. Inside the route I have two pages,
a) Content Profile Editing Form
b) Node Add form
The page route should take the user to the profile create page, and then route to the create a group node page.
Problem is after the user is directed to the content profile editing form and clicks next, it redirects back to the profile form instead of going to the next page.
Any ideas, this does not seem normal at all.
Charles

thanks for the help. I found the solution. I thought it might be a module or a coding change I have made so I decided to create a new drupal install and only install the modules needed.
I still had the same problem, very strange indeed. I eventually found the this article, with someone whom has had the same issues.
http://drupal.org/node/699458
The following needs to be added to the pageroute.module
<?php
/**
* Submit function for all pageroute forms, except submit-like tab buttons
* Redirect to the set target.
*/
function pageroute_page_form_submit($form, &$form_state) {
$page = &$form_state['page'];
$route = &$form_state['storage']['route'];
/* hack saturnino part */
if(!empty( $page->options['neighbours']['forward']) )
{
drupal_redirect_form($form, $route->path.'/'.$page->options['neighbours']['forward']);
return;
}
/* hack saturnino part */
// no page access -> try redirect
if (!$route->checkPageAccess($page->name, $form_state['target'])) {
unset($form_state['storage']);
$form_state['rebuild'] = FALSE;
if ($route->options['redirect_path']) {
drupal_redirect_form($form, pageroute_get_redirect_path($page));
return;
}
drupal_not_found();
pageroute_exit_now();
return;
}
$form_state['rebuild'] = TRUE;
}
?>
thanks for your help

Related

Modify User Roles in WordPress?

I have been working on a client's WordPress Website and last day my client want to hide navigation menu and pages from author/contributor categories.
I have searched and tried some of the plugin but didn't get the exact thing. Please let me know what should i use to hide some pages from user and from navigation.
Only Admin can see all the pages and other members should see only 1 section that is allowed to visible for them.
Thank You
use this plugin to manage All roll:
http://wordpress.org/plugins/user-role-editor/
Here is the Complete function for removing each Menu and submenu from wp-admin for another user:
function remove_menus() {
global $menu, $submenu;
$restricted = array(__('Dashboard'), __('Profile'), __('Users'), __('Tools'), __('Comments'), __('Settings'), __('Plugins')); //Here you can also define the name like Pages
end($menu);
while (prev($menu)) {
$value = explode(' ', $menu[key($menu)][0]);
if (in_array($value[0] != NULL ? $value[0] : "", $restricted)) {
unset($menu[key($menu)]);
}
}
unset($menu[5]); // this is just for example
unset($submenu['edit.php'][16]); // this is just for example
}
Now You have to put a conditon for other user i.e:
$thisusername = $current_user->user_login; // this is to get the current user login
if (($thisusername == "user123")) {
add_action('admin_menu', 'remove_menus');
}
Note: You can find many plugins but all of them are not in depth like this code.Well you can try this plugin to manage your user's roles.Capability Manager Plugin

How can I redirect a Drupal user after they create new content

I want to redirect my users after they create a piece of new content, instead of directing them to the 'view' page for the content.
I have seen mention of using hook_alter or something, but I'm really new to drupal and not even sure what that means?
Thanks!
As you mention that you are new to Drupal, I'd suggest to take a look at the Rules module. You can add a trigger on for content has been saved/updated and add an action, to redirect the user to a specific page.
You can however do the same in a light weight custom module using a form_alter hook.
First, find the form ID of the form. For node forms, it's the [node-type]_node_form.
Then, you can add a new submit function to be executed when the form is submitted. In this submit handler, set the redirect path.
See this guide on a basic how-to on creating a module.
Your module code would be something like belows:
<?php
function mymodule_mytype_node_form_alter(&$form, &$form_state) {
$form['#submit'][] = 'mymodule_node_submit_do_redirect';
}
function mymodule_node_submit_do_redirect($form, &$form_state) {
$form_state['redirect'] = 'my_custom_destination';
}
A much much simpler approach is to set the destination in the node form's URL.
For example, if you opened http://example.com/node/add/mytype?destination=my_custom_destination, you will be redirected to that URL instead of the node view page.
This works for me using Drupal 7, after creating a new module!
Put into the .module file the following PHP code:
<?php
function custom_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == '[node-type]_node_form') {
$form['actions']['submit']['#submit'][]= 'my_custom_submit_handler';
}
}
function my_custom_submit_handler($form, &$form_state) {
$form_state['redirect'] = 'http://www.expamle.eu/?q=node/2';
}
You just need to change [node-type]_node_form with your node type name (e.g.: example_node_form) and the http://www.expamle.eu/?q=node/2 with the correct URL.

How to logout and display message after login under certain condition?

Given a Drupal 7 website I want to customize log in behavior: When a users logs in I want to check if they are in a blacklist. If they are in that list I want them to be automatically logged out and told about the reason they are being kicked out. So In one of the custom modules of this drupal I have add the following hook:
function mymodule_user_login(&$edit, $account) {
if(blacklist(&$edit, $account)) {
drupal_goto("/user/logout/");
drupal_set_message('Acces denied','error');
}
}
However, my code doesn't work. What I'm doing wrong? I'm sure the hook is executed because I checked this using a watchdog. However, I also discovered the hook only gets executed if admin is the user who is logging in.
Are there any alternatives (maybe using Context module)? Any suggestions would be aprreciated!
Thanks!
Your code does not work because drupal_goto() calls drupal_exit() so the rest of your script does not get executed.
What you are trying to do will not work because user_logout() itself calls drupal_goto() to the front page.
You can however add an extra validation callback in the user login form so you can prevent users from logging in altogether.
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'user_login':
case 'user_login_block':
$form['#validate'][] = 'mymodule_custom_user_validation',
break;
}
}
function mymodule_custom_user_valudation($form, &$form_state) {
if (// Add your blacklist conditons here. ) {
form_set_error('', t('Your account is blacklisted, therefore you cannot login to this account'))
}
}
?>
If your interested in using the Login Destination Module, then you could create some type of rule to hook into your blacklist check and then redirect that user to the "user/logout" path. Let me know if you have any questions.
What exactly is your "blacklist()" function doing?

Close Overlay and Redirect to Custom URL on Save-Node in Drupal 7?

When my node form saves, I want to close the admin overlay and redirect to a custom URL that is stored with the node. hook_form_alter() is setting $form['#redirect'] but I think that would only work with no admin overlay.
I have never used it before myself, but i think you can call the overlay_close_dialog(...) function from your hook_submit
See http://api.drupal.org/api/drupal/modules--overlay--overlay.module/function/overlay_close_dialog/7 for more info
Kept googling my way here as well.. this is the working solution:
Inside your form:
$form['somebutton']['#submit'] = array('your_custom_callback');
Add a custom callback
function your_custom_callback($form, &$form_state) {
//redirect users to Drupal.org
$url = "http://drupal.org";
if (module_exists('overlay') && overlay_get_mode() == 'child') {
unset($_GET['destination']);
overlay_close_dialog($url, array('external' => TRUE));
$form_state['redirect'] = FALSE;
} else {
$form_state['redirect'] = $url;
}
}
Kept googling my way here and wanted to post a final solution that worked for me on Drupal 7 (got here thanks to jakraska's suggestion). First use hook_form_FORM_ID_alter() to hook into the specific form you want to alter
/**
* Implementation of hook_form_FORM_ID_alter()
*
**/
function mymodule_form_FORM_ID_alter(&$form, &$form_state) {
$form['#submit'][] = 'mymodule_callback';
}
Then write your callback that will render the page. In my case I simply wanted to close the overlay, so that's why I used the $form_state['redirect'] = FALSE;
function mymodule_callback(&$form, &$form_state) {
// Form API will re-render the current page and pass the redirect information to the overlay JavaScript
overlay_close_dialog();
// stay on the same page after all submit callbacks have been processed.
$form_state['redirect'] = FALSE;
}
If you want to redirect to another path,
See https://api.acquia.com/api/drupal/modules!overlay!overlay.module/function/overlay_form_submit/7 - I believe that should get you there.
Make sure to use $form_state['rebuild'] = TRUE; inside your hook_submit function, otherwise it would not close overlay after form is submitted.

remove "profile" admin-menu from administrative panel

I am using WordPress, and I want to remove "profile" menu-option completely
Any one is having idea how can I achieve this?
Thanks
For the sake of completeness, here's how to do it programmatically...
// Run the function on admin_init
add_action('admin_init', 'remove_profile_menu');
// Removal function
function remove_profile_menu() {
global $wp_roles;
// Remove the menu. Syntax is `remove_submenu_page($menu_slug, $submenu_slug)`
remove_submenu_page('users.php', 'profile.php');
/* Remove the capability altogether. Syntax is `remove_cap($role, $capability)`
* 'Read' is the only capability subscriber has by default, and allows access
* to the Dashboard and Profile page. You can also remove from a specific user
* like this:
* $user = new WP_User(null, $username);
* $user->remove_cap($capability);
*/
$wp_roles->remove_cap('subscriber', 'read');
}
I know this is late but I just stumbled on this and thought I would add to it. That does remove the sub-menu profile menu item but does not remove the menu profile item. For someone like me who has created a completely custom profile page, I don't want my users to access the profile.php page at all. So this code will work for that:
function remove_profile_menu() {
remove_submenu_page('users.php', 'profile.php');
remove_menu_page('profile.php');
}
add_action('admin_menu', 'remove_profile_menu');
And if you only want to do this for certain capabilities....use this code:
function remove_profile_menu() {
// Only the Admin can see the profile menu
if(!current_user_can('update_core')) {
remove_submenu_page('users.php', 'profile.php');
remove_menu_page('profile.php');
}
}
add_action('admin_menu', 'remove_profile_menu');
You can use the current_user_can() function to determine who you want to see the menu items.
Profiless plugin does that on the subscriber-level.
If you wish to do that for other groups, you should probably use it in combination with Capability manager plugin.

Resources