{"id":12048,"date":"2021-09-03T00:47:41","date_gmt":"2021-09-03T06:17:41","guid":{"rendered":"https:\/\/www.emizentech.com\/blog\/?p=12048"},"modified":"2023-01-30T11:03:05","modified_gmt":"2023-01-30T11:03:05","slug":"add-custom-media-in-admin-config-settings-in-shopware-6","status":"publish","type":"post","link":"https:\/\/multisitelocal.ezxdemo.com\/blog\/add-custom-media-in-admin-config-settings-in-shopware-6.html","title":{"rendered":"How To Add Custom Media In Admin Config Settings In Shopware 6"},"content":{"rendered":"<section class=\"blog-section\">\n<div class=\"container\">\n<div class=\"row\">\n<div class=\"col-lg-12\">\n<div class=\"blog-text casestudy-content text-justify\">\n<p>\tWhen working with the Shopware 6 admin interface, you can upload the file in the Shopware 6 system configuration. The admin interface in Shopware 6 accepts all types of input types such as text files, radio buttons, drop-downs, and multiple selects that are plain, encrypted, or serialized and then displayed in various ways such as grids, forms, simple fields, and images.<\/p>\n<p>\tShopware, in particular, allows you to extend the default interface, allowing you to freely add fields. In this guide, we will learn How to Add Custom Media in Shopware 6 Admin Config Settings.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Add_the_code_to_this_location\"><\/span>1. Add the code to this location<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\tcustom\/plugins\/PluginName\/src\/Resources\/app\/administration\/src\/module\/sw-cms\/elements\/elementFolderName\/index.js<\/p>\n<p>\tcode example : To add custom Media<br>\n\t<code><br>\n\tdefaultConfig: {<br>\n\tcustomImageMedia:{<br>\n\tsource: 'static',<br>\n\tvalue: '',<br>\n\tentity: {<br>\n\tname: 'customImageMedia'<br>\n\t}<br>\n\t}<br>\n\t}<br>\n\t<\/code><\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_After_that_you_need_to_add_block_in_the_config_template\"><\/span>2. After that you need to add block in the config template<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\tadd the given code on the given location :<\/p>\n<p>\tcustom\/plugins\/PluginName\/src\/Resources\/app\/administration\/src\/module\/sw-cms\/elements\/elementFolderName\/config\/FileTemplateName.html.twig<br>\n\t<code><br>\n\t{% block sw_cms_element_image_config_customImageMedia_upload %}<br>\n\t&lt;sw-cms-mapping-field label=\"Image\" valueTypes=\"entity\" entity=\"customImageMedia\" v-model=\"element.config.customImageMedia\"&gt;<br>\n\t&lt;sw-media-upload-v2 variant=\"regular\"<br>\n\t:uploadTag=\"uploadCustomImageMediaTag\"<br>\n\t:source=\"previewCustomImageMediaSource\"<br>\n\t:allowMultiSelect=\"false\"<br>\n\t:defaultFolder=\"cmsPageState.pageEntityName\"<br>\n\t:caption=\"$tc('sw-cms.elements.general.config.caption.mediaUpload')\"<br>\n\t@media-upload-sidebar-open=\"onOpenCustomImageMediaModal\"<br>\n\t@media-upload-remove-image=\"onCustomImageMediaRemove\"&gt;<br>\n\t&lt;\/sw-media-upload-v2&gt;<br>\n\t&lt;\/sw-cms-mapping-field&gt;<br>\n\t&lt;sw-upload-listener<br>\n\t:uploadTag=\"uploadCustomImageMediaTag\"<br>\n\tautoUpload<br>\n\t@media-upload-finish=\"onCustomImageMediaUpload\"&gt;<br>\n\t&lt;\/sw-upload-listener&gt;<br>\n\t{% endblock %}<br>\n\t{% block sw_cms_element_image_config_customImageMedia_modal %}<br>\n\t&lt;sw-media-modal-v2<br>\n\tvariant=\"regular\"<br>\n\tv-if=\"customImageMediaModalIsOpen\"<br>\n\t:caption=\"$tc('sw-cms.elements.general.config.caption.mediaUpload')\"<br>\n\t:entityContext=\"cmsPageState.entityName\"<br>\n\t:allowMultiSelect=\"false\"<br>\n\t:initialFolderId=\"cmsPageState.defaultMediaFolderId\"<br>\n\t@media-upload-remove-image=\"onCustomImageMediaRemove\"<br>\n\t@media-modal-selection-change=\"onCustomImageMediaSelectionChanges\"<br>\n\t@modal-close=\"onCustomImageMediaCloseModal\"&gt;<br>\n\t&lt;\/sw-media-modal-v2&gt;<br>\n\t{% endblock %}<br>\n\t<\/code><\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_After_that_you_need_to_add_the_given_code_on_the_given_location\"><\/span>3. After that you need to add the given code on the given location:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\t<img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-12051\" src=\"\/blog\/wp-content\/uploads\/sites\/2\/2021\/09\/image_2021_09_03T06_39_19_161Z.png\" alt=\"Custom media add in shopware 6\" width=\"1153\" height=\"374\"><br>\n\tcustom\/plugins\/PluginName\/src\/Resources\/app\/administration\/src\/module\/sw-cms\/elements\/elementFolderName\/config\/index.js<\/p>\n<p>\t<code><br>\n\tdata() {<br>\n\treturn {<br>\n\tinitialFolderId: null,<br>\n\tcustomImageMediaModalIsOpen: false<br>\n\t};<br>\n\t},<\/code><\/p>\n<p>\tcomputed: {<br>\n\tuploadCustomImageMediaTag() {<br>\n\treturn `cms-element-advancedslider-customImageMedia-config-${this.element.id}`;<br>\n\t},<br>\n\tpreviewCustomImageMediaSource() {<br>\n\tif (this.element.data &amp;&amp; this.element.data.customImageMedia &amp;&amp; this.element.data.customImageMedia.id) {<br>\n\treturn this.element.data.customImageMedia;<br>\n\t}<br>\n\treturn this.element.config.customImageMedia.value;<br>\n\t},<br>\n\tcustomImageMediaRepository() {<br>\n\treturn this.repositoryFactory.create(&#8216;media&#8217;);<br>\n\t}<br>\n\t}<\/p>\n<p>\tmethods: {<br>\n\tasync createdComponent() {<br>\n\tthis.initElementConfig(&#8216;media&#8217;);<br>\n\t},<br>\n\tonOpenCustomImageMediaModal() {<br>\n\tthis.customImageMediaModalIsOpen = true;<br>\n\t},<br>\n\tonCustomImageMediaRemove() {<br>\n\tthis.element.config.customImageMedia.value = null;<br>\n\tthis.updateCustomImageMediaElementData();<br>\n\tthis.$emit(&#8216;element-update&#8217;, this.element);<br>\n\t},<br>\n\tasync onCustomImageMediaUpload({ targetId }) {<br>\n\tconst mediaEntity = await this.customImageMediaRepository.get(targetId);<\/p>\n<p>\tthis.element.config.customImageMedia.value = mediaEntity.id;<\/p>\n<p>\tthis.updateCustomImageMediaElementData(mediaEntity);<\/p>\n<p>\tthis.$emit(&#8216;element-update&#8217;, this.element);<br>\n\t},<br>\n\tupdateCustomImageMediaElementData(customImageMedia = null) {<br>\n\tconst customImageMediaId = customImageMedia === null ? null : customImageMedia.id;<br>\n\tif (!this.element.data) {<br>\n\tthis.$set(this.element, &#8216;data&#8217;, { customImageMediaId });<br>\n\tthis.$set(this.element, &#8216;data&#8217;, { customImageMedia });<br>\n\t} else {<br>\n\tthis.$set(this.element.data, &#8216;customImageMediaId&#8217;, customImageMediaId);<br>\n\tthis.$set(this.element.data, &#8216;customImageMedia&#8217;, customImageMedia);<br>\n\t}<br>\n\t},<br>\n\tonCustomImageMediaCloseModal() {<br>\n\tthis.customImageMediaModalIsOpen = false;<br>\n\t},<\/p>\n<p>\tonCustomImageMediaSelectionChanges(mediaEntity) {<br>\n\tconst customImageMedia = mediaEntity[0];<br>\n\tthis.element.config.customImageMedia.value = customImageMedia.id;<br>\n\tthis.updateCustomImageMediaElementData(customImageMedia);<br>\n\tthis.$emit(&#8216;element-update&#8217;, this.element);<br>\n\t},<br>\n\t}<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Afterwards_you_will_get_the_output_like_the_given_image_in_the_element_config_setting\"><\/span>4. Afterwards you will get the output like the given image in the element config setting.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\t<img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-12051\" src=\"\/blog\/wp-content\/uploads\/sites\/2\/2021\/09\/image_2021_09_03T06_39_19_161Z.png\" alt=\"Custom media add in shopware 6\" width=\"1153\" height=\"374\"><\/p>\n<p>\t&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"5_You_can_upload_media_by_clicking_on_upload_file_select_image_then_save_after_that_you_will_find_the_config_setting_image_like_the_given_screenshot\"><\/span>5. You can upload media by clicking on upload file select image then save, after that, you will find the config setting image like the given screenshot.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\t<img decoding=\"async\" class=\"aligncenter size-full wp-image-12053\" src=\"\/blog\/wp-content\/uploads\/sites\/2\/2021\/09\/image_2021_09_03T06_41_23_829Z.png\" alt=\"Custom media add in shopware 6\" width=\"1149\" height=\"346\"><\/p><\/div>\n<p><\/p><\/div>\n<p><\/p><\/div>\n<p><\/p><\/div>\n<\/section>\n\n","protected":false},"excerpt":{"rendered":"<p>When working with the Shopware 6 admin interface, you can upload the file in the Shopware 6 system configuration. The admin interface in Shopware 6 accepts all types of input types such as text files, radio buttons, drop-downs, and multiple selects that are plain, encrypted, or serialized and then displayed in various ways such as<\/p>\n","protected":false},"author":36,"featured_media":12049,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"MSN_Categories":"Uncategorized","MSN_Publish_Option":false,"MSN_Is_Local_News":false,"MSN_Is_AIAC_Included":"Empty","MSN_Location":"[]","MSN_Add_Feature_Img_On_Top_Of_Post":false,"MSN_Has_Custom_Author":false,"MSN_Custom_Author":"","MSN_Has_Custom_Canonical_Url":false,"MSN_Custom_Canonical_Url":"","_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[85],"tags":[84],"class_list":{"0":"post-12048","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-shopware","8":"tag-shopware"},"modified_by":"Marketing EmizenTech","featured_image_src":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-content\/uploads\/sites\/2\/2021\/09\/How-To-Add-Custom-Media-In-Admin-Config-Settings-In-Shopware-6-1.jpg","featured_image_src_square":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-content\/uploads\/sites\/2\/2021\/09\/How-To-Add-Custom-Media-In-Admin-Config-Settings-In-Shopware-6-1.jpg","author_info":{"display_name":"Vivek Khatri","author_link":"https:\/\/multisitelocal.ezxdemo.com\/blog\/author\/vivek"},"_links":{"self":[{"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/posts\/12048","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/comments?post=12048"}],"version-history":[{"count":0,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/posts\/12048\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/media\/12049"}],"wp:attachment":[{"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/media?parent=12048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/categories?post=12048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/tags?post=12048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}