これについて私が見つけた唯一のソースはこの投稿からです: JSubmenuHelperをJHtmlSidebar/Joomla 4の管理メニューで置き換える
ここでの問題は、私が試してみたことであり、JHtmlSidebar
で試してもサイドバーが表示されません。
ここにコードがあります:
_public function render($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'toolbar' => null
));
foreach ($config->toolbar->getCommands() as $command)
{
if(!empty($command->href)) {
$command->href = $this->getTemplate()->route($command->href);
}
JSubmenuHelper::addEntry($this->getObject('translator')->translate($command->label), $command->href, $command->active);
}
return '';
}
_
この場合、_JSubmenuHelper::addEntry
_をJHtmlSidebar
関数に置き換える必要があります。
行を次のように変更しようとしました
_JHtmlSidebar::addEntry($this->getObject('translator')->translate($command->label), $command->href, $command->active);
_
そして
_JHtmlSidebar::render($this->getObject('translator')->translate($command->label), $command->href, $command->active);
_
しかし、addEntry
ではサイドバーは非表示になり、render()
ではコンテンツがありません。
私がすでに試みた試みの何が問題になっていますか?
最初に、次のようにContentHelper
を拡張するヘルパークラスを作成する必要があります。
administrator/components/com_mycomponent/Helper/MyComponentHelper.php
_use Joomla\CMS\Helper\ContentHelper;
class MyComponentHelper extends ContentHelper
{
protected $config = null;
public function __construct($config)
{
$this->config = new KObjectConfigJson($config);
$this->config->append(array(
'toolbar' => null
));
}
public static function addSubmenu()
{
foreach ($this->config->toolbar->getCommands() as $command)
{
if (!empty($command->href))
{
$command->href = $this->getTemplate()->route($command->href);
}
\JHtmlSidebar::addEntry(
$this->getObject('translator')->translate($command->label),
$command->href,
$command->active
);
}
}
}
_
次に、次のディレクトリで:
管理者/コンポーネント/com_mycomponent/controller.php
次のように、JLoader
を使用してクラスをロードします。
_JLoader::register('MyComponentHelper', JPATH_ADMINISTRATOR . '/components/com_mycomponent/helpers/contact.php');
_
完了したら、view.html.phpでクラスをインスタンス化する必要があります。
_MyComponentHelper::addSubmenu();
_
メモ:
\JHtmlSidebar
_の名前空間付きバージョンはないため、J4でサポートされるか、置き換えられるかはわかりません。getObject()
メソッドをクラスに追加するか、別のクラスからの場合は$this->getObject()
参照を変更する必要があります。お役に立てれば