How to show a forum on a custom path? - php

By default forums are enabled on forum on my site; I want them to move to share/forum. What are the different approaches I can take for it, and which one is best?
I tried doing this with the Pathauto module, but then the breadcrumbs are showing "Home >> forum" when I would expect it to show "Home >> share >> forum."

there are many ways,
1) either you can use pathauto(which u used but it uses default nid to track things so thats why in breadcrumbs it's showing like that)
2) use subdomain module and shift ur forum (if ur host is supporting that)
3) use a use separate forum module like phpbb or so and put it to ur desired path and using redirect.
whichever suits u..

If you want to show the forum pages only on share/forum, you can use the following code in a custom module.
function mymodule_menu_alter(&$items) {
if (isset($items['forum'])) {
$items['share/forum'] = $items['forum'];
unset($items['forum']);
}
if (isset($items['forum/%forum_forum'])) {
$items['share/forum/%forum_forum'] = $items['forum/%forum_forum'];
unset($items['forum/%forum_forum']);
}
}
If you want the forums to be visible in both the old, and the new path, you can use the following code.
function mymodule_menu() {
$items['share/forum'] = array(
'title' => 'Forums',
'page callback' => 'forum_page',
'access arguments' => array('access content'),
'file' => 'forum.pages.inc',
);
$items['share/forum/%forum_forum'] = array(
'title' => 'Forums',
'page callback' => 'forum_page',
'page arguments' => array(1),
'access arguments' => array('access content'),
'file' => 'forum.pages.inc',
);
return $items;
}
As for the breadcrumbs, you need to implement hook_menu_breadcrumb_alter(), considering what reported in the documentation page.
Implementations should take into account that menu_get_active_breadcrumb() subsequently performs the following adjustments to the active trail after this hook has been invoked:
The last link in $active_trail is removed, if its 'href' is identical to the 'href' of $item. This happens, because the breadcrumb normally does not contain a link to the current page.
The (second to) last link in $active_trail is removed, if the current $item is a MENU_DEFAULT_LOCAL_TASK. This happens in order to do not show a link to the current page, when being on the path for the default local task; e.g. when being on the path node/%/view, the breadcrumb should not contain a link to node/%.

Related

how to create a custom drupal 7 edit page

Im a TOTAL newbie to drupal development so please help me here, ok i have created a custom module which so far creates a custom database how do i go about creating a list page in the backend that i can use to manage each item in the DB and how do i go about creating a custom edit form to manage the insert/ edit / delete of each item
function rollover_res_schema() {
$rollover_res = array();
$rollover_res['rollover_res'] = array(
// Example (partial) specification for table "node".
'description' => 'Positioning for rollovers',
'fields' => array(
'rollover_res_id' => array(
'description' => 'The primary identifier for a node.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'rollover_res_actual' => array(
'description' => 'The main rollover plain text.',
'type' => 'text',
'length' => 255,
'not null' => TRUE,
),
),
'indexes' => array(
'rollover_res_id' => array('rollover_res_id'),
),
'primary key' => array('rollover_res_id'),
);
return $rollover_res;
}
If you're a total newbie to Drupal development you should not be writing ANY code for the first month or two and you shouldn't do custom database code the first 6 months.
Start with learning about Fields and Views and once you grasp these you can add one of Display Suite, Context or Panels.
The key to learning how to do things in drupal is:
1) google search how
2) see how other modules do it. In this case, look at some core modules, such as the block module. In there you'll see the schema in .install, and you'll see some functions that create forms for saving new blocks, such as block_add_block_form. You'll need to read up on the form API. But basically, you'll create a form hook to display a form, a menu hook to create a page to hold the form, and a hook to submit the form. If you grep through your code base, you'll see many of examples that you can copy. In fact, there are drupal example modules you can download that cover most of the basics: https://www.drupal.org/project/examples
But to learn how to interact with the database, you could find a module that does something similar to what you're doing and look at how it uses hook_menu to set up page callbacks, forms for editing data.

Create new page in drupal

Iam new in drupal. I want to create a page and want to add data in page directly with out using backend content. I have created a page like this, page-test.tpl.php. How can I call this newly created page in browser?
First you have to create your own custom module.Let the module name be test.Create 2 files namely test.info and test.module.Declare a hook_menu function inside the test.module file.Since your module name is test your hook_menu will be named as test_menu.
Hook_menu enables modules to register paths in order to define how URL requests are handled. Paths may be registered for URL handling only, or they can register a link to be placed in a menu.
Test.module
function test_menu() {
$items = array();
$items['test'] = array(
'title' => 'My Page',
'description' => 'Study Hard',
'page callback' => 'test_simple', //Calls the function
'access arguments' => array('access content'),
);
return $items;
}
function test_simple() {
return array('#markup' => '<p>' . t('My Simple page') . '</p>');
}
Test.info
name = Test
description = Provides a sample page.
core = 7.x
After adding this try clearing the drupal cache and then navigate to /test.Try this link if you are a beginner.Try reading hook_theme which allows you to use your custom template.More about hook_theme here.Hope it might help u mate.. :)
Pages in drupal are stored in the database, not in actual code files like old websites used to. The template files (.tpl.php) are exactly that - templates. So for example, lets say you have blog content. You'd have to create a content type of 'Blog'. you could then create a template file (ex. node--blog.tpl.php) which would format the way the blog pages would look. But you would still need to add new pages through the drupal interface in order to add them to the site. You could always use an input type of PHP if you'd like to include php in the body of the page.
If you simply want to display a php file in your browser from your site, you can just upload a php file of your choice to your sites/default/files directory and access it directly via the file path.

