Attribute properties
When you need to create a magento attribute programmatically as shown in the previous post you'll be forced to provide a list of attribute properties to declare your attribute.
All the properties are located in a few php classes, so-called "Property Mappers" which implement the following interface
\Magento\Eav\Model\Entity\Setup\PropertyMapperInterface
EAV ATTRIBUTE PROPERTIES
\Magento\Eav\Model\Entity\Setup\PropertyMapperThe first mapper contains properties required for any entity type. As said in the class description it maps input attribute properties to storage representation. Here's the full list of the properties:
backend
here you can specify a class where the provided value can be modified. It's useful for validation if some custom validation is required.
type
is used for specifying a type of value. By default set at varchar
table
is used if you need a different database table to store the value. If not set the value will be stored in the default table
frontend
can be used for preparing a value before rendering on the frontend
input
is used to define how the field will be rendered on the backend. By default it's input
label
text displayed beside value on the frontend
frontend_class
is used for defining a css class for the input on the frontend
source
a php class that provides labels and values for an option list. Used for select and multi-select fields
required
Defines is an attribute must set as required. By default set at true
user_defined
There are two possible values: 1 is for user defined and 0 for system attribute
user_defined
There are two possible values: 1 is for user defined and 0 for system attribute. It's better to set it always as a custom attribute.
default
A default value for an attribute. Worth to mention that this value won't be applied for already created entities.
unique
Defines is a value of an attribute must be unique.
note
Text that will be displayed below the input on the backend
global
Here you can specify a scope
CATALOG EAV ATTRIBUTE PROPERTIES
\Magento\Catalog\Model\ResourceModel\Setup\PropertyMapperThis set of properties is used for catalog attributes. Here's the list:
input_renderer
Here you can specify a custom renderer for an input
visible
Defines visibility in the admin interface. Won't be available for changing a value in the admin interface if set to 0
searchable
Defines is an attribute will be searchable on the frontend
filterable
Defines whether an attribute will be used on layered navigation. Works for integer type only
comparable
Here you can define if an attribute will be used for compare
visible_on_front
If it set to 1 it will be shown in the additional information block on the product page
wysiwyg_enabled
is used for enabling wysiwyg editor for an attribute. Works for textarea only
is_html_allowed_on_front
Here you can specify if html must be escaped on the frontend
visible_in_advanced_search
Defines if it will be used in the advanced search form
filterable_in_search
Defines if it will be possible to filter the result by this attribute. Works for integer type only
used_in_product_listing
Set it to 1 if you're going to use an attribute on the category pages
used_for_sort_by
Set it to 1 if you want to use an attribute for sorting on the product pages
apply_to
This property defines if an attribute must be applied for particular types of product.
position
Defines a position in the layered navigation
used_for_promo_rules
Defines if an attribute can be used for promo rules
A following group of properties defines attribute behavior on the backend grid
is_used_in_grid
Set it to 1 if you need an attribute to be used on the backend grid
is_visible_in_grid
Set it to 1 if you need an attribute to be visible on the backend grid
CUSTOMER EAV ATTRIBUTE PROPERTIES
\Magento\Customer\Model\ResourceModel\Setup\PropertyMapperThe following list of properties to walk through is used for customer attributes:
visible
Defines if an attribute is visible in the admin form
system
Defines if an attribute's type. There are two types: system and custom. It's better to set all your customer attributes to custom.
input_filter
is used when a form is sent and the data is being extracted from the fields.
multiline_count
Is used for street addresses, where a value can be multiple lines.
validate_rules and data
apply before saving values and depend on a type and rules what can be applied
position
defines a position of an attribute in a form
is_used_in_grid
Set it to 1 if you need an attribute to be visible on the backend grid
is_filterable_in_grid
Set it to 1 if you need an attribute to be filterable on the backend grid
is_searchable_in_grid
Set it to 1 if you need an attribute to be searchable on the backend grid