Insert Description Text to Drupal User Registration Form - drupal

I am using the profile module and have several categories for different fields. I want to add a small bit of text to the top of one of the categories saying what the category is for. The information would be displayed when a new user registered. Basically I want to tell users to only fill out a category on certain conditions. Can anyone tell me how I could do this? I'm guessing I could use hook_form_alter(), but I don't know where to start.

You want to create your own module and implement hook_form_alter like you mentioned.
In a nutshell:
Use print_r($form) in hook_form_alter to look through what you'll need to edit
A category will have a #type => 'fieldset' and #title => 'What you named your category'
Remove print_r and add $form['categoryname']['#description'] = 'My description here!';
You may have to update your module's "weight" as I described here (replacing CCK with Profile).

As Chris Ridenour alluded to, you can do this with hook_form_alter() in a custom module:
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id === 'user_profile_form') {
// Change personal to the name of the category.
$form['personal']['#description'] = t('This is a description of your personal information.');
}
}
In this example, it adds a description to the personal category on the user profile form.
You can read more about what types of things you can modify in the Forms API reference. If you have the Devel module installed, dsm($form) within your hook_form_alter() will pretty-print the form structure to give you an idea of what's available to alter.

Related

SilverStripe field-level Page editing permissions

I need to implement field-level permissions in a Page model, in a SilverStripe 3.2 website.
Let's imagine I have an ArticlePage.php model. It has the usual fields like $MenuTitle and $Content, and I've added other properties like $Subtitle and $Author.
I can protect the whole model by using providePermissions() and the associated canEdit() methods, but I need to protect individual fields / page properties.
What I need to do is:
Admins should be able to edit all fields
Users in another permissions group should only be able to edit and save $Subtitle
Is this possible in SilverStripe 3.2? Is there a SilverStripe way of doing it?
If not, is there a way I can Identify the user group of the current user and then perhaps conditionally show the $field->addFieldToTab() code? Is it possible to stop the user saving a field by posting the data maliciously, perhaps by adding the missing fields via inspector?
Thanks in advance.
So here's my own answer. This post was helpful: https://www.silverstripe.org/community/forums/customising-the-cms/show/11693
You can conditionally show CMS fields and tabs using code like the post demonstrates:
public function getCMSFields()
if(!Permission::check('PERMISSION_LABEL'){
$fields->removeFieldFromTab("Root.Main","MenuTitle");
$fields->removeByName('BannerImages');
// etc...
}
// etc...
}
Having defined the permission:
public function providePermissions()
{
return array(
'PERMISSION_LABEL' => 'Can edit some fields',
);
}
My concern with this approach was that a user could still create a form field on the page using inspector or JS and submit values for fields they should not be able to see.
Having tested this it appears that field values are not saved if they are not listed on the page, but are sent with the POST data. Although I'd love to know if a SilverStripe expert could confirm that.

Wordpress post to user relation ship

Is there any way to connect post to specific user in wordpress. Is there any plugin available. Or any one know the code for doing that.I have a custom post type stories. When adding stories i need to chose the corresponding users from user list. Please help
Install Post2post https://wordpress.org/plugins/posts-to-posts/
Then in your function.php write this code
p2p_register_connection_type ( array(
'name' => 'releated_user',
'from' => 'story',
'to' => 'user'
) );
here story is your custom post type slug. related_user is just a connection name.You can name it as what you like.
Then in your post type section you can see an option for selecting corresponding user.
In the custom post type setup, you first need to ensure that this post type allows for authors to be set.
This comes in from the arguments when registering the post type.
$args = array('supports'=>array('author'=>true));
If you have an admin account, you can set who the author is using the quick edit function or by allowing to see it under screen options on the full edit page.
Other than that, you can make your own complete post meta box to allow for multiple authors. I cant see a plugin on the wordpress plugin directory so creating your own to fit your needs and wants will be your best bet.

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.

drupal show/hide certain fields based on author

I would like to show / hide certain fields in my Drupal view based on whether the current user is the author of the node being viewed.
I installed the Views Custom Field module which seems to allow this, but I have no knowledge of PHP, so wondered if anyone could help me with the PHP code.
Something like this (check that $data has uid, maybe different name):
global $user;
if ($user->uid == $data->uid) {
print 'something';
}

How do I move the tag section below the content in Drupal 6?

I have enabled taxonomies in the form of Tag, and I would like the tag field to show up below the content when users are editing the page. Where would I make that setting change?
For editing? You don't need code at all, provided you use the CCK module on your site.
Go to Admin > Content Types. Click on "manage fields" on the content type you want to edit, then drag the Taxonomy module form underneath the body. Hit Save, you're done.
For maximum control, you can also use the Content Taxonomy module which turns taxonomies into CCK fields.
You'll need to implement hook_form_alter() within a custom module to adjust the weights of the node edit form fields:
/**
* Implementation of hook_form_alter().
*/
function yourModule_form_alter(&$form, $form_state, $form_id) {
// Is this a node edit form?
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
// Yes, adjust taxonomy weight to push it to bottom of form
$form['taxonomy']['#weight'] = 42; // TODO: Find appropriate number by inspecting the other form element weights
}
}
Edit: As bmann pointed out in a separate answer, this is not necessary if you have installed the CCK module on your site, as it adds a configuration option for the field order under 'admin > content types > manage fields'.
This is a sample from one of the node.tpl.php files in the themes/ directory.
<div class="taxonomy"><?php print $terms?></div>
If you move that code below
<div class="content"><?php print $content?></div>
It should work.
Assuming I've understood your question correctly!

Resources