I have custom content type type_a
Inside that custom type I have few titles
Title
Body
Group1 (field_group1) (Field Collection Item Can have multiple values)
Following are the details of fields inside Group1 (Field Collection Item)
Group Item 1 (field_item1) Can have one value
Group Item 2 (field_item2) (Computed field) Can have one value
I would like to copy value of "Group Item 1" field of same field collection item inside "Group Item 2"
Below is I am using in computed code:
$entity_field[0]['value'] = $entity->field_item1[LANGUAGE_NONE][0]['value'];
But it is not working. I am getting an error
Notice: Undefined index: value in eval() (line 1 of /homepages/13/d160804/htdocs/test/sites/all/modules/computed_field/computed_field.module(466) : eval()'d code).
Please help how to do this. Thanks
$entity->field_item1[LANGUAGE_NONE][0]['value'] contains the entity id of the field collection item (which contains the fields you want to copy).
You either need to load both field collection items and set their individual fields. Eg,
$source_fc = field_collection_item_load($entity->field_item1[LANGUAGE_NONE][0]['value']);
$dest_fc = field_collection_item_load($entity->field_item2[LANGUAGE_NONE][0]['value']);
// now set values of $dest_fc with values from $source_fc
Or do some sort of clone similar to this method: http://drupal.org/node/1233256#comment-5167316
Related
im following this tutorial to implement a multi checkbox field in flask with jinja
https://gist.github.com/doobeh/4668212
It works for the most part but when I go to access the value in my code (products is the field where I used the multicheckbox) like
class CreateBoardForm(Form):
products = MultiCheckboxField(
'Select Products:',
coerce=int,
choices=[(1, 'one'), (2, 'two'), (3, 'three')])
......
if request.method == 'POST':
products=request.form['products']
print name, description, tags
print "Selected products:", products
When I print selected products I only see one value being selected. When I printed the forms object I see this python data structure ImmutableMultiDict([('products', u'1'), ('products', u'3')])
Im not sure how to get all the values for the 'products' key
you will have to use the getlist method in order to return a list of other choices.
request.form.getlist('products')
When editing bill of material (BOM) lines, the value of field "Quantity" should be copied to field "Height". How can this be achieved?
See also the following two pictures:
http://www.hostingpics.net/viewer.php?id=205252BOM1.jpg
http://www.hostingpics.net/viewer.php?id=282509BOM2.jpg
Table you are looking for is called BOM.
"Quantity" field is called BOMQty.
"Height" field is called dim1.
Both BOMQty and dim1 are of type real, so there should not be any real issues initializing the values. The main question is WHEN do you need to initialize "Height" field.
For learning purposes, try playing with this code:
BOM BOM; //Table buffer
ttsBegin;
while select forUpdate BOM
{
BOM.dim1 = BOM.BOMQty;
BOM.update();
}
ttsCommit;
For just updating the field once, I would suggest using update_recordset
For initializing the height upon line creation, add this line to BOM.insert() method, before calling super():
this.dim1 = this.BOMQty;
I try to display my taxonomy terms through views, from my vocbulary
now it goes like this
term1 name
term1 img
I need to add count of all nodes with that term, and it will look like ->
term1 name
term1 img
count of all nodes with *term1*
so far, my idea was to display term id in additional field, after use preprocess function, and run SQL query to count all nodes with that term,
but i think there must be a easy way, looking for ideas
Create Taxonomy Views.
Add relationship to the node (in case if you want to count number of nodes).
Enable grouping (Group by)
(or "Use aggregation" toggle in D7, then set the "Aggregation Settings" for each field)
In Style Settings/Format set Grouping field to 'Term ID' or 'Node ID' (depends of your query)
Add new field 'Node: NID' and set Group type to: Count
That should give you the count
Ref : http://drupal.org/node/603868#comment-4421144
Here is a simple method available for the same :
$tid = 'Enter tid number say 5';
$nids = taxonomy_select_nodes($tid, FALSE);
// count node here
$count = count($nids);
// you can load node content here
$nodes = node_load_multiple($nids);
A gridCoumn is defined in a Devex Xtra GridControl(winform type).
This column has two properties set :
FieldName --> a field name of a column in dataSource. OptionType
ColumnEdit --> as a RepositoryItemCombobox object , this object's 'Items' properties is having two value : Option1 , option2 & option3.
When data is set at runtime , the GridColumn shows the respective values in 'OptionType' column.
But now i cant change the values in any combobox of this column to other option by using the dropDown.
What am i missing ?????
I have a custom content type which has a field called "location" which is a long select list (100 or so items). I want to get an array of all locations which have a piece of content associated with them. The numeric value of this field is stored in content_type_[my_content_type], but I can't find anywhere in the database where the name of the values are stored. I hope that's not too confusing - just to be clear, I want to do something like this:
SELECT DISTINCT(field_location_value) FROM content_type_[my_content_type]
and then
SELECT field_location_name_or_something FROM where_on_earth_are_the_names_stored
and then do something with the two arrays to find the names I want.
Can anyone help?
Thanks a lot. Drupal 6, by the way.
If you mean select list field of CCK:
Get all location associated with current node (piece of content?):
$node = node_load('YOUR content ID');
print_r($node->field_location); // $node->field_location - this will array of values.
Get all values of that field (defined in "Allowed values"):
$content_field = content_fields('field_location');
$allowed_values = content_allowed_values($content_field); // array of values
I found this, after much trial and tribulation, in the database table content_node_field_instance, under the field's widget settings field.
This Drupal 6 code snipped will retrieve your cck field value options and put them in the $allowed_values variable as an array. Replace 'YOUR_CCK_FIELD_NAME' with your cck field name (name, not label)
$cck_field_name = 'YOUR_CCK_FIELD_NAME';
$cck_field = db_fetch_object(db_query("SELECT global_settings FROM {content_node_field} WHERE field_name = '%s'", $cck_field_name));
$cck_field_global_settings = unserialize($cck_field->global_settings);
$allowed_values = explode("\r\n", trim($cck_field_global_settings['allowed_values'], "\r\n"));
In Drupal 7 if you have a field of type List (text) then I have written the following function to return an array of options:
function get_drupal_select_options($field_name) {
$options = unserialize(db_query("SELECT c.data
FROM field_config_instance i
INNER JOIN field_config c ON c.id = i.field_id
WHERE i.field_name = :fieldname", array(':fieldname'=>$field_name))->fetchField());
return $options['settings']['allowed_values'];
}