I am in Drupal 7 and want to do some side processing, i.e. neither to affect the fields nor the themeing, on a node, before the node's page is rendered. In other words, I want to implement in a custom module an 'appropriate hook' so that I can pick-up node's info. Again the implementing function I want to be executed in .module file rather than in template.php.
Thanks
Check http://api.drupal.org/api/drupal/includes!module.inc/group/hooks/7
Probably you should have a look at hook_node_view.
Related
I am trying to detect when a content-type node is updated or saved for the first time and has attached audio.
If this is the case I want to re-write the Twitter Card meta tags to turn an image card into a media card and then include a link to the relevant audio field to complete the media card and player options.
I have a rule set that detects the creation / update of a node; I can screen for nodes of the correct "type", and my rule fires appropriately, but I am failing on my rule action to re-write the meta tags.
Rules tells me that $node is available to me, so I've been trying to do:
$node->metatags[LANGUAGE_NONE]['description']['value'] = 'Some description.';
$node->metatags[LANGUAGE_NONE]['title']['value'] = 'Some title | ZZZ';
This I have followed by an "entity save" action. My rationale is to write the changes before the recursion lock kicks in and stops the rule executing.
I've been going round the houses for a day trying to solve this. Can someone please point me in the right direction?
Many thanks.
Didn't fully understand your requirement. But you can easily update your node datas using hook_node_presave (https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_presave/7.x) before node is being saved in to database.
Use hook_node_insert(https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_insert/7.x) and hook_node_update(https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_update/7.x) if you need to do the same thing after the node is saved in to database
I created a view that makes a block for my homepage. I need to render this block in my PHP. Problem is, I need the nid to render the node and I usually get these by going to Structure -> Blocks -> Click configure and the ID is in the page url at that point. For this view I created, there is no ID, just /admin/structure/block/manage/views/cfps-block/configure.
How can I get the ID so I can render this programmatically?
If i understand your problem correctly.
Open you view
For example:
Blockquote
example.com/admin/structure/views/view/custom_view/edit
get the Machine Name of that view suppose it is block, than you can render it by using following code.
echo views_embed_view('custom_view', 'block');
Read the manual if any confusion:
https://api.drupal.org/api/views/views.module/function/views_embed_view/7
i've the following hierarchy structure : Group -> Family -> products -> Product details.
each node is retrieve through an $http service.
i would like the user to be able to drill down until the final product details and i would also like no reloads when the user hits the back button as parents never changes.
i've succeeded to build the first part using routes and it works pefectly but now each time i want to go back the controller of the parent view (last view) is reloaded and i don't know how to avoid this reloading.
i am thinking of changing my way of doing it by having only 1 view (while 4 before) and manage the drill down through a directive, do you think it could be considered as a good practice ? how would you implement this ?
You could check out AngularUI Router, since one of its main feature is the ability to nest states & views.
Have a look at the UI-Router Demo, source code here.
I have a content type which will contain just one node.
I need a form for the maintenance of this node, with the following logic:
If the node exists, show a form populated with the fields content, and a "update" buttom;
If not exists, show a clear form with a "insert" buttom.
What is the Drupal correct way to do this?
Thanks for any help!
if the content type will contain one node why will drupal need to check weather the node exists?
Drupal rules http://drupal.org/project/rules coupled with the core triggers and actions modules can help you setup up system logic events
Using rules it's easy to fill field values of a node after user pressed the save button. Just add a rule on before saving content event. But is it possible to have a rule to prefill a node field before edit form is shown to the user? So he has a change to corrent the default values.
This is a very late reply, but hopefully someone might find it to be of some help:
If you are creating the node using Rules, you could save it first, selecting "Force saving immediately: true". In the next step, you could set the value of the node field. You might need to save again. (also 'Force save' immediately.) And in the next step, do a 'page redirect' to the edit url.
Not sure if this is an elegant way to do it, but it might work. I had a somewhat similar requirement (not the same), and this is how I finally did that - by saving first, and then redirecting to the edit url of the saved node.
Not sure if this is something you can accomplish with rules or not, but if you go to structure->content types you can click "manage fields" and edit the default value of any field other than the title field (which you could always turn off and replace with a custom title field with a default value)
I think there are basically two ways of doing this:
1) Use Rules Forms. I don't know very much about that module, and I have had some less than perfect experiences with the module, but I'm fairly certain it could be done with the module.
2) Use Rules to create a node, populate the relevant field values, and then send the user to the edit page. One downside with this approach is that if the user decides to abort the node creation, you'll end up with a half-populated node that needs deletion in one way or another.
If you choose to go for option 2, and are comfortable with Page manager and Panels, it is probably worth checking out the Rules Panes module.