mecha-cms / x.panel

Control panel feature.
Other
6 stars 0 forks source link

TODO: Move Panel-Related Function to a Dedicated Namespace #21

Closed taufik-nurrohman closed 3 years ago

taufik-nurrohman commented 3 years ago

Developer should construct the GUI function as _\lot\x\panel\type\button(array $in, $key) instead of _\lot\x\panel\button(array $in, $key) to be used in the GUI data like so:

[
    'g' => [
        'title' => 'Update',
        // This calls `_\lot\x\panel\type\button()`
        'type' => 'button',
        'skip' => 's' === $_['task'],
        'stack' => 10
    ],
    'l' => [
        'title' => 'Delete',
        // This calls `_\lot\x\panel\type\button\link()`
        'type' => 'button/link',
        'stack' => 20
    ],
    's' => [
        'title' => 'Save',
        // This calls `_\lot\x\panel\type\button\text()`
        'type' => 'button/text',
        'stack' => 30
    ]
]

Most of function names that bound to the _\lot\x\panel namespace are added to be used by the type property such as button, link, and text. But some categories are no longer suitable to be declared under this namespace because they cannot be used as a valid type data. One example is the route category. Every functions under _\lot\x\panel\route namespace are intended to be used as custom routes.

My categorization plan for the future is like this:

taufik-nurrohman commented 3 years ago

Helper function should be attached to the function call scope to be used easily by third-party extensions:

namespace _\lot\x\panel\h;

function field(array $value, $key) {
    $out = /* … */;
    return new \HTML($out);
}
namespace _\lot\x\panel\type\field;

function text(array $value, $key) {
    $out = $this->field($value, $key);
    $out['content'][0] = 'input';
    $out['content'][1] = false;
    return $out;
}
// …
$v = "\\_\\lot\\x\\panel\\type";
$type = $value['type'] ?? "";
return \fire($v . ($type ? "\\" . $type : ""), [$value, $key], (object) [
    'description' => "\\_\\lot\\x\\panel\\h\\description",
    'field' => "\\_\\lot\\x\\panel\\h\\field",
    'title' => "\\_\\lot\\x\\panel\\h\\title"
]);