Hook: on_dashboard_boxes
avatar
Señor FAQ

¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.


Hook: on_dashboard_boxes

The on_dashboard_boxes hook in JScms allows developers to dynamically add custom boxes to the admin dashboard. This feature is particularly useful for providing administrators with additional information, statistics, or tools directly in their dashboard view.

How to Use the on_dashboard_boxes Hook

  1. Register a Hook: Use the DynamicHooks::addHook() function to define your custom logic and generate dashboard boxes.
  2. Provide Content: Return an array containing the box ID, title, icon, and content to display on the dashboard.
  3. Integrate: Ensure your hook is properly loaded and executed by JScms during the dashboard rendering.

Example Code

Here is an example of how to add a custom box to display marketplace statistics on the admin dashboard:


DynamicHooks::addHook('on_dashboard_boxes', function () use ($jakdb, $jkv, $lang) {

    // Fetch marketplace statistics
    $chartData = mp_getAdminMarketplaceStats($jakdb);

    // Generate the styled list content
    $boxContent = <<<HTML
    <ul class="list-group">
        <li class="list-group-item d-flex justify-content-between align-items-center">
            <div class="d-flex align-items-center">
                <i class="fas fa-dollar-sign me-2 text-success"></i> {$lang['marketplace_earnings_before_commission']}
            </div>
            <span class="badge bg-success rounded-pill text-white">{$chartData['total_earnings_before_commission']} {$jkv["marketplace_currency"]}</span>
        </li>
        <!-- Add additional statistics here -->
    </ul>
HTML;

    // Return the box data for the dashboard
    return [
        [
            'id' => 'unique_name',
            'title' => $lang['your_plugin_phrase'],
            'icon' => 'fas fa-store',
            'content' => $boxContent,
        ],
    ];
}, 'your_plugin');
        

Key Parameters

  • id: A unique identifier for the dashboard box (e.g., marketplace_stats).
  • title: The title of the dashboard box (supports multilingual values).
  • icon: The FontAwesome icon class to display next to the title.
  • content: The HTML content to display inside the box.

How to Render Boxes

In your admin dashboard file, make sure to include the following code to render the boxes dynamically:


<?php 
$dashboardBoxes = DynamicHooks::executeHook('on_dashboard_boxes', true); 
if (!empty($dashboardBoxes)) {
    foreach ($dashboardBoxes as $box) {
        echo '<div class="col-12" data-id="' . htmlspecialchars($box['id']) . '>';
        echo '<div class="card">';
        echo '<div class="card-header move-cursor">';
        echo '<h3 class="card-title">';
        if (!empty($box['icon'])) {
            echo '<i class="' . htmlspecialchars($box['icon']) . '"></i> ';
        }
        echo htmlspecialchars($box['title']);
        echo '</h3>';
        echo '<div class="card-options">';
        echo '<button class="btn btn-sm btn-outline-secondary toggle-visibility" data-id="' . htmlspecialchars($box['id']) . '" data-visible="true">';
        echo '<i class="fas fa-eye"></i>';
        echo '</button>';
        echo '</div>';
        echo '</div>';
        echo '<div class="card-body">';
        echo $box['content'] ?? '';
        echo '</div>';
        echo '</div>';
        echo '</div>';
    }
}
?>
        

Benefits of on_dashboard_boxes

This hook allows developers to extend the admin dashboard with dynamic content, providing administrators with valuable insights and tools in a centralized location.

Was this article helpful?
0 out of 0 found this helpful