-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Introduced MediaContent and MediaContentApi modules #27536
Introduced MediaContent and MediaContentApi modules #27536
Conversation
Hi @sivaschenko. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
{ | ||
/** @var CatalogProduct $model */ | ||
$model = $observer->getEvent()->getData('product'); | ||
if ($model instanceof AbstractModel) { |
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 ($model instanceof AbstractModel) { | |
if ($model instanceof \Magento\Catalog\Model\Product) { |
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.
@sivaschenko will this work if this preference will be changed <preference for="Magento\Catalog\Api\Data\ProductInterface" type="Magento\Catalog\Model\Product" />
and Magento\Catalog\Api\Data\ProductInterface
will have another implementation?
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.
No
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 not can we leave AbstractModel instance identification? I can hardly imagine the case when the Magento\Catalog\Api\Data\ProductInterface
can have another implementation but if this possible from the di perspective it can break the process. Or I missed something?
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.
@naydav can you please address this question?
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.
Do we expect to expose any of those newly created APIs via WEB API ?
* @param string $content | ||
* @return AssetInterface[] | ||
*/ | ||
public function execute(string $content): array; |
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.
what's $content in this case?
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.
A "content" in the scope of the MediaContent domain is an alias to any kind of an object property which possibly contains a media asset. For example, a product object has a description which probably includes a media asset. A category object description and image also can have a media asset as a part of storage data.
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.
How somebody (a developer) knows what to put in this property? Where to find list of supported aliases?
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.
Data, selected for this property, is a developer choice made on next conclusion: if an object has a property which possibly contains a media asset, to get it from this property it needs to be sent to this Interface implementation. For example, currently, we represented a declaration of content properties in di:
https://github.com/magento/magento2/pull/27536/files/b6e79cf870273936cb70ffc05add1fa73a9e3334#diff-bcf67dbc51c19997838fdb60cee182abR9-R16
List of aliases, in that case, is a list of properties declared manually based on data structure and a possibility to have a media asset in properties.
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.
@buskamuza that's a parser that looks for image mentions in any content/text/string. Should we change the naming to make it better understandable or improving comments would be enough?
/** | ||
* @param int $assetId | ||
* | ||
* @return array |
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.
what's the format of return result ? Not looking at implementation it's not clear
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.
It's ContentIdentityInterface[] (introduced data interface), the code is updated
<preference for="Magento\MediaContentApi\Api\UnassignAssetInterface" type="Magento\MediaContent\Model\UnassignAsset"/> | ||
<preference for="Magento\MediaContentApi\Api\GetAssetsUsedInContentInterface" type="Magento\MediaContent\Model\GetAssetsUsedInContent"/> | ||
<preference for="Magento\MediaContentApi\Api\GetContentWithAssetInterface" type="Magento\MediaContent\Model\GetContentWithAsset"/> | ||
<preference for="Magento\MediaContentApi\Api\ExtractAssetFromContentInterface" type="Magento\MediaContent\Model\ExtractAssetFromContent"/> |
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.
Why interface and implementation located in one module and marked as API? It does not make sense for me. It would be better to leave the interface only.
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.
The interface is used for injecting the service, the model is used for di configuration
That change was requested by @naydav at the online review
app/code/Magento/MediaContent/Model/Content/ConfigInterface.php
Outdated
Show resolved
Hide resolved
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.
Review with Valerii
/** | ||
* @inheritdoc | ||
*/ | ||
public function setExtensionAttributes(ContentIdentityExtensionInterface $extensionAttributes): void |
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.
Delete all setExtensionAttributes
if it works with webapi
app/code/Magento/MediaContent/Model/GetAssetIdsUsedInContent.php
Outdated
Show resolved
Hide resolved
app/code/Magento/MediaContent/Model/RemoveRelationsForAssetIds.php
Outdated
Show resolved
Hide resolved
* @param string $path | ||
* @return int[] | ||
*/ | ||
private function getAssetIdsByDirectoryPath(string $path): array |
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.
Update after MediaGallery PR is merged
\Closure $proceed, | ||
string $mediaAssetPath | ||
) : void { | ||
$asset = $this->getByPath->execute($mediaAssetPath); |
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.
update after merge of MediaGallery PR
* | ||
* @param Observer $observer | ||
*/ | ||
public function execute(Observer $observer): void |
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.
Observers appear to be deprecated (but not documented)
Performance build: https://bamboo.corp.magento.com/browse/MCCE24-MCCE24405-1 |
@magento run tests |
@magento run all tests |
@magento run all tests |
@magento run all tests |
The pull request was tested with Used In functionality on Adobe Stock Integration |
Hi @sivaschenko, thank you for your contribution! |
Depends on:
Description (*)
The Magento_MediaContent module provides implementations for managing relations between content and media files used in that content.
Additionally observers have been added to Cms and Catalog modules to save the relation of corresponding entities to MediaContent storage
Story
magento/adobe-stock-integration#717: User sees pages the image is used in Magento
Related Pull Requests
magento/adobe-stock-integration#1235
Contribution checklist (*)