Skip to content

Commit

Permalink
Improve triggerEvent function
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Jun 13, 2024
1 parent 834f724 commit 1548a15
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
7 changes: 2 additions & 5 deletions framework/library/astroid/Element/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,15 @@ public static function getSublayouts($template = '')
foreach ($files as $file) {
$json = file_get_contents($file);
$data = \json_decode($json, true);
$layout = ['title' => pathinfo($file)['filename'], 'desc' => '', 'thumbnail' => '', 'data' => [], 'name' => pathinfo($file)['filename']];
$layout = ['title' => pathinfo($file)['filename'], 'desc' => '', 'thumbnail' => '', 'name' => pathinfo($file)['filename']];
if (isset($data['title']) && !empty($data['title'])) {
$layout['title'] = Text::_($data['title']);
}
if (isset($data['desc'])) {
$layout['desc'] = Text::_($data['desc']);
}
if (isset($data['thumbnail']) && !empty($data['thumbnail'])) {
$layout['thumbnail'] = Uri::root() . 'media/templates/site/' . $template . '/' . $data['thumbnail'];
}
if (isset($data['data'])) {
$layout['data'] = $data['data'];
$layout['thumbnail'] = Uri::root() . 'media/templates/site/' . $template . '/images/layouts/' . $data['thumbnail'];
}
$layouts[] = $layout;
}
Expand Down
7 changes: 5 additions & 2 deletions framework/library/astroid/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\Component\Menus\Administrator\Helper\MenusHelper;
use Joomla\Database\DatabaseInterface;

defined('_JEXEC') or die;

Expand Down Expand Up @@ -180,7 +181,9 @@ public static function getXml($url)
public static function triggerEvent($name, $data = [])
{
PluginHelper::importPlugin('astroid');
Factory::getApplication()->triggerEvent($name, $data);
// Factory::getApplication()->triggerEvent($name, $data);
$event = new Helper\Events($name, $data);
Factory::getApplication()->getDispatcher()->dispatch($name, $event);
}

public static function clearCacheByTemplate($template)
Expand Down Expand Up @@ -320,7 +323,7 @@ public static function fieldsetOrding($a, $b)

public static function getModules()
{
$db = Factory::getDbo();
$db = Factory::getContainer()->get(DatabaseInterface::class);
$query = "SELECT #__modules.*, #__usergroups.title as access_title FROM #__modules JOIN #__usergroups ON #__usergroups.id=#__modules.access WHERE #__modules.client_id=0";

$db->setQuery($query);
Expand Down
25 changes: 25 additions & 0 deletions framework/library/astroid/Helper/Events.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Astroid\Helper;

use Joomla\CMS\Event\AbstractImmutableEvent;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Event for getting information on an API Relationship
*
* @since 4.0.0
*/
final class Events extends AbstractImmutableEvent
{
}

0 comments on commit 1548a15

Please sign in to comment.