1

I am trying to override admin file,

module-product-video\view\adminhtml\templates\helper\gallery.phtml

I am not able to find layout file for this because it set inside the block called,

magento\module-catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content.php

Can anyone guide me?

Updated code:

etc/di.xml

<preference for="Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content" type="Bhupendra\Helloworld\Block\Adminhtml\Product\Gallery\Content" />

BLOCK:

<?php

namespace Bhupendra\Helloworld\Block\Adminhtml\Product\Gallery;

use Magento\Backend\Block\Media\Uploader;
use Magento\Framework\View\Element\AbstractBlock;

class Content extends \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content
{
    /**
     * @var string
     */
    protected $_template = 'Bhupendra_Helloworld::product/gallery.phtml';
}

Template:

module-product-video\view\adminhtml\templates\helper\gallery.phtml

to

view\adminhtml\templates\product\gallery.phtml
4
  • view\product\gallery.phtml => view\adminhtml\templates\product\gallery.phtml. We also need to have a prefix module in the variable template: protected $_template = 'Bhupendra_Helloworld::product/gallery.phtml'; Sep 8 '16 at 10:37
  • Yes! i have already done these both but still it is not working my path is \view\adminhtml\templates\product Sep 8 '16 at 10:40
  • You have a prefix protected $_template = 'Bhupendra_Helloworld::product/gallery.phtml'; ? Please, update your question properly. Sep 8 '16 at 10:42
  • Now! i think this block is not override the this template because even i am changing from that particular core block it is not changing the template. Sep 8 '16 at 10:47
4

If we take a look: vendor/magento/module-product-video/Observer/ChangeTemplateObserver.php. We can see that this template will be added via Observer event. So, we need to disable this observer event in our module. And then, try to add our custom template.

Vendor/Module/etc/events.xml

<event name="catalog_product_gallery_prepare_layout">
        <observer name="change_template" disabled="true"/>
        <observer name="custom_change_template" instance="Vendor\Module\Observer\ChangeTemplateObserver" />
</event> 

Vendor/Module/Observer/ChangeTemplateObserver.php

<?php

namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;

class ChangeTemplateObserver implements ObserverInterface
{

   public function execute(\Magento\Framework\Event\Observer $observer)
   {
     $observer->getBlock()->setTemplate('Vendor_Module::helper/gallery.phtml');
   }
}
10
  • how can we add js file on that page in header Sep 8 '16 at 8:54
  • Seem that you're asking a new issue, please open new question. Sep 8 '16 at 8:56
  • Gallery.phtml is not calling from my module Sep 8 '16 at 9:26
  • Uppercase or lowercase your template name? Gallery.phtml or gallery.phtml? It should be lowercase. Sep 8 '16 at 9:29
  • yes i am using lowercase template name but still is not working i had flushed the cache . Sep 8 '16 at 9:53
0

You have to create a module.

app/code/Test/Video/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Test_Video" setup_version="2.0.0" schema_version="2.0.0"/>
    <sequence>
        <module name="Magento_Customer"/>
        <module name="Magento_Store"/>
        <module name="Magento_Ui"/>
    </sequence>
</config>

app/code/Test/Video/registration.php

<?php
    \Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Test_Video',
    __DIR__
);

app/code/Test/Video/etc/adminhtml/events.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="catalog_product_gallery_prepare_layout">
        <observer name="change_template" disabled="true"/>
        <observer name="custom_change_template" instance="Test\Video\Observer\OptionObserver" />
    </event> 
</config>

app/code/Test/Video/Observer/ChangeTemplateObserver.php

 <?php

namespace Test\Video\Observer;

use Magento\Framework\Event\ObserverInterface;

class OptionObserver implements ObserverInterface
{

   public function execute(\Magento\Framework\Event\Observer $observer)
   {
     $observer->getBlock()->setTemplate('Test_Video::helper/gallery.phtml');
   }
}

app/code/Test/Video/view/adminhtml/templates/helper/gallery.phtml

 <?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var $block \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content */
$elementName = $block->getElement()->getName() . '[images]';
$formName = $block->getFormName();
?>

<div class="row">
    <div class="add-video-button-container">
        <button id="add_video_button"
                title="<?php echo $block->escapeHtml(__('Add Video'));?>"
                data-role="add-video-button"
                type="button"
                class="action-secondary"
                data-ui-id="widget-button-1">
            <span><?php echo $block->escapeHtml(__('Add Video')) ?></span>
        </button>
    </div>
    **<div class="uplload" style="color:#000; font-weight:bold";>Please Upload a Image 1000px * 1000px </div>** - **If you wanna add a text , you can do like this** 
</div>

<?php
/** @var $block \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content */
$element = $block->getElement();
$elementToggleCode = $element->getToggleCode() ? $element->getToggleCode() : 'toggleValueElements(this, this.parentNode.parentNode.parentNode)';
?>

