I am learning Drupal 7 computed field. According to web sources they say i should use $entity instead of $node for Drupal 7.
I have a content type product with custom fields field_price and field_discount. I need a computed field field_finalprice = field_price - field_discount.
As a first step I am just trying to assign field_discount to my finalprice so I created a computed field with code
$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_discount')));
I do not get any value. Please provide any links that uses computed field for drupal 7.
There is an update in the comments IIRC http://drupal.org/node/1271050
$entity_field[0]['value'] = $entity-> field_price[LANGUAGE_NONE][0]['value'] - $entity-> field_price[LANGUAGE_NONE][0]['value']
should work
Related
I have created a new index that is populated using an indexer. The indexer's datasource is a SQL view that has a Timestamp column of type datetime. Since we don't want a full reindexing each time the indexer runs, this column should be used to determine which data have changed since the last indexer run.
According to the documentation we need to create or update the datasource by setting the HighWatermarkColumnName and ODataType to the DataChangeDetectionPolicy object. The example in the documentation uses the REST API and there is also way to do it using the azure search portal directly.
However I want to do it using .netsdk and so far I haven't been able to do so. I am using Azure.Search.Documents(11.2.0 - beta.2). Here is the part of the code I use to create the datasource:
SearchIndexerDataSourceConnection CreateIndexerDataSource()
{
var ds = new SearchIndexerDataSourceConnection(DATASOURCE,
SearchIndexerDataSourceType.AzureSql,
this._datasourceConStringMaxEvents,
new SearchIndexerDataContainer(SQLVIEW));
//ds.DataChangeDetectionPolicy = new DataChangeDetectionPolicy();
return ds;
}
The commented code is what I tried to do to initialize the DataChangeDetectionPolicy but there is no ctor exposed. Am I missing something?
Thanks in advance.
Instead of using DataChangeDetectionPolicy, you will need to use HighWaterMarkChangeDetectionPolicy which is derived from DataChangeDetectionPolicy.
So your code would be something like:
ds.DataChangeDetectionPolicy = new HighWaterMarkChangeDetectionPolicy("Timestamp");
I created a custom field checkbox in trac. Written here.
How to make the field were only available for users to TRAC_ADMIN?
example trac.ini
[ticket-custom]
newfield = checkbox
newfield.label = Checkbox field name
newfield.value = 0
newfield.permissions = TRAC_ADMIN
newfield.permissions - does not work
Thank you.
You could use BlackMagicTicketTweaksPlugin. The feature is proposed in #9289, and I will probably work on adding the feature to Trac for release 1.4 (probably about a year away since 1.2 is just about to come out).
I found this article useful when indexing documents, however, how can I attach additional fields so I can pass in, say, the ID of the document in our database for use in displaying the search results? I thought by using the Fields (Of the ExtractParameters class) property I could index additional data with the document, but that doesn't seem to work or that is not its function.
Example code:
var solr = ObjectLocator.Instance.Resolve<ISolrOperations<IndexDocument>>();
var guid = Guid.NewGuid().ToString();
using (var fileStream = System.IO.File.OpenRead(Server.MapPath("~/files/") + "greenroof.pdf"))
{
var response =
solr.Extract(
new ExtractParameters(fileStream, "greenRoof1234")
{
ExtractFormat = ExtractFormat.Text,
ExtractOnly = false,
Fields = new[] { new ExtractField("field1", "value1"), new ExtractField("field2", "value2") }
});
}
#aitchnyu is correct, passing the values via the literal.field=value method is the correct way to do this.
However, according to this post on ExtractingRequestHandler support in the SolrNet Google Group, there was a bug with the ExtractParameters.Fields not working properly. This was fixed in the 0.4.0.X versions of SolrNet. Please make sure you are using one of the latest versions of SolrNet. You can obtain that by one of the following means:
Project Site Downloads
NuGet PreRelease Package
Also that discussion has some good examples of using the ExtractingRequestHandler in SolrNet as well as a workaround for adding the additional field values if you cannot upgrade to a newer version of SolrNet.
This is sufficient: http://wiki.apache.org/solr/ExtractingRequestHandler#Literals .
In general use a literal.field=value while uploading.
It turned out not to be an issue with SOLRNet, but my knowledge of SOLR, in general. I needed to specify the fields in my schema. After i added the fields to my schema they were visible in my SOLR query.
I had a previous question combining two questions on this subject...but I think I explained a little bit vague...too much story...so I will ask just one question at a time :)
I'm trying to create a node with a rule. Rules needs to create a new "product" node and show it to the user so that they can fill in some detail fields and then save it.
I'm trying to do this with Rules -> Create new entity. As "Entity type" I choose "Node" and as "Content type" I choose my product content type. Then I also need to fill in a title. There is where it goes wrong. I tried to put every type of data or string inside this Value field of Title and Rules accepts it and saves the rule. But every time the rules fails creating the node with the following error message:
Unable to create entity node": Invalid data value given. Be sure it matches the required data type and format.
How can I effectively create a new node of a certain content type and present it to the user for further finishing, all with rules?
You could just do it with code:
global $user;
$node = new stdClass;
$node->type = 'type';
$node->title = 'A title';
$node->uid = $user->uid;
node_object_prepare($node);
node_save($node);
drupal_goto("node/$node->nid");
Hope that helps
Here are two tutorials with lots of comments on how to create a Drupal 7 node in code: 1, 2.
The code can be added into the hook_node_insert or hook_node_update hoooks so that nodes can also be added while saving other nodes.
I am storing a type in the EPiServer DDS that has a few properties such as string and guid. I now want to add a new property of type string to that type. How is it possible to get the DDS to recognise the new property added to the type and add it to the schema for the type in the DDS.
You need to remap the type to the store like this:
Let's say your class is called Car
var store = DynamicDataStoreFactory.Instance.GetStore(typeof(Car));
store.StoreDefinition.Remap(typeof(Car));
store.StoreDefinition.CommitChanges();
If you're then going to use the store instance directly after then do a refresh:
store.Refresh();
You can find more info about the DDS here:
http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-6/EPiServer-CMS-60/Dynamic-Data-Store/
Paul Smith
Developer Evangelist
EPiServer
The next version of CMS / EPiServer Framework will ship with a PowerShell cmdlet to do this from a script.
For the CMS 6 version I suggest you add the code to the Global.asax or create an initialization module
(http://world.episerver.com/Blogs/Magnus-Strale/Dates/2010/2/Changes-in-the-initialization-system-from-EPiServer-CMS-6-RC1/)
You can first check if the type and store are aligned:
var store = DynamicDataStoreFactory.Instance.GetStore(typeof(Car));
if (!store.StoreDefinition.ValidateAgainstMappings(typeof(Car), false))
{
store.StoreDefinition.Remap(typeof(Car));
store.StoreDefinition.CommitChanges();
}
This way you only remap when needed.