3

I want to generate nodes for a content type using fields of some other content types. For example I have three content types A,B,C. All three content types have some common fields as well like Title, Category and Date. I want to create another content type D to hold only those common fields.

Now here I want to generate content automatically for content Type D. I'm looking for a technique in which I can define that, "fetch data" from these common fields of A,B C content types to fill fields of content type D and generate nodes automatically for content type D.

Any suggestions about how to get this to work?

  • Why did you tag this question with "Views"? Nowhere in your question you mention anything about a View, so I suggest you improve your question to make that clear also. It might be the missing piece to fully understand your question (and also improve my answer to make it an even better fit). – Pierre.Vriens Feb 3 '17 at 9:38
  • Thanks for your suggestions. but I thought its is related to views as well because views can edit nodes directly. – Ather Khan Feb 3 '17 at 9:49
  • views is for questions asking about a view, not for questions where the OP believes the Views module is the solution to the problem they are having. – kiamlaluno Feb 3 '17 at 11:56
1

Similar to the previous answer, I would also recommend to use the Rules module to implement what you're looking for. However, your major challenge is going to be "What is actually the trigger to create such node of content type D" (and your question says nothing about that).

A solution that would work for sure is to (also) get the Views Rules module involved in the puzzle you're trying to solve. Some details about this module (from its project page):

Provides Views directly as Rules actions and loops to seamlessly use view result data.

If you're not familiar with Rules (yet), the previous quote may seem a bit cryptic (it may make you think like "so what, how can this help me?"). Therefor some more details about how to move forward using these modules:

  1. Create a view (using Views) so that you have 1 Views result (row) for each node of content type "D" to be created, whereas that view has fields (columns) for each of the fields, title, etc from your nodes of content type A, B, C that you want to use to create your node of content type D. Important: use a Views display type of "Rules".
  2. Create a custom rule in which you use the Views Rules module to iterate over each of these Views results in a Rules action, using the Rules technique known as a "Rules Loop".
  3. For each iteration step in your Rules loop, perform a Rules Action to create an entity, of type Node (and content type D). At that point you'll have all data from each column of your Views results available as so called Rules Parameters. So at that point it's a piece of cake to populate the various fields of your node of content type D.
  4. The only remaining thing is to decide about the Rules Event to use for this rule to be triggered. But that's up to your own imagination (any Rules Event will do). Optionally, you may also want to add whatever extra Rules Condition(s), also up to your own imagination.

Easy, no?

PS: I'm assuming this question is about D7 ...

  • @AtherKhan: merci for the accept ... sounds like your answer to my question (at the end) is something like "indeed" ... so thank you also for that confirmation ... PS: next question? – Pierre.Vriens Feb 3 '17 at 9:54
1

The Rules module is your friend here.

You may use it to create an entity (here a node) after saving a new content of type A B or C (or any other event). Then you can add actions (set a data value) to fetch field values from A, B and C for your new content of type D. The first action would be of course Create an entity, then set data values.

You may find a great set of tutorials about Rules at Learning the Rules framework series.

Here is a short example : after saving a new Drupal Article, create a new Drupal Basic Page with the Body extracted from the Article and an automatic node-title.

{ "rules_automatic_node_creation_based_on_another_node" : {
    "LABEL" : "Automatic node creation based on another node",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert--article" : { "bundle" : "article" } },
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "page",
            "param_title" : "Basic page from Article [node:title]",
            "param_author" : [ "node:author" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : { "data" : [ "entity-created:body" ], "value" : [ "node:body" ] } }
    ]
  }
}
  • Please review the minor edit I applied to your answer, trying to improve it. If you don't like my edit at all, just perform a rollback, ca va? BTW, I partially agree with your answer (Rules is part of the solution). But are you sure you can solve the question here with ONLY using Rules? If so, I'd like to learn how to do so (can you extend your answer to better explain the solution you have in mind?). – Pierre.Vriens Feb 3 '17 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.