I am working on a Drupal 6 to 7 site migration project. Many pages contain a custom token in [node-NID] format. The function of this custom token is to retrieve a node (identified by NID) body text.
After migration to Drupal 7, the custom function cannot work and I have no plan to write it because I find Advanced Entity Tokens can do a much better job.
So I want to keep [node-NID] in database, but whenever a node is loaded, I want to parse the loaded text to see if it contains an expression in [node-NID] format. If it does, then replace it with [aet:node:NID:body], which is custom token format that Advanced Entity Tokens offer. I will leave it to Advanced Entity Tokens to do the remaining work (replace token value)
Which node API hook shall I use?
hook_load? hook_node_load?
hook_view? hook_node_view?
I found a better solution: use Custom Filter module
Related
I'm developing SPA using ASP.NET Core and ReactJS.
In some places of application users have an opportunity to create comments, that will be shown everyone. So I have string inputs in controllers, and I save data 'as is' in database.
I've added attribute [Produces("application/json")] for each controller - to return json as results (I don't use server-side render).
My question: should I additionally encode input data (before saving in DB or before sending to user) - or this attribute automatically encodes all strings (before sending to user) and I won't have any chance have XSS attack in my application?
Thanks.
As the docs specify
A filter that specifies the expected Type the action will return and
the supported response content types. The ContentTypes value is used
to set ContentTypes
The Produces attribute will only define what the action/method will produce, it will not encode any input string
I am trying out to create an Ranker using the REST API after successfully Adding documents to the collection.
Do I need to use train.py. If so then whats the use of create Ranker API. Also while trying to create RANKER, can you please tell me where do I need to specify cluster id and collection name. Do I need to specify it in metadata.json file.
Any help would be highly appreciated.
See here for an overview of the methods available for training a ranker: https://www.ibm.com/watson/developercloud/doc/retrieve-rank/training_data.html#methods. Using the REST API directly is described under the 'Manually training a ranker' section and is intended for advanced users that might be appending additional columns to the feature vectors that are generated automatically when you use train.py.
The create Ranker REST API call does not take 'cluster id' and 'collection names' as input parameters. It assumes that you've already used the /fcselect REST API call (which does take 'cluster id' and 'collection id') to pre-generate feature vectors similar to what train.py is doing internally. Again, in the advanced use case, you might take these feature vectors and then augment them using some other custom features as described in this blog post: https://medium.com/machine-learning-with-ibm-watson/developing-with-ibm-watson-retrieve-and-rank-part-3-custom-features-826fe88a5c63#.unfm2ocik
I have a web application that uses SOLR as backend search service.
All requests that control searches are GET requests: user does something (type something, choose a page size, a sort critera) and, after pressing the search button, a corresponding servlet on the web app calls SOLR.
Now, the parameters sent to my servlet are exposed in the browser address bar; this is good because
1) each page on the webapp can be stored as permalink
2) the search can be controlled by changing directly the URL
On top of that, for a specific parameter, the page size, I would like to impose some constraint. I mean: if the select menu on the web app proposes 3 choices (5,10,15) I don't want other values.
Now, I know I can do that in my servlet but I was wondering if it is possible on SOLR side too...local params? don't know.
Briefly: the "rows" parameters on SOLR must be 5,10 or 20: if a value > 20 comes then 20 is applied.
Within Solr SearchHandlers you can predefine some configuration settings as outlined in the Configuration section. This allows you to set the following parameter behaviors
defaults - provides default param values that will be used if the param does not have a value specified at request time.
appends - provides param values that will be used in addition to any values specified at request time (or as defaults.
invariants - provides param values that will be used in spite of any values provided at request time. They are a way of letting the Solr maintainer lock down the options available to Solr clients. Any params values specified here are used regardless of what values may be specified in either the query, the "defaults", or the "appends" params.
However, these three options, do not provide for the specific behavior of limiting the rows value to 20 like you are seeking. I believe the only way to limit this within Solr would be to create a custom Request Handler and plug that into Solr. The article - Developing a Request Handler for Solr provides a good overview of the steps needed to create you own Request Handler.
I am using a drupal installation as a REST server for an Android application. I store data in nodes and occasionally a field is blank, for example a location that has no phone number. I had to standardize the JSON coming out of the drupal REST server to a specified class, so I was forced to add 0, as the value in the field.. Works great in Andriod, but when viewed on the drupal site, it looks bad..
So question is, if the value of the field is 0, Id like to change it to
'None'.
I could do this in D6 with cck, but i dont know d7 field api. Thanks
You can do this in the node.tpl.php file, in the field.tpl.php file or with the template_preprocess_field function (recommended) and with so many other options with an if statement.
See an example for first template and one for second option with the preprocess function.
If you don't want to edit tpl.php files or you don't have access to the template.php file of your theme you can use the Field formatter conditions module that allows you to do this condition. Alternatives are Custom Formatters and field_formatter_css_class.
I have a Drupal 7.9 taxonomy vocabulary according to the following scheme:
category-1
category-1 > subcategory-1-1
category-1 > subcategory-1-2
category-1 > subcategory-1-3
category-2
category-2 > subcategory-2-1
I want to reflect this taxonomy hierarchy in my page url path like
category-1/subcategory-1-1/page-123
To achieve this I'm using the modul Pathauto version 7.x-1.0. but I don't know
which pattern I have to use.
Currently I'm using [node:%field_taxonomy%]/[node:title] but with this pattern the url path is just subcategory-1-1/page-123, so the complete hierarchy isn't reflected. Is there a taxonomy tree pattern? I can't find any updated information about this and valid patterns seem to change in every version of Pathauto.
After some trial and error I came up with a way which works pretty good for me while creating custom URL paths using taxonomy terms. All you need to do is to install an additional module called Entity API. You can find it here http://drupal.org/project/entity. After installing you should enable both Entity API and Entity tokens modules. Entity tokens provides token replacements for all properties that have no tokens and are known to the entity API.
First, go and create a new taxonomy vocabulary. Let's call it "Category" and add some terms. Then for a content type you want to have a custom URL path you need to create a new term reference field. I don't know why but it's not working with the standart field_tags. So, make sure to create a new one. Let's also call it category and use our previously created vocabulary "Category" as the source. And here's another thing you need to take into account: you have to label this field with a small letter; otherwise it's not working for an unknown to me reason ;). You'll end up with a field_category field.
Go to URL Aliases administration page -> Patterns. Expand replacement patterns for Content paths -> expand Nodes -> you'll see category at the bottom, expand it. Ok, now you're ready to use taxonomy terms tokens.
Use something like [node:field-category:name]/[node:title] where [node:field-category:name] is the name of the taxonomy term and you'll have a path like mysite.com/term/title.
By the way, I use Pathauto 7.x-1.0-beta1, Token 7.x-1.0-beta2 and Entity API 7.x-1.0-beta8.
Good Luck! ))
http://drupal.org/node/1044980#comment-4562844
You can create url with this pattern:
[node:field-category:vocabulary:name]/[node:field-category:parents:join:/]/[node:field-category:name]/[node:title]
In your particular situation you can go away with using following pattern for taxonomy items:
[term:vocabulary:name]/[term:parent:parent]/[term:parent]/[term:name]
And for node pattern:
[node:%field_taxonomy%:url:path]/[node:title]
There is downside tho - term pattern will handle up to three levels in this case. So you can not make it unlimited with this approach. (I believe you can add term:parent:parent:... as many as you want).
Although, it will handle LESS than 3 levels fine (just tested to make sure).
As far as I know, basic Drupal + Token + PathAuto is not able to create paths, like you want them to.
Check my answer here. You can use the taxonomy entity index module for achieving such behaviour.