The Mini Blocks module allows administrators to create simple key/value elements similar to typical Drupal Blocks, but with named keys rather than auto-increment integers. This allows admins/content editors to create editable pieces of content with "keys" that can be programmatically called based on their names.
This module allows programmers to call editable pieces of content that are not associated to a particular content type with keys that remain consistent from all environments whether they be in different sequences in local, dev, test, stage, prod etc.
Lets say you have a dashboard. This dashboard may be used to pull in multiple content types/entities, but there are always headings, labels etc. that are not editable. With Mini Blocks, you can build this into your dashboard so any or every visible piece of content can be managed without future code changes.
Simple example: lets say you might change "login" to "log in" or "sign in". Just make it a configurable Mini Block named "user_access_label" in the admin screen, then in your module or theme call it like so:
Example 1
<?php
// Output content directly (check for XSS).
$output .= filter_xss_admin(mini_blocks_get_value("myform_label"));
?>Example 2
<?php
// Show link to login page (XSS is checked in l() automatically.
$user_access_label = mini_blocks_get_value("user_access_label");
l($user_access_label, "user/login");
?>
FAQs
Q: But can't I do this by loading a block?
A: Yes, but in your code you must call the block by numeric block ID. These ID's change from local, to dev, to prod environments. When you make a predictable key you can keep these consistent.
Q: Won't this be fixed with Drupal 8?
A: Partially, but you run the risk of make your blocks become unbearably verbose. The hope with Mini Blocks is that you can use it like a "label maker". It's simple and you can create tons of entries without making you Blocks too verbose.
Caution:
The function call mini_blocks_get_value() does not do any filtering allowing the developer to specify if this goes in HTML, form, etc. This means content editors can input any value they want into the "block value", so apply permissions with caution, and filter your outputs appropriately.
Similar Modules
The advantage of Mini Blocks over many others is that it is specifically a developer module to place bits of content in your theme/module. This removes a lot of extras that may be unnecessary.
blocks — (Drupal Core) cannot be called by predictable keys.
snippets — Has integration with panels. Requires Panels module.
bean — Contains a full featured entity API to field your blocks. Use this if you're looking for more than just a light-weight module to gain key/value pairs.
boxes — Boxes are meant to add functionality to existing blocks, while Mini Blocks intentions are to remain completely independent without affecting the core functionality of blocks.
Project information
- Project categories: Administration tools, Content editing experience, Content display
2 sites report using this module
- Created by cfischer83 on , updated
Stable releases for this project are covered by the security advisory policy.
There are currently no supported stable releases.
