Module: Scrivito::AttributeContent::ClassMethods
- Included in:
- BasicObj, BasicWidget
- Defined in:
- lib/scrivito/attribute_content.rb
Instance Method Summary collapse
-
#attribute(name, type, options = {}) ⇒ Object
Defines an attribute.
-
#attribute_definitions ⇒ Scrivito::AttributeDefinitionCollection
Returns the attribute definitions.
-
#description_for_editor ⇒ Object
This method determines the description that is shown in the UI and defaults to class name.
-
#hide_from_editor ⇒ Object
This method disables the creation of
ObjsorWidgetsof the given type using the UI.
Instance Method Details
#attribute(name, type, options = {}) ⇒ Object
Defines an attribute.
In order to be able to persist model data in CMS you have to define its attributes. By defining an attribute you tell Scrivito under which name its value should be persisted, which type of content it will contain etc, which values are allowed etc.
Attributes are inherited, e.g. if a model Page defines an attribute title of type string and a model SpecialPage inherits from Page, then the model SpecialPage will also have the attribute title. Inherited attributes can be overridden, e.g. SpecialPage can override the inherited attribute title by defining its own title with a different type for example.
382 383 384 385 386 387 388 |
# File 'lib/scrivito/attribute_content.rb', line 382 def attribute(name, type, = {}) name, type, = name, type, assert_valid_attribute_name(name.to_s) assert_valid_attribute_type(type.to_s) own_attribute_definitions[name.to_s] = AttributeDefinition.new(name, type, ) nil end |
#attribute_definitions ⇒ Scrivito::AttributeDefinitionCollection
Returns the attribute definitions.
407 408 409 |
# File 'lib/scrivito/attribute_content.rb', line 407 def attribute_definitions AttributeDefinitionCollection.new(all_attribute_definitions) end |
#description_for_editor ⇒ Object
This method determines the description that is shown in the UI and defaults to class name. It can be overriden by a custom value.
396 397 398 |
# File 'lib/scrivito/attribute_content.rb', line 396 def description_for_editor name end |
#hide_from_editor ⇒ Object
This method disables the creation of Objs or Widgets of the given type using the UI. It does not prevent adding these objects programatically.
By default hide_from_editor is false.
427 428 429 |
# File 'lib/scrivito/attribute_content.rb', line 427 def hide_from_editor @hide_from_editor = true end |