Drupal 7 add contact_site_form to a block but only one category - drupal

I have two categories set up in my site wide contact forms:
General
Technical
I want to embed the general form in a block. I have this code that works for loading the form:
<?php
require_once drupal_get_path('module', 'contact') .'/contact.pages.inc';
$form = drupal_get_form('contact_site_form');
print render($form);
?>
But I only want to load the General form and not have the drop down select list.
I installed the Contact Forms modules which give me access to the forms seperatly so I know it can be done. This module didn't help with this situation thoigh as the forms still have the same ID.
Any help here would be much appreciated.
C

I think you can use other variables in form alter for this. Based on some variable we can alter a given form only in particular case. For example $_GET['q'] of contact page is 'contact'. You can check this and set default value for form category select list only if $_GET['q'] != 'contact', then hide a select list with '#type' => 'hidden'.

ok, This modules did the job...
http://drupal.org/project/contact_form_blocks

Related

Create a blog post from content in another post type

The Wordpress site I'm working on has a section for "News" (which is the regular blog/posts) which will be used for any news the company has to write about. Then I have a custom post type for Promotions, which has it's own page.
I want the client to be able to add his promotion content through the custom post type, which is going on the Promotions page, however I'd like this content to also be "cross posted" into the blog/news without forcing the client to write it up twice.
Is there a way to do this? Thanks.
Just a note: The reason I have the promotions as a custom type on it's own instead of just having them do it all from the blog is because I needed custom fields that would be unnecessary for any other kind of blog post.
Two options:
1) Use the Shortcode API
And in your cross-post you'd add the shortcode [crosspost id="POST-ID"]. Where POST-ID corresponds to the numeric ID of the other post (post type). Instead of ID, the title could be used, see the function get_page_by_title.
Create your own plugin for this. Add a sample shortcode from the Codex and use the function get_post to get the contents of the cross-post.
2) Use Advanced Custom Fields plugin
With it, adding meta boxes with custom fields is a breeze. And it has a Post Object field that's basically a Cross Post functionality.
You could do it a lot more simply by adding a filter to wp_insert_data(). For example, in your theme's functions.php file add the following:
add_filter('wp_insert_post_data', 'post_to_other', 99, 2);
That filter will then run anytime you add a new post. In the function post_to_other(), you look to see what type of post is being submitted. If it's a promotion, then insert a second copy as a News item.
function post_to_other($post_id, $post){
/** check $post to see what type it is, if it's a promotion */
if($post->post_type == 'promotion'){
$second_post = array(
'post_type'=> 'post',
'post_title'=> $post->post_title,
'post_name' =>$post->post_name,
'post_content'=> $post->post_content,
'post_author'=> $post->post_author,
'post_status'=> 'publish',
'tax_input'=> array('taxonomy_name'=>array('news'))
);
wp_insert_post($second_post);
}
}
I'm running out the door so I don't have time to double check the exact code but that's the basic structure of it. The tax_input bit is optional, lets you specify a category if you want. You'll probably need to tweak it a bit but that's the basics.

Anyone know how to add a field or column to the /ADMIN/CONTENT listing page? DRUPAL 7

I would like to add a field / column to the Content Administration Overview page but it appears the easiest theme override to do this has been deprecated with D7.
In D6 I could just override the method:
theme_node_admin_nodes($form)
But this method no longer exists for D7. What's the equivalent replacement or do I actually need to hook into node_admin_nodes() now and modify the form directly?
For me it was super easy with these two modules:
views bulk operations (VBO)
administration views (needs VBO)
As soon as both modules are installed and activated you can go to your views (admin/structure/views) where now 3 additional views appear (Administration comments, Administration nodes, Administration users). You then just need to edit the view "Administration nodes", where you can add and arrange everything you want as usually with views.
I wanted to add a column displaying all content's nids. Worked super well!
You'll have to hook into the form, the theme element has been completely removed node_admin_nodes() in Drupal 7.
It's actually node_admin_content() that you'll need to hook into as node_admin_nodes() is no longer a form function, it just builds up elements that are used by node_admin_content().
Fortunately the elements in node_admin_nodes() and node_filter_form() (the two functions used in node_admin_content() to build up the page) are nicely structured and will be very easy to override.
I've been able to add an element to the bottom of the table. Although I am unsure how you ADD a coloumn into the body of the table?
function seven_form_alter(&$form, &$form_state, $form_id) {
drupal_set_message("Form ID is : " . $form_id);
//get node_admin_content
//$nodeAdmin = drupal_get_form("node_admin_content");
// Add a checkbox to registration form about agreeing to terms of use.
$form['node_admin_content']['poland'] = array(
'#type' => 'checkbox',
'#title' => t("I agree with the website's terms and conditions."),
'#required' => TRUE,
);
}
The Administration Views module replaces a lot of admin listings with real views (as in Views module) that you can edit and configure any way you want it.

