How to programatically unhide Drupal 7 content field - drupal

On my company's Drupal 7 site, I created a field for one of our content types through the admin UI. We decided to hide it from the user until some styling changes make it through to production. Is there a was to programmatically unhide the field via an update hook? I know get at least some of the field information through the field_info_field function, but I'm not sure how if it contains the setting needed to make the field visible to the user. Any help on this would be appreciated.
I know I can unhide it through the UI once the changes hit production, but it would be nice to have an automated way of doing this.

You can hide it programmatically from it's node template with hide() function:
https://api.drupal.org/api/drupal/includes%21common.inc/function/hide/7.x
You can do that conditionally, i.e. by checking user role first.
Now, I'm not sure will this work from update hook, and I'm not even sure why you want to use that hook?!? If users are allowed to edit that content type and you actually want to hide it from edit form then check out my answer here:
Drupal 7 - Hide certain form fields of a content edit form depending on the content data

You can use https://www.drupal.org/project/field_permissions drupal module to hide and unhide fields to users of specific role.Initially during development the field can be made visible to admin role and then later on the permission can be granted to users of other roles

Related

Wordpress - Proper way to manage custom users

I have a site in Wordpress.
The functionality I need is such that, I can create 'users' of the site. These users have no purpose editing the Wordpress site in any way, and don't need to know we're even using the wordpress platform.
These users need to be able to edit their contact info and upload/view/swap out their own resume, using a page that I will build for them (not the wp-admin dashboard in any way). This resume will be PDFs and WordDocs.
At first I thought I'd just use the built in Wordpress Users and Roles that Wordpress offers. However, I'm not sure how I would attach resumes to that user, and let that user edit their own resume. I know I can use the 'user_contactmethods' hook to attach basic fields. However, I'd be trying to attach a link to a file that Wordpress hosts, and would need to be able to replace that file on a whim, in php. Also, my goal is to prevent them from ever using the Wordpress dashboard or editing tools.
Next, I thought I could create a custom post type for a 'SiteUser'. That would make it easy to manage a PDF/WordDoc attached to that post type. Also, that user wouldn't have any way to access the Wordpress stuff. Before I do that though, I wanted to ask on here if this really is the right way to do this.
This solution feels hacky.
Can I get some proposed solutions to this problem that could be perceived as 'the proper way'?
Thanks
Here is a rough idea of what you are looking to do.
Step 1
Create the user role for these new users
Step 2
Set the permission for them and disable backend access and redirect all access of those roles to a custom page /account/
Step 3
Use Advance custom fields plugin to create some custom fields on the user meta. (text, file, image)
Step 4
Apply some login logic/form and Link to a /account/edit-info/ custom page with the acf frontend form. https://www.advancedcustomfields.com/resources/create-a-front-end-form/
Step 5
Use these info to display somewhere on the /account/ page
Optional
Using gravity forms instead to manage user data entry gives better control but requires more coding, and a better user experience.
Front-end Admin Steps
Repeat Step 1-2
Loop site user and list them and their custom field files Have a button that opens a Gravity form with the user ID text field pre-populated and hidden, and have a file uploader element.
Add backend hooks after validation directly replace the user meta
containing the file path or ID (however you choice to store it in
Advance custom fields)

Drupal 6.x Add More Module - No end to adding more

Simple question for all of you here dealing with Drupal 6.x...
With Drupal's Add More module, is there a way to configure my webform so that there is no limit on how many of a specific fields I can add more of?
Please see my image for example:
For example, I'd like to enable the user to add as many titles as they would like. Is that doable?
Unfortunately, it's not currently possible to add unlimited "add another" functionality with webforms. And if this functionality does become a reality someday, I doubt it will be backported to the Drupal 6 version of the module. From the webform modules author (quicksketch):
there is no progress on this subject. The ability to support multiple
values requires a tremendous amount of re-architecting, including
changes to the way CSVs are generated, analysis, the database
structure, and the UI (both for administrators and users). I wouldn't
expect this feature to be added any time soon.
See this thread for more information:
http://drupal.org/node/354381
I would suggest using a node and the CCK module plus rules and views to collect this information.
Assumptions:
Anonymous users can fill out the current form
You need some way of retrieving the data that is submitted
Regular users of the site should not be able to view submissions
Very loose directions:
Create a content type and add all of the fields that your current webform contains to it. CCK has the ability to store unlimited values out of the box. On the field settings page, inside the Global Settings fieldset, select "Unlimited" for the "Number of Values" field.
Give anonymous users permission to Create [your-new-content-type] Content on the Role Permissions page.
Using the Rules module, create a new triggered rule that fires on "Content is about to be viewed" with an condition "Content has type [your-new-content-type]" and an action of redirect to homepage (or a custom error page that you created). (Note: this is a bit of a performance hit. There are better ways to restrict access to this content type, but for the sake of this tutorial, this was the easiest to explain)
Using the Views module, create a new view with Style set to Table. Add each of the fields in [your-new-content-type] in the fields section. Under "Access" choose "role" and select the role that is assigned to your user. Add a "page" display, give it a Path and save. This is the page you will use to view submissions.
Optional:
Use the Rules module to send yourself (or the submitter) an email when a node of [your-new-content-type] is created.

