Mini Blocks is a contributed module available on Drupal.org’s website www.drupal.org/project/mini_blocks.
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
// Output content directly (check for XSS).
$output .= filter_xss_admin(mini_blocks_get_value("myform_label"));
Example 2
// 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.
You can install by downloading the stable release here, or you can use drush:
drush dl mini_blocks --y;
drush en mini_blocks --y;