How would you approach creating a "Mad Libs" style form in Drupal?

I'm intrigued by the idea in this article: "Mad Libs" Style Form Increases Conversion 25-40%. I'd like to test such a form in place of the registration form on a couple of Drupal sites; however, I'm not sure how to approach such an unorthodox form using Drupal's Form API.
Would it be practical to alter the existing user_register form using hook_form_alter? Is there a better way?
Ideally, I'd like to be able to token-ize each form field on an arbitrary form, then enter the "story" text with token IDs where the fields should appear. I'm not sure where in the form rendering process to do that though?
Interesting. You should build the form as one would normally build a drupal form, only with the fields in it. Your narrative would go in the template file that should be used to theme the form. Using template to theme forms is extremely easy. For example in your _theme hook, bind the form with a template file,
testmodule_theme()
{
return array(
"user_aboutme_form" => array(
"arguments" => array( "form" => NULL ),
'path' => $path_to_template_folder,
"template" => "user-aboutme-form",
)
);
}
Make sure you clear your theme cache in between. In your template file, you'll get the entire form array, and you can render individual elements using drupal_render function. With custom styling you can get the same look and feel as on the above website. The only catch here is to make sure you render the root form element i.e. drupal_render($form) after you are done with rendering individual form elements, that would put in form token values in the form, otherwise the form won't work.

What is the best way to add a content/view to a node

I am developing a module to display video. I have created a view so-called navigation for the user to select a video from a list.
Now I want o add this navigation to every node with type = 'video'. I don't know whether I should create a template for it ( then I have to put the template file in theme folder which is not so good ) or use some kind of hooks ( I haven't figured out which one to use ) ?
I tried to install http://drupal.org/project/views_attach, however the view only appeared in the content (after Title) which is not what I really want. I want it to be on top of the title.
Please help. I'm using drupal 6
Thanks in advance.
Sounds like you'd just create the navigation block any number of ways, and tell the block to only show on video node types using php in the display rules. Maybe menu_block module can help you here.
You can render the view anywhere you want in your node template with views_embed_view.
Create a template specific for your video node type: node-video.tpl.php and insert the view where you want it.
If you don't want to do it via template files, the Panels module can be used to have different layouts per node type. Once you install it, create a variant under the node_view panel and restric that variant to be selected for nodes of type 'video'
I finally found how to implement a view as block (simply select block as a content view) and I use this code below to display a block in a certain node type
<?php
$match = FALSE;
$types = array('video'=>1);
if ((arg(0) == 'node') && is_numeric(arg(1))) {
$node = node_load(arg(1));
$match = isset($types[$node->type]);
}
return $match
}
?>

Create dynamic link in drupal

Could anyone tell me how to create a dynamic link in drupal?
I want to create a link to a group membership list. I have created the view with the argument. How do I create the menu item link to the view? It will be different depending on the group.
Thanks
I create a redirect link for such situations. For example, if I want a menu link to direct the user to their user edit page, I will implement hook_menu() as follows:
function my_module_menu()
{
$menu['user/cp'] = array
(
'title' => 'User Control Panel',
'page callback' => 'user_cp_redirect_page',
'access callback' => 'user_is_logged_in',
'type' => MENU_CALLBACK,
);
return $menu;
}
Then, I set the page callback to look like this:
function user_cp_redirect_page()
{
global $user;
drupal_goto('user/' . $user->uid . '/edit');
}
In short, you can't. Drupal's menu system caches the entire menu: menu items can't appear differently for different users (although you can set access permissions for them). If you want menu items to appear, you have to either register them in hook_menu() (which is only called when the menu is rebuilt), or you have to add them manually in Menu administration.
The handbook page on the Menu system provides more information about this.
However, you can create a fake menu using a block display in your view and the HTML list row style. This is useful if you wanted to have a category listing block, outside the main menu structure.
It sounds like you may need to use views arguments to filter your results if you are pulling different "groups" based on a single view. I would start here to learn more about views arguments: http://drupal.org/node/54455, if this is indeed what you are trying to accomplish.
EDIT:
I guess it would help if I read the question fully. It sounds like you are already using arguments for your view. In this case you already have created dynamic links to your page. Try putting the arguments for each "group" at the end of the URL. For example if created a page display with a path news, you can pass the argument by appending it at the end of the URL. So, if you created an argument using "Node:Created Year" you could then filter this content by putting something like example.com/news/2009 to access only the nodes that were created in 2009. What you pass is dependent on the type of argument you have created.

Resources