Community Documentation

Creating entities

Last updated December 9, 2012. Created by mitchell on May 21, 2012.
Log in to edit this page.

You can use this action to:
* create a user
* create a node
* ...

Creating Multiple Entities

To create multiple entities, use the 'Save entity' action after the 'Create a new entity' action.

Below is an example component rule which illustrates this. When executed, it asks for a list of titles from which to create a group of pages.

{ "rules_list_create" : {
    "LABEL" : "List create",
    "PLUGIN" : "rule",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "titles" : { "label" : "Titles", "type" : "list\u003Ctext\u003E" } },
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "titles" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "entity_create" : {
                "USING" : {
                  "type" : "node",
                  "param_type" : "page",
                  "param_title" : [ "list-item" ],
                  "param_author" : [ "site:current-user" ]
                },
                "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
              }
            },
            { "entity_save" : { "data" : [ "entity-created" ], "immediate" : 1 } }
          ]
        }
      }
    ]
  }
}

About this page

Drupal version
Drupal 7.x
Level
Beginner, Intermediate, Advanced
Audience
Site builders
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.