5
'system' => 0

What that property of (product - only?) does or means? I've noticed that all built-in Magento attribute has it with value 1. So my custom attributes should have 0? is it only for marking custom and built-in attributes?

4

System attributes are the default attributes shipped natively with the software.

The purpose is to be able to differentiate Magento system attributes and custom attributes.

I reckon it is similar to Magento 1 as system attributes are used directly in the code logic of Magento 2

2

If some attribute is flagged as "is_system" = true

Then such attribute deny to change some specific options on attribute edit page, as shown below

vendor/magento/module-customer-custom-attributes/Block/Adminhtml/Customer/Address/Attribute/Edit/Tab/General.php

if ($attribute->getIsSystem()) {
    $elements = ['sort_order', 'is_visible', 'is_required', 'used_in_forms'];
}
if (!$attribute->getIsUserDefined() && !$attribute->getIsSystem()) {
    $elements = ['sort_order', 'used_in_forms'];
}
foreach ($elements as $elementId) {
    $form->getElement($elementId)->setDisabled(true);
}

Other place where this attribute is used is EAV Attribute Metadata. But there is one difference in method name: isSystem instead of getIsSystem:

vendor/magento/module-customer/Model/Metadata/AddressMetadata.php

public function getCustomAttributesMetadata($dataObjectClassName = AddressMetadataInterface::DATA_INTERFACE_NAME)
{
    //...
    $customAttributes = [];
    foreach ($this->getAllAttributesMetadata() as $attributeMetadata) {
        // ...
        if (!$isDataObjectMethod && !$attributeMetadata->isSystem()) {
            $customAttributes[] = $attributeMetadata;
        }
    }
    return $customAttributes;
}

Same for Customer you may find here:

\Magento\Customer\Model\Metadata\CustomerMetadata::getCustomAttributesMetadata

These methods are deciding to add or not to add your created attributes to custom_attributes array. It means that these attributes will not be accessible for CRUD operations in Repositories.

And here, as for me, logical bug in magento.

Custom attributes metadata isn't responsible for rendering forms in magento admin.

It means that if attribute has following configuration

is_system = 0
is_required = 1
used_in_forms = [] or with default value ['adminhtml_customer_address']
Attempt to save empty value

Following attribute will not appear on adminhtml customer address edit page, but the model will claiming on saving empty value, when this field does not shown due insufficient value in "used_in_forms" option.

At the same time when you have following configuration:

is_system = 1
is_required = 1
used_in_forms = ['adminhtml_customer_address', 'customer_address_edit']
Attempt to save "blabla"

This attribute does not present inside metadata and will not be saved. Page will be reloaded and no value being saved.

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.