How to display content submission page to users?

I would like to add a page where users can submit content (not just a comment, but a specific 'content type' including the relevant fields). I could use the regular admin link but that would require alternating the admin theme a lot and also would need to hide/disable things i otherwise need.
Is there a good way to display a submission form to the users through which they can submit content? I was looking for a solution via 'Views' but didn't get far.
I hope i managed to get my point across.
drupal 6 or drupal 7?
in drupal 7 you have the field API that is very helpfull to get the fields of an entity.
in drupal 6 you can create your own form with forms API and run node_save() in the submit function.
If the only problem with using the usual node/add/node-type page is that you don't want users to see the admin theme, then you don't have a problem. You can disable the admin theme for non-admin users - on the permissions page, look for "System / View the administration theme". It's already unchecked by default, I think. Any adminny-type pages they access will use your default public-facing theme.

Creating a custom content type in drupal

i tried to create a custom content type in drupal but unnecessary features like Title, Menu settings, and Revision Information, URL aliases come with it which i don't really want ..coz it doesn't mean anything to the user..
how can i hide all those things, just preserving the fields(say only 3 fields from CCK) that i want only for this custom content type??
thanks..
You can automatically generate titles using the auto_nodetitle module, which also enables you to remove the title field from the node submission form.
As others have mentioned above, most of the other form elements don't appear to non-admin users anyway.
With auto_nodetitle module, you can hide it, not remove it. Then, simply assign a title like "your-content-type-nid", so it will be different for each node (nid will be different).
That would be a better title than an empty one.
You will need to do a combination of things to do what you want. One of those is to add the module auto_nodetitle suggested by others. You can hide the "Body" by removing the "Body field label" from the edit screen for your custom content type. Lastly is that you will have to do the right settings for your CCK fields.
If you have CCK fields you want them to be able to edit and others you do not want them to edit, you will need to enable the Content Permissions module in the CCK section of the modules admin page. Once you've done that, you can go to the role permissions page and set what roles have access to which fields. While permissions can potentially hide CCK fields from the user, you can also control what fields are in the teaser, node, and RSS views via the "Display fields" section of your content type editing screens.
Menu settings, revision info and URL alias type info is admin stuff. If you create a new user that doesn't have admin permissions, I'm pretty sure they won't see it.
Can try some thing like below using hook_form_alter.
function my_module_form_alter(&$form, $form_state, $form_id) {
if($form_id='company_node_form'){
$form['menu']['#prefix'] ='<div style="display:none">';
$form['menu']['#suffix'] ='</div>';
$form['revision_information']['#prefix'] ='<div style="display:none">';
$form['revision_information']['#suffix'] ='</div>';
$form['author']['#prefix'] ='<div style="display:none">';
$form['author']['#suffix'] ='</div>';
$form['options']['#prefix'] ='<div style="display:none">';
$form['options']['#suffix'] ='</div>';
}
}
You might want to try the NodeFormCols module. It does several handy things, among them is to add a Manage Form button which allows you to hide most fields in an input form.

Drupal CCK Field Level Visibility

I am using the Drupal 6 module Content Profile to allow using a CCK defined type as a user profile which is working well. The issue I have is that I want the first completion of the profile to trigger an action however the user may save the profile without completing it. My thoughts on this is to have a checkbox by the save button which states 'My profile is complete' which the user will select once they are happy with it, and I have another module which creates a trigger by using the node_api hook and checking the type of the node, the action, and the value of this checkbox.
Once this trigger has been raised I don't want that checkbox to appear again however. If I could set the visibility of the checkbox using PHP code that would work as I could write a short script to determine if the completed action has already happenede and if so hide the checkbox. Is there a module that allows this? I haven't been able to find one.
I have also looked at using the same node_api hook to manipulate the profile as it is being displayed however the node just seems to have the values for the fields and not a form object that can be manipulated as I would have expected. IS there a way to programatically manipulate a CCK form?
Thanks
I think hook form alter is what you are after. This can perform alterations to a form before it is rendered.
I would suggest another approach using the Save & Edit module. Set your CCK profile type as "unpublished" by default. Allow users to save it and/or save AND publish it with this module. On publish, use triggers and actions.
This approach is arguably more in keeping with the Drupal way - configuration over customization.

Resources