mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-02 22:36:21 -04:00
Add event-based view hook system allowing plugins to inject UI elements into core views without modifying core files. Includes helper functions and example CasposPlugin demonstrating the pattern.
27 lines
651 B
PHP
27 lines
651 B
PHP
<?php
|
|
|
|
use CodeIgniter\Events\Events;
|
|
|
|
if (!function_exists('plugin_content'))
|
|
{
|
|
function plugin_content(string $section, array $data = []): string
|
|
{
|
|
$results = Events::trigger("view:{$section}", $data);
|
|
|
|
if (is_array($results))
|
|
{
|
|
return implode('', array_filter($results, fn($r) => is_string($r)));
|
|
}
|
|
|
|
return is_string($results) ? $results : '';
|
|
}
|
|
}
|
|
|
|
if (!function_exists('plugin_content_exists'))
|
|
{
|
|
function plugin_content_exists(string $section): bool
|
|
{
|
|
$observers = Events::listRegistered("view:{$section}");
|
|
return !empty($observers);
|
|
}
|
|
} |