When creating a Drupal 7 content type programmatically, is there a way to add tuples of fields? - drupal-7

In Drupal 7, I'd like to create a Person content type. A person may have multiple profiles - an administrator should be able to select which profile will be considered the primary one. So, that means that I need a tuple consisting of:
A textarea, for the profile text
A checkbox, indicating that this is the primary profile
A textbox, for naming this particular profile
I need functionality to behave like that of any of the lists: I can click "Add another Item", and a set of all three of these fields will appear.
I have a vague idea of how this can be executed, but it involves using the form API to add fields before the form renders each time, as well as the necessary AJAX behavior. This seems a bit overcomplicated, since this would also necessitate creating an additional DB table to hold these tacked-on fields.
Is there a relatively simple way of doing this solely through hook_install()?

You can use drupal.org/project/profile2 or you can complete it using standard Drupal functionality, i.e. create a content type named, let's say, 'myprofile' and add all the fields use need. Then add a nodereferece (http://drupal.org/project/references) field to the user standard profie that would point to your 'myprofile' content type.
So all the 'myprofile' content, created by that user would be his profiles and the one pointed in his standard profile will be his default.
I hope it's clear enough )

Related

How to create new entity (node type) using drupal rule

I have content type award with few fields (user, position, lesson).
I have create a rule to create new node in rule actions.
When i select node type in rule it's show only two fieds : title and author.
How i get all other fields in rules action or condition .
Thanks
You have to create additional actions to set data values for the additional fields you want filled in.
It looks like (part of) what you're trying to do, is to add a Rules Action like "Set a data value" for the fields you mentioned (like lesson, etc).
But before you will be able to create a Rules Action like "Set a data value" for your field(s), you have to make sure to add a Rules Condition Entity has field (related to the field for which you want to set a value). And make sure to add that Entity has field condition BEFORE other Rules Conditions in which you might want to refer to this field. Depending on what exactly you want to do in your custom rule, an alternative might be to use content is of type.
That's also what is mentioned in the Rules UI, e.g. when you're adding a "data comparison" condition: somewhere it says:
The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type').
For a video tutorial that illustrates the importance of this Entity has field condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in it.

How do I get the SalesForce record id in a custom field

I wanted to add a simple read-only URL-field to 'opportunities' in SalesForce that contains a link to an external webpage with the 15-char record id (used in the salesforce urls) attached to it . To do this I wen to /ui/setup/Setup?setupid=Opportunity --> fields and created a new field under 'Opportunity Custom Fields & Relationships'.
I chose a field with data type 'URL' and added a default value. I thought
"http://example.com/?sfid="&id would do the trick, but this returns
Error: Field id may not be used in this type of formula
This is a vague error. Is my syntax of a default value wrong, or am i using the 'id' parameter in a wrong way? And what is the right way to do this?
I'm new to SalesForce, as you probably already have guessed.
As the other answer stated - Id will be known only after insert meaning the "default value" trick won't work for you.
You have some other options though:
Workflow rule that would be populating the URL field after save.
Formula field of type text that uses HYPERLINK function
HYPERLINK("http://example.com/?sfid=" & Id , "See " & Name & " in ext. system")
Custom link (similar to custom buttons, they appear on the bottom of the page layout. Search them in online help)
The difference between 2 and 3 is quite minor. Custom links can appear only on the record's detail view while formula fields & other urls are well... fields - so they can be used in reports, listviews etc.
You'd have to decide which version suits you best.
This is a great question. You're right, the error is very vague.
To begin with, read some of the documentation on default fields. Pay particular attention to the order of operations:
The user chooses to create a new record.
Default field value is executed.
Salesforce displays the edit page with the default field value pre-populated.
The user enters the fields for the new record.
The user saves the new record.
Default field values are calculated before any other record data including the id are available. For this reason, they cannot be calculated based on other record fields. Especially the record id, which has not yet been assigned.
To get this functionality, you will need to create a workflow rule that fires on record creation and inserts the proper value into your field.
It would be nice if we could have formula URL fields, but we don't. EDIT: I am dumb and forgot about using HYPERLINK in text formula fields, as eyescream correctly points out.

How do I display an input field for Users, in a visualforce page?

I simply want to display an input field, that will let me capture a user, so I can filter a list from a custom object by owner. CustomObject__c.OwnerId is not writable, so when I bind it to an input field, nothing is displayed on my page! I don't want to have a drop down list of users (There could be hundreds!) and I don't want to create a spurious custom object with a writeable field, related to the User object. How can I get the input field functionality for a read only field, as if it were writeable?
OwnerId field should be writeable. Unless your field security permissions are messed up or for example the field is hidden because it's a detail in Master-Detail relationship.
But when you'll manage to get it to work you'll see that most likely it's a bit weird lookup that can point to User or Queue.
If you're fine with that - great, just check the security around the field. If you need really only a lookup to user - check if you have any custom Lookup(User) field? You could create a dummy record of that type in the controller and don't do any DML with it, just use the fact it'll have the lookup.
If you don't have any custom ones - I think that Account / Contact / Opportunity owner must be a user (can't have queues). You might have to force <apex:input field... required="false"/> but other than that it should OK?

Sales-force Custom Object Edit page layout and Button

We have a custom object say Sales form. On edit apge of customer object we need to add a button Save and Add Product(similar to One we can have on Opportunity page). User forget to add Product/SKU after saving the sales form
New Button(Save and Add product), will save the sales-form first and then depends on record type will open the related list(child object).
Say a Sales form is for Custom Program, after save,. it will open up Custom Program relate list.
If Record type is of Price Change Notification it willl open up related list of SKU detail..
Is this possible, please adivse, we have 9-10 different record type, and we don't want to re-write the application with visualforce and all customization. Re-writing with Visualforce page has some pitfalls.
As far as I'm aware, you can't replace the Save button as it's part of the Edit page and not the standard layout, so to achieve this with one button you'd need to write a custom visualforce page, this need not be complicated though — a simple custom controller which uses a standardController for management of the record would suffice.
You would call Save on the StandardController and then return a different page redirect based on the record type, the page itself would pretty much only consist of an <apex:detail> tag. If you want more details I can provide more.
If you really don't want to write any custom code or pages then you'll need to do this as a two step process, i.e. use the standard page and then have a custom "Continue" button which takes the user onto a custom URL based on the record type. I've just created a contrived version of this by doing the following:
1 - Define a custom formula field on the object, this should be of type text and can use a CASE() statement to determine the URL which the user will be taken to when hitting the button (note that this was made just for the sake of an example so it forwards to the accounts standard page for the record type 'Friend' and contacts page for 'Foe').
CASE($RecordType.DeveloperName, 'Friend', '../001/o', 'Foe', '../003/o', '')
Note the reason I use a formula field here instead of the doing this in the custom button is that for some reason you can't seem
access the record types by name when defining a custom button.
2 - Define a custom button for the object called "Continue" or something similar that makes sense for you. For my example I just used the Contact object, so I referenced the custom field on my record and specified the options shown here:
3 - Customise the page layouts used by your record types to include this new button and you should be done!

Multiselect Form Field in PDF

Using PDF, is it possible to create a single form element with multiple fields of which several can be selected? For example, in HTML, one can create a set of checkboxes associated with the same field name:
<div>Select one for Member of the School Board</div>
<input type="checkbox" name="field(school)" value="vote1">
<span class="label">Libby T. Garvey</span><br/>
<input type="checkbox" name="field(school)" value="vote2">
<span class="label">Emma N. Violand-Sanchez</span><br/>
In this case, the field name is "field(school)", and when the form is submitted, "field(school)" can be supplied 0, 1, or 2 times.
Is there an equivalent construct in PDF where a single field can have multiple values. So far in my investigation, it appears that if fields are assigned the same name, it is only possible to select one field. If it is possible to implement this in PDF, what is this construct called and how can it be implemented?
Edit: To clarify, I am aware that a PDF can contain multiple form fields with different field names, and those can be selected independently, but then the grouping is implicit and not explicit as with the HTML form. I would like to use a construct that makes the grouping of options explicit, and preferably allows for restrictions (e.g. at least one required, no more than 2 allowed, etc).
Edit: If someone can find an authoritative opinion that this is not possible, that would also be a desirable answer.
Yes it is possible. In Adobe PDFs you have the checkbox concept and the radio button concept. While each checkbox and radio button can have its own name, however, they can also be grouped through a subtier via the GroupName.subobj.
Adobe describes it as follows:
The field name. This may include
hierarchical syntax in order to
facilitate logical groupings. For
example, the name myGroup.firstField
implies that the form field firstField
belongs to a group of fields called
myGroup. The advantage of creating
logical hierarchies is that you can
enforce consistency among the
properties of related form fields by
setting the properties of the group,
which automatically propagate to all
form fields within the group.
When the fields are set via a hierarchy you can then get the value of myGroup in this case, and return the selected value of the group. Similarly in the case of RadioButtons you would make sure that all fields in a group have the same name.
This approach to creating form fields
is applicable to all fields, but it
should be noted that radio buttons
require special treatment. Since a set
of radio buttons represents a set of
mutually exclusive choices, they
belong to the same group. Because of
this, the names of all radio buttons
in the same group must be identical.
In addition, the export values of the
set of radio buttons must be set with
a single statement, in which an array
of values are assigned by the
exportValues property of the Field
object. For example, suppose we would
like to create a set of three radio
buttons, each 12 points wide and 12
points high, all named myRadio. We
will place them on page 5 of the
document, and their export values will
be Yes, No, and Cancel. They can be
created as shown in the code given
below:
var name = "myRadio";
var type = "radiobutton";
var page = 5;
var rb = this.addField(name, type, page, [400, 442, 412, 430]);
this.addField(name, type, page, [400, 427, 412, 415]);
this.addField(name, type, page, [400, 412, 412, 400]);
rb.exportValues=["Yes", "No", "Cancel"];
asnyder's response led me to the conclusion that there is no automatic way to handle multiple values within a single field (as one can with HTML). asnyder's examples come from Developing Acrobat Applications Using JavaScript, available from the Acrobat Javascript Developer Center. This document provides some examples of how to manipulate checkboxes, combo boxes, and radio buttons. All of the examples shed some light on the problem and ultimately led me to the conclusion that any system that is using PDF forms will have any multi-selectable groups implicitly defined.
Using the construct of groupName.fieldName appears to be useful to manipulate the widgets as a group (in Acrobat Javascript), but the fields of a group cannot be enumerated (without enumerating all fields and filtering for the groupName), and the collective value of that group cannot be determined without programatically inspecting the values.
In other words, a multi-selectable value is not an intrinsic feature of Acrobat nor of PDF in any substantial way, though it is possible to implement such a form through programming.

Resources