Filters
Use filters to influence ImpressPages core or other plugins behavior. Filtering is used when there is some data that potentially could be modified by many plugins. Good example is ipForbiddenExtensions filter issued by the core. This filter provides default array of extensions that are forbidden to be uploaded to the system. You can add two different plugins who both add or remove some items to / from that list without conflicting.
Listen to filter
Create Filter.php file in your plugin's root directory and add a Filter class definition. It should contain a static method which matches an event name. That's all you need to filter data.
<?php namespace Plugin\MyPlugin; class Filter { public static function ipForbiddenExtensions($extensions) { $extensions[] = '.xxx'; return $extensions; } }
Execute a filter
You can execute filters in your plugin to allow other plugins to filter your data. Put this code in the controller or model.
<?php $result = ipFilter('MyPlugin_parseTitle', 'Very long string.');
Listen to the event and replace the word "long" with "short".
<?php namespace Plugin\MyPlugin; class Filter { public static function MyPlugin_parseTitle($string) { return str_replace('long', 'short', $string); } }
Processing order
Many plugins can be attached to the same filter. They are executed in order specified by filter's priority. The priority is set by placing underscore character and numeric value in filter function name definition. Lower number means higher priority. The default filter's priority is 50.
Specify filter priority
<?php public static function changeLongToShort_20($string)
Additional filter data
When throwing a filter event you can pas not only the data needed to be filtered, but also contextual info needed.
Example of passing contextual filter data
<?php $contextualData = array( 'language' => 'en' ) $result = ipFilter('MyPlugin_parseTitle', 'very long string', $contextualData);
Use passed data to adjust filter behavior.
<?php namespace Plugin\MyPlugin; class Filter { public static function MyPlugin_parseTitle($string, $info) { if ($info['language'] == 'en) { //... } else { //... } } }