How can I rewrite drupal page metatags from within a Rules module action? - drupal-7

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

Related

react-flow renderer edges remain in ui without any parents

I implement a web page in reactjs, and should show some input and output nodes and the edges between them. the data inside each nodes will change periodically and i need to change the data for them time to time.
i implemented it and works fine, but after stay in this page for a minute it can not remove the previous edges and it remain in the web page.
I uploaded a video clip about this issue
any idea about this issue?
issue with edges in react flow- youtube link
Finally I found the issue, i set the random generated id for edges, which sometimes make a repeated id and cause this issue, when i set the unique id for each edges issue solved. :)

Get content Id (nid) from path on views block

I just can't seem to wrap my head around Drupal relationships. I have been reading and watching tutorials, but as soon as I try to get my own project done - I fail. I think it's very basic, so I would love to understand it. Maybe someone here can help me understand how it works :)
On my drupal site, I want to keep track of some private game tournaments.
I have created a content type called contestant, which has fields like: Tournament date, Player name, Final Position. I can then create a view that list the information from one tournament. I used the help I got from this thread: drupal views dynamic filter
I would like to have the view described above as a block. And then place that block-view on a "tournament description" page. I could do this, by simply creating a new block each time, and then manually place it on the page it should be shown (structure-->Blocks-->configure), but that is not an elegant way to do it. I am pretty sure this is where Relationships should be used. But I fail to understand how to create this relationship, so that the specific block view, that matches the specific tournament description page will be displayed together.
Use a Content:Nid as a Contextual filter.
WHEN the Filter value is not in the URL >>
Provide default value
Content ID from URL

Drupal 7: Form for node maintenance

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

Drupal 7: Hook for Node processing before page loaded

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.

How to prefill a field of a node using rules in Drupal7?

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.

Resources