I have two fields I want to fill with the exactly same values; users should fill only one.
I also have a function which checks if the second field is empty. Is there any change in how the field values are obtained and set in Drupal 6, and Drupal 7?
EDIT:
I am trying to edit module right now.
Yes, I am talking about node fields.
$node array has only ID of terms I added to node. How do I get the term name, knowing its ID?
Since you tagged this question with cck, I'm going to assume you are working with node fields.
To copy the value of one field (x) to another (y), you can either install the Computed Field module and set it up so that the value of y is computed from the value of x, or you can create a custom module with something similar to the following hooks:
This hook copies all of the data from field x to field y:
function mymodule_node_presave($node) {
$node->field_y = $node->field_x;
}
This hook only copies the value of the first instance of field x to field y:
function mymodule_node_presave($node) {
$node->field_y[$node->language][0]['value'] = $node->field_x[$node->language][0]['value'];
}
You might want to do a print_r on $node->field_x and $node->field_y as the structure of your data may be different based on the type of field you are using. If you want to check if either of the fields are empty, you can wrap the assignment statement in a conditional that calls your custom function.
One good way for finding out a field's value, is using field_get_items() which is provided by field API.
field_get_items($entity_type, $entity, $field_name, $langcode = NULL);
Where:
$entity_type: Is something like 'node' or 'user',
$entity: Is the entity which it's field value is needed,
$field_name: machine name of the field,
$langcode: The language that entity is stored in, It is optional and if not provided, field_get_items will find it out automatically.
Related
Made a script for updating a wp post custom fields. All works fine for the fields with type text or number but a I have issues updating the field of type PostObject that contains a select list. Can not find any info on the format of the argument that must be passed to the update_post_meta() in order to update the selected value in the WP database of type PostObject.
For now the post id is static just for testing. And do not take into consideration the field name of the $_GET[] const. It is related to a other custom field. It is just given to see structure of the script.
My script test version I use tot change a specific custom field.
The select where I ge the value from. It returns a string.
Options of the field I want to change from user input.
Plugin name:
Found the solution with the trial and error method :-))).
So, in case you are modifying a custom field of type PostObject, you have to pass as the 'value' argument the ID of the post you want to be the new value of the custom field:
update_post_meta( 15896, 'specialita', '208' );
Thus, in this case the old post ID was for example 325 and and we replace it with a new post with the ID 208.
I'm trying to generate unique id for label & input pairs.
After googling I now know that, unlike with handlebars, there is no array #index syntax extension in spacebars yet (also anybody knows why Blaze development has been inactive since the version 0.1 for past 5 months?).
So I ended up using the JS Array .map() solution inspired by this blog post and other posts. However, this solution returns label & input pairs of objects which DOM appears to be rendering the same on 'pagination' through Session.
Live example: http://meteorpad.com/pad/NXLtGXXD4yhYr9LHC
When clicking on first set of "Non-Indexed IDs" checkboxes, then next/previous, DOM will display new set of checkboxes correctly.
However clicking on the second set of "Indexed IDs" checkboxes below, then next/previous, DOM seems to retain the same checkboxes because one selected from the previous page remains checked on the next page.
What am I doing wrong or missing?
I also put the code on github for quick testing & refinement:
The solution, which I've found by looking at the ObserveSequence source, appears to be to give your generated objects a unique field called _id (generated like {{questionId}}:{{questionIndex}}:{{choiceIndex}}). See this meteorpad: http://meteorpad.com/pad/2EaLh8ZJncnqyejSr
I don't know enough about Meteor internals to say why, but this comment seems relevant:
// 'lastSeqArray' contains the previous value of the sequence
// we're observing. It is an array of objects with '_id' and
// 'item' fields. 'item' is the element in the array, or the
// document in the cursor.
//
// '_id' is whichever of the following is relevant, unless it has
// already appeared -- in which case it's randomly generated.
//
// * if 'item' is an object:
// * an '_id' field, if present
// * otherwise, the index in the array
//
// * if 'item' is a number or string, use that value
//
// XXX this can be generalized by allowing {{#each}} to accept a
// general 'key' argument which could be a function, a dotted
// field name, or the special #index value.
When the _id is absent, it uses the index in the array, so I guess ObserveSequence assumes it's the same object with changed fields, rather than a different object, so it re-uses the old elements rather than destroying them and recreating them. I suppose the name _id is chosen so that it works well with arrays generated by .fetch() on a Minimongo cursor.
I don't know if this is documented behaviour, or if it might change in the future.
The case is following: I have a custom Content Type with a filed "data_field", for example. I want to have a block on a sidebar that will properly process and display data of this "data_field" field. How can I access that with Drupal API?
P.S. I understand that this problem can be solved with Views in some way, it has an ability of content-specific displaying, but I'm interested in the way it's achieved owing to API.
To render a field with the default Drupal settings for the content type:
$n = node_load($nid_of_content);
$n = node_view($n);
print render($n['field_somevalue']);
You can specify a node display format as well, eg
$n = node_view($n, 'teaser');
If you want to manipulate field content in a different way, use the raw field value:
$n = node_load($nid_of_content);
$value_you_want = $n->field_data_field_somevalue['und'][0]['value'];
This assumes you're not using any language/translation functionality - the 'und' stands for "undefined" and states that no language is has been explicitly set for the node.
If the field can contain multiple values, iterate through ['und'][0]['value'] to ['und'][x]['value']
The above code displays a raw value for most field types. Use print_r($n->field_somevalue) during development to find out what values are available to you; it depends on the field type. For example, file types give you 'uri' (among others) instead of 'value', text fields also have 'safe_value' which has input format filtering applied, long text fields will have 'summary' and 'safe_summary', &c.
In Views, I have an exposed filter that looks at the UID (User ID / Author), but is there a way to limit this to "ONLY" the users who have posted in this content type?
I tried adding a "Content: Author" relationship and hit Apply. I'm not exactly sure why, but it wasn't until this point that I could go back into the relationships and see MORE options, like: "User: Content authored" (which must then be dependent on the first relationship?) so I selected that one too and set it up like so:
Now I was able to go to the exposed filter and select the relationship:
But this didn't work-- the exposed filter continues to show all the registered users.
I also tried putting in a User Reference field (to this content type) and attaching that to a relationship, but it didn't allow anything to show and gave this SQL warning:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_field_hidden_name.uid' in 'on clause'
How can I limit this author exposed filter to "ONLY" the users who have posted in this content type?
There are a few drupal modules that may help you out. Such as Corresponding node references
However, if you are good with php code, you can create the logic to query the database and return the desired results (which would be the columns of the table). Create a contextual filter, then select a field (any field should work, but best select something in either content type). Then edit it, WHEN THE FILTER VALUE IS NOT AVAILABLE -> Provide default value -> PHP Code
$nid = arg(1);// current node id
$query = "SELECT <desired_field_column_name> FROM {<field_data_table_name>} c
WHERE c.<column_that_is_same_as_nid> = :nid";
$result = db_query($query, array(':nid' =>$nid));
$id = array();
while ($row = $result->fetch())
{
array_push($id, $row->field_curator_target_id);//put each node id that's referenced in array
}
$separated = implode("+", $id); // separate them by + for AND , for OR
return $separated; //eg.32 + 30 would represent nodes that you want.
In Linked theme there is answer about Views Selective Filters (aka "Views Selective Exposed Filters", aka views_filters_selective, aka views_selective_filters).
This module adds filters that have suffix "(selective)" in their names – add one you need instead of filter w/o the suffix.
In apex code I want to enumerate the legal values for a picklist field. To do this I can just call Account.Foobar__c.getDescribe().getPickListValues() and I've got a list of Schema.PickListEntry values.
However it's possible to setup multiple record types for a given sObject. For example Account might have "Manufacturer", "Distributor" and "Retailer" record types. In the Salesforce setup it is possible edit (limit) the picklist entries for each field based on record type. So Retailer type accounts might only use a subset of the picklist values for the Foobar field.
So basically I want Account.Foobar__c.getDescribe().getPickListValues('Retailer') however this is not the syntax. The validFor method looks promising, but it seems like it is only for field dependent picklists - a picklist filtered only by record type returns false for isDependentPicklist.
I know this is an old post, but maybe the info below will help someone who still needs the answer.
I found here that one can actually get a list of record type specific picklist values by making a describeLayout() call.
Using your example (C#):
DescribeLayoutResult result = binding.describeLayout("Account", new string[] { "01230000000xxXxXXX" } );
PicklistEntry[] values = result.recordTypeMappings[0].picklistsForRecordType[12345].picklistValues;
Replace "01230000000xxXxXXX" with a RecordTypeId of your Retailer record type object. Use the query "SELECT Id FROM RecordType WHERE Name = 'Retailer'" to get the value.
Replace 12345 with an index of your picklist object that you would like to get values of.
You can't do it in pure Apex AFAIK, unfortunately. The metadata API does expose it.
Related opinions: http://boards.developerforce.com/t5/Apex-Code-Development/Any-way-to-obtain-picklist-values-by-record-type/td-p/287563