-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Introduced MediaContent and MediaContentApi modules #27536
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
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
Looks like domain model has such entity as "content". There are several places with Also, I'd suggest to define more clearly purpose of the MediaContent domain and make sure public APIs don't include interfaces/classes which are just details of implementation. Public API should be useful for developers from unrelated domains. For example, if somebody would like to use MediaContent for order details or for emails, which methods would be needed? Things like "relations" sound too technical (low level) and don't help understand domain model. |
* | ||
* @throws \Magento\Framework\Exception\CouldNotSaveException | ||
*/ | ||
public function execute(int $assetId, string $contentType, string $contentEntityId, string $contentField): 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.
$contentEntityId
- what is "content entity"? In the implementation I see no relation of the ID to anything https://github.com/sivaschenko/magento2/blob/media-content/app/code/Magento/MediaContent/Model/AssignAsset.php#L51 , so it's not clear what does this ID mean.
Is it "CMS", "Product Page", etc? Why $contentType
is a string? I'd assume there is limited set of content types supported. Looks like implementation doesn't limit any input as well.
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.
content entity id
is an id of an entity which has content where an asset is used. For example, if we store a relation between asset and content of the product entity the catalog_product_entity.entity_id
will be used for this.
In a provided implementation this is used here: https://github.com/magento/magento2/pull/27536/files#diff-425fc7fd56cadd0cbbf4f2b600c74771R107
The implementation doesn't limit supported types of object with content to provide extensibility. From the box, the cms_page
, cms_block
, catalog_product
, catalog_category
provided as a basic content type. If someone will need to store information about media asset usage in the content of a custom object it will create its own content type and this automatically be used for all other features such as showing where and how an asset is used.
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 we've introduced ContentIdentityInterface, please see the updated code
namespace Magento\MediaContentApi\Api; | ||
|
||
/** | ||
* Saving data represents relation between the media asset and media content |
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.
"Assign asset to media content" would sound less technical and would explain the domain better, IMO. Or "Assign content to asset", depending on what is happening.
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.
comment updated
* Used for extracting media asset list from a media content by the search pattern. | ||
* @api | ||
*/ | ||
interface ExtractAssetFromContentInterface |
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.
Should it be plural then? ExtractAssetsFromContentInterface
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.
changed
* @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.
How somebody (a developer) knows what to put in this property? Where to find list of supported aliases?
* @return int[] | ||
* @throws \Magento\Framework\Exception\IntegrationException | ||
*/ | ||
public function execute(string $contentType, string $contentEntityId = null, string $contentField = null): 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.
If there are content aliases (as in the previous interface), why there is also this method? Is it that in some cases alias is not known or doesn't exist? And in some cases an alias is all you know (and don't know about content type and all the input for this method)?
* | ||
* This class should be used for DI configuration only, please use the interface in the code | ||
* | ||
* @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.
Probably marking the interface with @api
should be enough.
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.
this class should be used for DI configuration
app/code/Magento/MediaContent/Model/DeleteContentAssetLinks.php
Outdated
Show resolved
Hide resolved
app/code/Magento/MediaContentApi/Api/Data/ContentAssetLinkInterface.php
Outdated
Show resolved
Hide resolved
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 (*)