Injected API (injapi)
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
This is a proof-of-concept module for a pattern to replace some overly verbose info hooks for a better DX, and a better ratio of verbosity vs expressiveness/readability.
The module wraps around 3 well-known info hooks, to provide an alternative API based on the "InjectedAPI" pattern.
With injapi, hook implementations should be
- less verbose
- less boilerplate
- more semantic
- more informative to read
- more pleasant to work with overall.
Results:
- hook_image_default_styles(): Awesome!
- hook_schema(): Nice.
- hook_menu(): Debatable.
Explanation: hook_menu() already has a pretty good information density, while hook_image_default_styles() has not. hook_schema() is somewhere in the middle.
Why should I install this?
If you intend to manage your image styles in code instead of the database, then hook_injapi_image_default_styles() is enough reason to install this module.
All the rest (menu and schema) can be seen as case studies, which you are free to use or not. At least, they won't be in the way.
Example
Image styles defined with the new injapi hook:
/**
* Implements hook_injapi_image_default_styles()
*/
function hook_injapi_image_default_styles($api) {
// Scale the image to 50x50.
$api->style('example_scale_50')->scale(50, 50);
// Crop the image to 100x100, then convert to grayscale.
$api->style('example_crop_gray')->crop(100, 100)->grayscale();
}
Equivalent, using the original hook:
/**
* Implements hook_image_default_styles()
*/
function hook_image_default_styles() {
$styles = array();
$styles['example_scale_50'] = array(
'effects' => array(
array(
'name' => 'image_scale',
'data' => array(
'width' => 50,
'height' => 50,
'upscale' => 1,
),
'weight' => 0,
),
),
);
$styles['example_crop_gray'] = array(
'effects' => array(
array(
'name' => 'image_crop',
'data' => array(
'width' => 100,
'height' => 100,
),
'weight' => 0,
),
array(
'name' => 'image_desaturate',
'data' => array(),
'weight' => 0,
),
),
);
return $styles;
}
