on Jan 9, 2020
Almost half a year ago, we’ve published a tiny Screenshot Widget module on Drupal.org. And I’ve just realized that we’ve never posted any manual or at least an announcement about it. Now it’s time to fix this.
As it is seen from the name, Screenshot Widget is a widget on top of the Drupal core Image field. Basically, it changes how an image is being retrieved from the client-side. Image usage remained exactly the same as with other image fields. This module heavily uses html2canvas library which does the main magic.
We’ve used this module to generate a preview of the dynamically-built product (via our product builder module). Though, I see a couple of other use scenarios for this module as well. For example:
To show it’s usage, I will describe the steps to build a simple bug reporting feature for Drupal website.
First, you need to ensure that you have all requirements met to proceed with the screenshot widget configuration. You need to have the following:
Functioning Drupal 8 website (preferable clean composer-based installation)
Content type with a core Image field. Preferable to call this content type “Issue” or “Bug”.
Of course, the first thing to proceed is installation. Since I’ve suggested using a composer-based installation, I assume you have a composer on your local machine. Run installation command
composer require drupal/screenshot_widget
Once the module was pulled to the file system, you need to enable it via the admin interface or using old-good drush.
drush en screenshot_widget
Now you need to download html2canvas library (version 1.0.0-alpha.12 or later) from https://html2canvas.hertzen.com/ and unzip it into the libraries folder. After that, libraries/html2canvas/html2canvas.min.js file should be available.
I am going to use an image field named “Screenshot”, this way I can keep consistent naming. Though, you can use whatever image field you have in your content type.
In order to start using Screenshot Widget, the only thing you need to do is to enable this widget on the “Manage form display” page.
Our widget has only a few settings available for change.
Now when you are creating the “Issue” content, you should see a similar result:
Screenshot of the content form. Not very useful, but already halfway to the expected result.
To make it look closer to a real bug reporting software, we need to place it on all pages of the site. Probably, the easiest way to achieve that is to use a Formblock module, which allows to output specific forms as blocks.
Using this module, we can easily output form in a right sidebar (or wherever fits you best).
Later, It can be styled to look like a pop-up or pop-over. I won’t stop on the functionality of the Formblock module, there is plenty of information on this topic on the web.
As soon as the form was placed into a sidebar, our goal is achieved. Now we have a form, which allows us to report some layout issues or text typos without need to create screenshots manually and upload them into the form.
I know that the form looks a bit ugly now, but this article isn’t about styling. Honestly, I don’t think that disabling WYSIWYG and applying some graphic sugar to the node form will cause you any problems.
I hope this blog article enlightens the purpose of this tiny module a bit. And as usual, if you have any questions/requests about this module (or any other Drupal-related topic) - feel free to contact us via a website or via social networks.
P.S. Just wanted to share a list of reliable Top eCommerce Development Companies.