-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Add Value to Magento Framework's public API #17296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Value to Magento Framework's public API #17296
Conversation
These classes are necessary/useful for creating a backend source for a Magento Configuration field. As such they should be reliable and part of the public API.
Hi @navarr. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
@@ -17,6 +17,8 @@ | |||
* @method string getValue() | |||
* @method \Magento\Framework\App\Config\ValueInterface setValue(string $value) | |||
* | |||
* @api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a good idea to make fat ugly model a part of API. Why isn't interface sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When writing a backend model for a config, Magento expects that the model implements methods that do not exist in the Interface (such as "addData"). Though, this can be solved by any implementation of ValueInterface extending from AbstractModel (as Value does).
However, this model contains all the default functionality expected from a configuration backend model - including setting the correct events to fire and invalidating the cache. I have hard trouble finding a backend model that does not extend from Value.
Tutorials and examples online also show that the typical config backend model utilizes this model. I would think for those reasons it should be part of the public @api so that custom module's backend models may depend on it not removing functionality without a major version break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do not use the Value model, you must also specify the resource and resourcecollection for configuration yourself. Magento does it for Value as such:
<type name="Magento\Framework\App\Config\Value">
<arguments>
<argument name="resource" xsi:type="object">Magento\Config\Model\ResourceModel\Config\Data</argument>
<argument name="resourceCollection" xsi:type="object">Magento\Config\Model\ResourceModel\Config\Data\Collection\Proxy</argument>
</arguments>
</type>
It appears that in all cases the expectation is that you extend from this model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@navarr do we have any other model extending AbstractModel
marked as @api
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orlangur Yes. For example \Magento\Customer\Model\Customer
and Magento\Eav\Model\Entity\Type
. Nothing in Magento\Framework
, however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we have the interface for this model marked with @api
. There's no sense to mark the model itself as @api
as well since we won't be needed the interface. That's why it is important to extend the interface while we can deliver that to 2.3.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@slavvka I've had little personal time to work on open source - so forgive me for the delay - though I had last spoken about this over two months ago.
I laid out a variety of good reasons that this model should be part of the API on August 1st, and that simply updating the interface is not good enough. My fallback position on this is that "developers currently rely on this model to perform the basic tasks associated with a backend value"
And similarly Magento expects that it is receiving a Value model for a vast majority of the information it conveys to such objects:
// Magento\Config\Model\PreparedValueFactory
/** @var ValueInterface $backendModel */
$backendModel = $this->valueFactory->create(
$backendModelName,
['config' => $this->config]
);
if ($backendModel instanceof Value) {
$scopeId = 0;
$scope = $this->scopeTypeNormalizer->normalize($scope);
if ($scope !== ScopeInterface::SCOPE_DEFAULT) {
$scopeId = $this->scopeResolverPool->get($scope)
->getScope($scopeCode)
->getId();
}
if ($field instanceof Structure\Element\Field) {
$groupPath = $field->getGroupPath();
$group = $structure->getElement($groupPath);
$backendModel->setField($field->getId());
$backendModel->setGroupId($group->getId());
$backendModel->setFieldConfig($field->getData());
}
$backendModel->setPath($configPath);
$backendModel->setScope($scope);
$backendModel->setScopeId($scopeId);
$backendModel->setScopeCode($scopeCode);
$backendModel->setValue($value);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since current interface is not enough and we are in code-freeze stage now, I propose the following:
In 2.3.0
- Mark the model as
@api
- Do NOT mark the interface as
@api
In 2.4.0
- Create a task to investigate how the interface should look like to cover the needs
- Extend existing interface or create a new one based on the investigation. Mark it as
@api
- Deprecate the model
in 2.5.0
- Remove
@api
from the model and leave only one interface marked as@api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the decision is made. We are following to what @paliarush described. Please remove @api
mark from the interface and add there a description what is going to be done with it. Also please add a description to the model that what it will be marked as @api
temporarily until we introduce a new interface and make everybody use use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@navarr thank you for your valuable contribution! Your changes was cherry-picked and delivered to 2.3.0 release branch. This PR is also accepted and will be delivered to 2.3.1 release
Hi @slavvka, thank you for the review. |
Hi @navarr. Thank you for your contribution. |
Description
These classes are necessary/useful for creating a backend source for a
Magento Configuration field. As such they should be reliable and part
of the public API.
Contribution checklist