Buddypress bp_core_new_nav_item() function not working to create new navigation item under ”my profile” tab

So I’m trying to add a new navigation under the “my profile” tab in buddypress once a user logs in. I created and am using the bp-custom.php file in my wp-content/plugins directory (outside of the buddypress directory) to insert the custom code.
This is the code I have in bp-custom.php file (and that’s all I have!)
<?php
//place for custom buddypress functions
bp_core_new_nav_item(
array(
'name' => 'feedback',
'slug' => 'Feedback'
));
?>
I got the following error in my browser.
————————–
Server error
The website encountered an error while retrieving http://myhostname.com It may be down for maintenance or configured incorrectly
—————————
I am using the frisco for buddypress theme, not sure if this is part of my problem.
What can I do to fix this error? (move bp-custom? misuse of function? theme incompatibility?) I will rate you up if you give me the correct answer. Thanks in advance!
-Alex
Please use this one:
bp_core_new_nav_item( array(
'name' => __( 'My Links', 'bp-my-links' ),
'slug' => 'my-link',
'position' => 80,
'screen_function' => 'bp_my_link_screen_my_links',
'default_subnav_slug' => 'my-link'
) );
Please put this code and see the under my profile tab there it will display the new "My Link" menu.
asked and answered here:
http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/bp_core_new_nav_item-not-working-to-create-new-navigation-item-under-my-profile-tab/

Drupal 7 - why is my action not showing up in the triggers menu?

I've added a second element to the userbeep_action_info() hook which I plan to make into a new action, but when I check it in the Triggers page, it doesn't appear. The first item, userbeep_beep_action shows, but not the second. Why is this? Is it because it's configurable that it needs extra information to appear? My book asks me to check for its presence at this stage but it isn't appearing.
<?php
/**
* #file
* Writes to the log every time a user logs in or edits a node.
*/
/**
* Implementation of hook_action_info().
*/
function userbeep_action_info() {
return array(
'userbeep_beep_action' => array(
'type' => 'system',
'label' => t('Beep annoyingly'),
'configurable' => FALSE,
'triggers' => array('node_view', 'node_insert', 'node_update', 'node_delete')
),
'userbeep_multiple_beep_action' => array(
'type' => 'system',
'label' => t('Beep multiple times'),
'configurable' => TRUE,
'triggers' => array('node_view', 'node_insert', 'node_update', 'node_delete')
)
);
}
/**
* Simulate a beep. A Drupal action.
*/
function userbeep_beep_action() {
watchdog('beep', 'Beep! at ' . '');
}
From the Book's error corrections site - http://www.drupalbook.com/errata3
Error: The screenshot in Figure 3.4 is of the wrong overlay. (What is
shown in Figure 3.4 is not available until an instance of the advanced
action has been created as described on pp. 43-44 and in Figure 3.5.)
Correction: What should be shown in Figure 3.4 is the overlay
accessed by clicking the Configuration link in the top menu and then
clicking on the Actions link in the Configuration page, and finally
scrolling to the bottom of the overlay to the "Create an Advanced
Action" drop-down select box.
The figure you're basing your assumption that your code isn't working isn't the right one. Complete the rest of the chapter and you'll get it working. Use the resource above to hunt down more errors in the book.
Hint: There are quite a few...
It is not showing up because advanced (configurable) actions need to be created and configured once defined in code at: /admin/config/system/actions, where as simple actions do not. It may also require the configuration form and actions to be defined first as well.

Drupal clean urls on custom page GET request

I have a drupal page (content type page) that should accept GET values using clean urls.
I put the following code in the page body using the php code input format.
<?php
$uid = $_GET['uid'];
$user = user_load($uid);
print $user->name;
?>
Now the following link http://www.example.com/mypath/?uid=5 results in user 5's name being displayed. Great.
My question is: Can this be accomplished using clean urls such that going to http://www.example.com/mypath/5 has the same result? (Similar to using arguments in views)
You can do what you ask in the menu system using hook_menu in a module, but you can't create an alias where a part of it is a name. The whole alias is a name, so you can't extract info from it. Using hook_menu you can do this:
function my_module_menu() {
$items = array();
$items['path/%user'] = array(
'title' => 'Title',
'page callback' => 'callback',
'page arguments' => array(1),
'access callback' => '...',
'access arguments' => array(...),
);
return $items;
}
Then in your callback function you will have the value or argument 1 in the path which corresponds to the uid (in reality it will be a loaded user object because of %user).
Yes. Use arg() instead of $_GET
Keep in mind that arg() uses the $_GET['q'] by default and so effectively translates an alias before returning the result. Thus, the parameter you are trying to access may be in another position.
For example, the path myalias/5 might translate into taxonomy/term/5. In this case, arg(2) is 5.
For more information on the Drupal arg() function, see http://api.drupal.org/api/function/arg/6
If you use Views to assemble these pages, that part can be done easily for you by putting UID as an argument provided in the URL.

Categories