Load Rules
public function onLoadReservationCodesRules( array &$config ) : void
Fires while loading all the supported rules of the reservation codes.
Description
This hook can be used to support custom rules for the reservation codes.
It is enough to include the directory containing the new rules. Only the files that inherits the E4J\VikRestaurants\ReservationCodes\CodeRule
class will be taken.
In addition, the loaded classes must have a name built as [FILE_NAME] + CodeRule and should be part of the E4J\VikRestaurants\ReservationCodes\Rules
namespace.
In case the class name is not correct or it doesn't extend the previously mentioned class, the file will be ignored.
Parameters
- &$config
-
(array) It is possible to inject here the configuration for a specific rule. The parameters have to be assigned by using the rule file name.
Return Value
None.
Example
The example below adds support for all the rules contained in a specific folder of a third-party plugin. Such as:
/plugins/vikrestaurants/e4j/rules/
All the PHP
files contained within the rules folder of the VikRestaurants - E4J plugin will be loaded.
/**
* This hook can be used to support custom reservation codes rules.
* It is enough to include the directory containing the new rules
* Only the files that inherits the ResCodesRule class will be taken.
*
* @param array &$config It is possible to inject the configuration for
* a specific rule. The parameters have to be assigned
* by using the rule file name.
*
* @return void
*/
public function onLoadReservationCodesRules(&$config)
{
// fetch rules folder path
$folder = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'rules';
// include rules folder
E4J\VikRestaurants\ReservationCodes\CodesHandler::addIncludePath($folder);
// recover rule configuration from database
$params = [];
// register plugin configuration for being used
// while trying to apply the rule
$config['test'] = $params;
}
The class (shell) of the rule will be built as follows. The path of the file will be equal to this one.
/plugins/vikrestaurants/e4j/rules/test.php
namespace E4J\VikRestaurants\ReservationCodes\Rules;
class TestCodeRule extends \E4J\VikRestaurants\ReservationCodes\CodeRule
{
/**
* Returns a code readable name.
*
* @return string
*/
public function getName()
{
return 'E4J - Test';
}
/**
* Returns the description of the reservation code.
*
* @return string
*/
public function getDescription()
{
return 'Rule for test purposes';
}
/**
* Checks whether the specified group is supported
* by the rule. Children classes can override this
* method to drop the support for a specific group.
*
* @param string $group The group to check.
*
* @return boolean True if supported, false otherwise.
*/
public function isSupported($group)
{
return true;
}
/**
* Executes the rule.
*
* @param mixed $record The record to dispatch.
*
* @return void
*/
public function execute($record)
{
/**
* @todo apply the rule
*/
}
}
Changelog
Version | Description |
---|---|
1.9 | The hook has been changed from a filter into an action as the plugin didn't need a return value anymore. |
1.8 | Introduced. |