Created
October 25, 2013 06:41
-
-
Save mariuswilms/7150324 to your computer and use it in GitHub Desktop.
Lithium filter to inject data into elements.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use lithium\net\http\Media; | |
$injectDataIntoElements = function(array $elements = [], array $data = []) { | |
Media::applyFilter('view', function($self, $params, $chain) use ($elements, $data) { | |
$view = $chain->next($self, $params, $chain); | |
$view->applyFilter('_step', function($self, $params, $chain) use ($elements, $data) { | |
$whitelisted = in_array($params['params']['template'], $elements); | |
if ($params['step']['path'] == 'element' && $whitelisted) { | |
$params['data'] += $data; | |
} | |
return $chain->next($self, $params, $chain); | |
}); | |
return $view; | |
}); | |
}; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment