Defining the problemWidgets are small snippets of code that enable people to do a variety of things such as share content, visit social media profiles, view updates and so forth. Some widgets are simply copy and paste. Others require dynamic data such as a page title or URL. Many widgets can be customized by changing various parameters in their code. The main challenges with widgets are:
- How do we place them on the site?
- How do we deal with dynamic data?
- How do we manage custom settings?
- How do we keep a diverse set of widgets organized?
The Widgets module
The Widgets module is meant to act as an API to help centralize management of various code snippets. It has an API for modules to provide code snippets via widget definitions. You can also add custom definitions via the admin.
Widgets definitions can be organized and customized into widget sets. Widget sets are built using an interface similar to core's image style admin. Just create a new widget set then add widget elements from a drop down list. You can sort widgets via drag and drop and modify customizable widgets via configuration forms.
Sets can be displayed in blocks, tokens and node links by content type and display modes.
Drupal's core token system is used as the standard for managing dynamic data. Widget definitions can include standard tokens and special variable tokens which enable admins can configure settings per widget. A simple syntax makes it easy for widget definitions to auto-generate configuration forms from variable tokens.
To make things even more plug and play, the API enables modules to define pre-built widget sets. These can be overridden and customized.
Finally, a tunable caching layer is used to assure widget sets load quickly. Caching can be set across all pages, by node authors, by page and by logged in user.We hope you find the Widgets module as useful as we have for wrangling in the widget herds. Got any improvements, suggestions or comments? Let me know below. photo by kidicarus222