<div id="<?php echo $block->getHtmlId() ?>"
     class="gallery"
     data-mage-init='{"openVideoModal":{}}'
     data-parent-component="<?php echo $block->escapeHtml($block->getData('config/parentComponent')) ?>"
     data-images="<?php echo $block->escapeHtml($block->getImagesJson()) ?>"
     data-types="<?php echo $block->escapeHtml(
         $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getImageTypes())
     ) ?>"
>

    <?php
    if (!$block->getElement()->getReadonly()):
        ?>
        <div class="image image-placeholder">
            <?php /* @escapeNotVerified */ echo $block->getUploaderHtml();
            ?>
            <div class="product-image-wrapper">
                <p class="image-placeholder-text">
                    <?php echo $block->escapeHtml(
                        __('Browse to find or drag image here')
                    ); ?>
                </p>
            </div>
        </div>
        <?php /* @escapeNotVerified */ echo $block->getChildHtml('additional_buttons'); ?>
        <?php
    endif;
    ?>
    <?php
    foreach ($block->getImageTypes() as $typeData):
        ?>
        <input name="<?php echo $block->escapeHtml($typeData['name']) ?>"
               data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"
               class="image-<?php echo $block->escapeHtml($typeData['code']) ?>"
               type="hidden"
               value="<?php echo $block->escapeHtml($typeData['value']) ?>"/>
        <?php
    endforeach;
    ?>
    <script id="<?php /* @escapeNotVerified */ echo $block->getHtmlId() ?>-template" data-template="image" type="text/x-magento-template">
        <div class="image item <% if (data.disabled == 1) { %>hidden-for-front<% } %>  <% if (data.video_url) { %>video-item<% } %>"
             data-role="image">
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][position]"
                   value="<%- data.position %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"
                   class="position"/>
            <% if (data.media_type !== 'external-video') {%>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][media_type]"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"
                   value="image"/>
            <% } else { %>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][media_type]"
                   value="<%- data.media_type %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <% } %>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][video_provider]"
                   value="<%- data.video_provider %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][file]"
                   value="<%- data.file %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][value_id]"
                   value="<%- data.value_id %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][label]"
                   value="<%- data.label %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][disabled]"
                   value="<%- data.disabled %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][removed]"
                   value="" class="is-removed"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][video_url]"
                   value="<%- data.video_url %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][video_title]"
                   value="<%- data.video_title %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][video_description]"
                   value="<%- data.video_description %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][video_metadata]"
                   value="<%- data.video_metadata %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>
            <input type="hidden"
                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][role]"
                   value="<%- data.video_description %>"
                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"/>

            <div class="product-image-wrapper">
                <img class="product-image"
                     data-role="image-element"
                     src="<%- data.url %>"
                     alt="<%- data.label %>"/>

                <div class="actions">
                    <button type="button"
                            class="action-remove"
                            data-role="delete-button"
                            title="<% if (data.media_type == 'external-video') {%>
                            <?php echo $block->escapeHtml(
                                __('Delete video')
                            ); ?>
                        <%} else {%>
                            <?php echo $block->escapeHtml(
                                __('Delete image')
                            ); ?>
                        <%}%>">
                    <span>
                        <% if (data.media_type == 'external-video') { %>
                        <?php echo $block->escapeHtml(
                            __('Delete video')
                        ); ?>
                        <% } else {%>
                        <?php echo $block->escapeHtml(
                            __('Delete image')
                        ); ?>
                        <%} %>
                    </span>
                    </button>
                    <div class="draggable-handle"></div>
                </div>
                <div class="image-fade"><span><?php echo $block->escapeHtml(
                            __('Hidden')
                        ); ?></span></div>
            </div>

            <div class="item-description">
                <% if (data.media_type !== 'external-video') {%>
                <div class="item-title" data-role="img-title"><%- data.label %></div>
                <div class="item-size">
                    <span data-role="image-dimens"></span>, <span data-role="image-size"><%- data.sizeLabel %></span>
                </div>
                <% } else { %>
                <div class="item-title" data-role="img-title"><%- data.video_title %></div>
                <% } %>
            </div>

            <ul class="item-roles" data-role="roles-labels">
                <?php
                foreach ($block->getImageTypes() as $typeData):
                    ?>
                    <li data-role-code="<?php echo $block->escapeHtml(
                        $typeData['code']
                    ) ?>" class="item-role item-role-<?php echo $block->escapeHtml(
                        $typeData['code']
                    ) ?>">
                        <?php echo $block->escapeHtml($typeData['label']) ?>
                    </li>
                    <?php
                endforeach;
                ?>
            </ul>
        </div>
    </script>

    <script data-role="img-dialog-container-tmpl" type="text/x-magento-template">
        <div class="image-panel" data-role="dialog">
        </div>
    </script>

    <script data-role="img-dialog-tmpl" type="text/x-magento-template">
        <div class="image-panel-preview">
            <img src="<%- data.url %>" alt="<%- data.label %>" />
        </div>
        <div class="image-panel-controls">
            <strong class="image-name"><%- data.label %></strong>

            <fieldset class="admin__fieldset fieldset-image-panel">
                <div class="admin__field field-image-description">
                    <label class="admin__field-label" for="image-description">
                        <span><?php /* @escapeNotVerified */ echo __('Alt Text')?></span>
                    </label>

                    <div class="admin__field-control">
                            <textarea data-role="image-description"
                                      rows="3"
                                      class="admin__control-textarea"
                                      name="<?php /* @escapeNotVerified */
                                      echo $elementName
                                      ?>[<%- data.file_id %>][label]"><%- data.label %></textarea>
                    </div>
                </div>

                <div class="admin__field field-image-role">
                    <label class="admin__field-label">
                            <span><?php echo $block->escapeHtml(
                                    __('Role')
                                ); ?></span>
                    </label>
                    <div class="admin__field-control">
                        <ul class="multiselect-alt">
                            <?php
                            foreach ($block->getMediaAttributes() as $attribute) :
                                ?>
                                <li class="item">
                                    <label>
                                        <input class="image-type"
                                               data-role="type-selector"
                                               data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"
                                               type="checkbox"
                                               value="<?php echo $block->escapeHtml(
                                                   $attribute->getAttributeCode()
                                               ) ?>"
                                        />
                                        <?php /* @escapeNotVerified */ echo $block->escapeHtml(
                                            $attribute->getFrontendLabel()
                                        ) ?>
                                    </label>
                                </li>
                                <?php
                            endforeach;
                            ?>
                        </ul>
                    </div>
                </div>

                <div class="admin__field admin__field-inline field-image-size" data-role="size">
                    <label class="admin__field-label">
                        <span><?php /* @escapeNotVerified */ echo __('Image Size') ?></span>
                    </label>
                    <div class="admin__field-value" data-message="<?php /* @escapeNotVerified */ echo __('{size}') ?>"></div>
                </div>

                <div class="admin__field admin__field-inline field-image-resolution" data-role="resolution">
                    <label class="admin__field-label">
                        <span><?php /* @escapeNotVerified */ echo __('Image Resolution') ?></span>
                    </label>
                    <div class="admin__field-value" data-message="<?php /* @escapeNotVerified */ echo __('{width}^{height} px') ?>"></div>
                </div>

                <div class="admin__field field-image-hide">
                    <div class="admin__field-control">
                        <div class="admin__field admin__field-option">
                            <input type="checkbox"
                                   id="hide-from-product-page"
                                   data-role="visibility-trigger"
                                   data-form-part="<?php /* @escapeNotVerified */ echo $formName ?>"
                                   value="1"
                                   class="admin__control-checkbox"
                                   name="<?php /* @escapeNotVerified */ echo $elementName ?>[<%- data.file_id %>][disabled]"
                            <% if (data.disabled == 1) { %>checked="checked"<% } %> />

                            <label for="hide-from-product-page" class="admin__field-label">
                                <?php echo $block->escapeHtml(
                                    __('Hide from Product Page')
                                ); ?>
                            </label>
                        </div>
                    </div>
                </div>
            </fieldset>
        </div>
    </script>
    <div id="<?php /* @noEscape */ echo $block->getNewVideoBlockName();?>" style="display:none">
        <?php /* @escapeNotVerified */ echo $block->getFormHtml();?>
        <div id="video-player-preview-location" class="video-player-sidebar">
            <div class="video-player-container"></div>
            <div class="video-information title">
                <label><?php echo $block->escapeHtml(
                        __('Title:')
                    ); ?> </label><span></span>
            </div>
            <div class="video-information uploaded">
                <label><?php echo $block->escapeHtml(
                        __('Uploaded:')
                    ); ?> </label><span></span>
            </div>
            <div class="video-information uploader">
                <label><?php echo $block->escapeHtml(
                        __('Uploader:')
                    ); ?> </label><span></span>
            </div>
            <div class="video-information duration">
                <label><?php echo $block->escapeHtml(
                        __('Duration:')
                    ); ?> </label><span></span>
            </div>
        </div>
    </div>

    <?php echo $block->getChildHtml('new-video'); ?>
</div>
<script>
    jQuery('body').trigger('contentUpdated');
</script>

Follow this one. you will get.

4
  • Why do you have to create a module? How do you create it? What should be the content? Your answer is very limited...
    – 7ochem
    Jun 7 '18 at 12:18
  • Can you please tell me , without creating a module , how you can override this .
    – Priya
    Jun 8 '18 at 8:10
  • I'm not saying you don't need to create a module. I mean that your answer is not very helpful if you do not explain why, where, what and how
    – 7ochem
    Jun 8 '18 at 8:20
  • Thanks Rama Chandran M - I don't know how to do edit above code. Reallly Thanks.
    – Priya
    Jun 8 '18 at 11:17

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.