Skip to content
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

Feature Request: Widget #7

Open
johnny-longneck opened this issue Aug 8, 2017 · 6 comments
Open

Feature Request: Widget #7

johnny-longneck opened this issue Aug 8, 2017 · 6 comments
Assignees

Comments

@johnny-longneck
Copy link

First of all, thanks for this module.
It was wonderful when turning category images into responsive images with srcset and sizes attributes.

One thing that I would love to see is the feature to use it outside of templates, but as widget in the admin section.

@jalogut
Copy link
Contributor

jalogut commented Aug 10, 2017

Hi @johnny-longneck,

I am glad you are using the module. Regarding your suggestion, could you please elaborate your idea? I do not quite undestand how this would work.

If you create a custom widget, you can also use the 'resizerHelper' inside the template of your widget. Besides that, if you need to use the resizer somewhere else, you could inject the helper in any class comtructor as done here:

Would that work for you?

@johnny-longneck
Copy link
Author

johnny-longneck commented Aug 11, 2017

Thanks for your reply. Sorry for bad description. What I am going to achieve is what I did with template images: Have one image being output in several sizes. Speaking of
<picture>
<source ...></source>
<source ...></source>
<!-- fallback image -->
<img src="image.png" />
</picture>

As far as I know, I cannot use your plugin on CMS Static Blocks for example.
Writing an own widget which implements your solution is an idea.

I can try that.

@jalogut
Copy link
Contributor

jalogut commented Oct 9, 2017

Hi @johnny-longneck
It has been a long time. Sure that a widget would be a good solution to implement that. Did you progress on that?

@johnny-longneck
Copy link
Author

Unfortunatly no. I was super busy fixing bug after bug after bug for severeal M2 shops. But jeah I should give it a try.

@jalogut
Copy link
Contributor

jalogut commented Oct 10, 2017

Hi @johnny-longneck

I was yesterday thinking about that and I think this feature should not belong to that module but to be implemented on a project level. In my opinion, a widget is project specific and it makes more sense to create that widget directly on the project. In fact that would be quite easy to accomplish using 2 modules:

In your project your will need the following:

composer.json

composer require "staempfli/magento2-module-image-resizer":"~1.0"
composer require "staempfli/magento2-module-widget-extra-fields":"~1.0"

Vendor/Package/etc/widget.xml

<widget id="<widget_id>" class="Vendor\Module\Block\Widget\<Your_Widget>" >
    <label translate="true">Widget Image With Resize</label>
    <description>Widget Description</description>
    <parameters>
        <parameter name="image" xsi:type="block" visible="true" sort_order="10" required="true">
            <label translate="true">Image</label>
            <block class="Staempfli\WidgetExtraFields\Block\Adminhtml\ImageField"/>
        </parameter>
           <parameter name="width" xsi:type="text" visible="true" required="true" sort_order="20">
                <label translate="true">Width</label>
            </parameter>
           <parameter name="height" xsi:type="text" visible="true" required="true" sort_order="30">
                <label translate="true">height</label>
            </parameter>
    </parameters>
</widget>

Vendor\Module\Block\Widget\<Your_Widget>

protected $_template = "Vendor_Module::widget/image-resize.phtml";

public function getImageUrl() : string
    {
        $image = $this->getData('image');
        if ($image) {
            return $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . $image;
        }
        return '';
    }

view/frontend/templates/widget/image-resize.phtml

<?php $resizerHelper = $block->getImageResizerHelper(); ?>
<img class="cms-widget__image"
             src="<?php echo $resizerHelper->resizeAndGetUrl($block->getImageUrl(), $block->getData('width'), $block->getData('height')); ?>">

What do you think? Would that be a valid solution for you?

@jalogut
Copy link
Contributor

jalogut commented Feb 2, 2018

Hi @johnny-longneck
Did you check the suggested solution? Any update will be appreciated to know if we can close this issue.

@jalogut jalogut self-assigned this Feb 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants