Method: Scrivito::BasicObj.create
- Defined in:
- app/cms/scrivito/basic_obj.rb
.create(attributes = {}, context = {}) ⇒ Obj
Create a new Obj in the CMS.
This allows you to set the different attributes of an Obj by providing a hash containing the attribute names as keys and the corresponding values you want to set. The defaults set via Obj.default_for are taken into account.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/cms/scrivito/basic_obj.rb', line 139 def self.create(attributes = {}, context = {}) attributes = with_default_id_attribute(attributes) if obj_class = extract_obj_class_from_attributes(attributes) obj_class.create(attributes, context) else attributes = build_attributes_with_defaults(attributes, context) attributes = prepare_attributes_for_instantiation(attributes) extraction, api_attributes = prepare_attributes_for_rest_api(attributes) workspace = Workspace.current obj_data = workspace.create_obj(obj: api_attributes) obj = BasicObj.instantiate(obj_data) obj.revision = workspace.revision extraction.notify_persisted(obj) obj end end |