Ir al contenido

Extensión interna del sistema central de Znuny

Extensión interna del sistema central de Znuny

Sección titulada «Extensión interna del sistema central de Znuny»

En este artículo aprenderás cómo adaptar Znuny directamente en el núcleo mediante configuración XML, módulos Perl y plantillas. Te mostramos paso a paso cómo integrar tu propio módulo “HelloWorld” en el sistema.


Todas las adaptaciones se encuentran dentro de tu clon de Znuny en el directorio Kernel/:

Kernel/
├─ Config/Files/ # Registros XML
│ └─ XML/
├─ System/ # Módulos de lógica de negocio (Core)
├─ Modules/ # Frontend-Controller (Agent/Customer)
├─ Output/HTML/Standard/ # Plantillas Template Toolkit (TT)
└─ Language/ # Traducciones

Los nuevos módulos y rutas se registran mediante XML. Crea un archivo HelloWorld.xml en Kernel/Config/Files/XML/:

<?xml version="1.0" encoding="UTF-8"?>
<znuny_config version="2.0" init="Application">
<!-- 1. Registrar módulo de Frontend -->
<Setting Name="Frontend::Module###AgentHelloWorld" Required="1" Valid="1">
<Navigation>Frontend::Agent::ModuleRegistration</Navigation>
<Value>
<Item ValueType="FrontendRegistration">
<Hash>
<Item Key="Group"><Array><Item>users</Item></Array></Item>
<Item Key="Description" Translatable="1">Módulo HelloWorld</Item>
<Item Key="Title" Translatable="1">HelloWorld</Item>
<Item Key="NavBarName">HelloWorld</Item>
</Hash>
</Item>
</Value>
</Setting>
</znuny_config>

Crea tu lógica en Kernel/System/HelloWorld.pm:

package Kernel::System::HelloWorld;
use strict;
use warnings;
our @ObjectDependencies = ();
sub new {
my ($Type, %Param) = @_;
return bless {}, $Type;
}
sub GetHelloWorldText {
my ($Self, %Param) = @_;
return $Self->_FormatText(String => 'Hello World');
}
sub _FormatText {
my ($Self, %Param) = @_;
return uc $Param{String};
}
1;

En Kernel/Modules/AgentHelloWorld.pm integras tu lógica en el Frontend del agente:

package Kernel::Modules::AgentHelloWorld;
use strict;
use warnings;
sub new { bless {}, shift }
sub Run {
my ($Self, %Param) = @_;
my $HelloObj = $Kernel::OM->Get('Kernel::System::HelloWorld');
my $LayoutObj = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
my %Data;
$Data{Text} = $HelloObj->GetHelloWorldText();
return
$LayoutObj->Header(Title => 'HelloWorld')
. $LayoutObj->NavigationBar()
. $LayoutObj->Output(
TemplateFile => 'AgentHelloWorld',
Data => \%Data,
)
. $LayoutObj->Footer();
}
1;

Crea la siguiente plantilla en Kernel/Output/HTML/Standard/AgentHelloWorld.tt:

[% Data.Text %]
<p>¡Este es tu módulo HelloWorld creado por ti mismo!</p>

  1. Recargar:

    Ventana de terminal
    bin/znuny.Console.pl Maint::Config::Rebuild
  2. Limpiar caché:

    Ventana de terminal
    bin/znuny.Console.pl Maint::Cache::Delete
  3. Abrir navegador: Interfaz de agente → Menú → “HelloWorld”


  • Declarar limpiamente las ObjectDependencies (p. ej., DB, Layout).
  • No olvidar la documentación POD en los módulos Perl.
  • Mantener las traducciones en Kernel/Language/es_*.pm.
  • Configurar Unit-Tests con Mojolicious (opcional).
  • Después de cada cambio, ejecutar Config rebuild y limpiar caché.

Con esto tienes una base sólida para realizar más extensiones del núcleo en Znuny. ¡Diviértete desarrollando!