Error after adding the custom field to the extension.
see how I'm using it in the template:
Code: Select all
{CG_IMAGE_TOP}
the id of the custom field is cg_image_top.
see my code
controller
Code: Select all
<?php
namespace hs11\codegenerator\controller;
/**
* Code Generator main controller.
*/
class main
{
/* @var \phpbb\config\config */
protected $config;
/* @var \phpbb\controller\helper */
protected $helper;
/* @var \phpbb\request\request */
protected $request;
/* @var \phpbb\template\template */
protected $template;
/* @var \phpbb\user */
protected $user;
/* @var \phpbb\profilefields\manager */
protected $custom_fields_manager;
/**
* Constructor
*
* @param \phpbb\config\config $config
* @param \phpbb\controller\helper $helper
* @param \phpbb\request\request $request
* @param \phpbb\template\template $template
* @param \phpbb\user $user
* @param \phpbb\profilefields\manager $custom_fields_manager
*/
public function __construct(
\phpbb\config\config $config,
\phpbb\controller\helper $helper,
\phpbb\request\request $request,
\phpbb\template\template $template,
\phpbb\user $user,
\phpbb\profilefields\manager $custom_fields_manager
) {
$this->config = $config;
$this->helper = $helper;
$this->request = $request;
$this->template = $template;
$this->user = $user;
$this->custom_fields_manager = $custom_fields_manager;
// Recuperar o valor do campo personalizado
$this->cg_image_top = $this->get_custom_field('cg_image_top');
}
/**
* Recupera o valor de um campo personalizado.
*
* @param string $field_name Nome do campo personalizado.
* @return mixed Valor do campo ou null se não encontrado.
*/
protected function get_custom_field($field_name)
{
$user_id = $this->user->data['user_id'];
$custom_fields = $this->custom_fields_manager->grab_profile_fields_data([$user_id]);
return isset($custom_fields[$user_id][$field_name]) ? $custom_fields[$user_id][$field_name] : null;
}
/**
* Demo controller for route /codegenerator/{name}
*
* @param string $name
*
* @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
*/
public function handle($name)
{
// ANIMATION
$nome = $this->request->variable('nome', '', true);
$poster = $this->request->variable('poster', '', true);
$descricao = $this->request->variable('descricao', '', true);
$screen1 = $this->request->variable('screen1', '', true);
$screen2 = $this->request->variable('screen2', '', true);
$screen3 = $this->request->variable('screen3', '', true);
$screen4 = $this->request->variable('screen4', '', true);
$traduzido = $this->request->variable('traduzido', '', true);
$temporada = $this->request->variable('temporada', '', true);
$nome_episodio = $this->request->variable('nome_episodio', '', true);
$fan = $this->request->variable('fan', '', true);
$idioma = $this->request->variable('idioma', '', true);
$midias = $this->request->variable('midias', '', true);
$duracao = $this->request->variable('duracao', '', true);
$qualidade = $this->request->variable('qualidade', '', true);
$tamanho = $this->request->variable('tamanho', '', true);
$video_codec = $this->request->variable('video_codec', '', true);
$video_bitrate = $this->request->variable('video_bitrate', '', true);
$audio_codec = $this->request->variable('audio_codec', '', true);
$audio_bitrate = $this->request->variable('audio_bitrate', '', true);
$resolucao = $this->request->variable('resolucao', '', true);
$legendas= $this->request->variable('legendas', '', true);
$formato= $this->request->variable('formato', '', true);
$frame_rate = $this->request->variable('frame_rate', '', true);
$frame_rate = $this->request->variable('frame_rate', '', true);
$rip = $this->request->variable('rip', '', true);
$site = $this->request->variable('site', '', true);
$outras_info = $this->request->variable('outras_info', '', true);
$http = $this->request->variable('http', '', true);
$compartilhamento_http = $this->request->variable('compartilhamento_http', '', true);
$compartilhamento_torrent = $this->request->variable('compartilhamento_torrent', '', true);
$compartilhamento_magnet = $this->request->variable('compartilhamento_magnet', '', true);
$compartilhamento_ed2k = $this->request->variable('compartilhamento_ed2k', '', true);
$this->template->assign_vars(array(
'A_NOME'=> $nome,
'A_POSTER'=> $poster,
'A_DESCRICAO'=> $descricao,
'A_SCREEN1'=> $screen1,
'A_SCREEN2'=> $screen2,
'A_SCREEN3'=> $screen3,
'A_SCREEN4'=> $screen4,
'A_TRADUZIDO'=> $traduzido,
'A_TEMPORADA'=> $temporada,
'A_NOME_EPI'=> $nome_episodio,
'A_FAN'=> $fan,
'A_IDIOMA'=> $idioma,
'A_MIDIAS'=> $midias,
'A_DURACAO'=> $duracao,
'A_QUALIDADE'=> $qualidade,
'A_TAMANHO'=> $tamanho,
'A_VIDEO_C'=> $video_codec,
'A_VIDEO_B'=> $video_bitrate,
'A_AUDIO_C'=> $audio_codec,
'A_AUDIO_B'=> $audio_bitrate,
'A_RESOLUCAO'=> $resolucao,
'A_LEGENDAS'=> $legendas,
'A_FORMATO'=> $formato,
'A_FRAME_R'=> $frame_rate,
'A_RIP'=> $rip,
'A_SITE'=> $site,
'A_OUTRAS_INFO'=> $outras_info,
'A_HTTP'=> $http,
'A_COMPARTILHAMENTO_HTTP'=> $compartilhamento_http,
'A_COMPARTILHAMENTO_TORRENT'=> $compartilhamento_torrent,
'A_COMPARTILHAMENTO_MAGNET'=> $compartilhamento_magnet,
'A_COMPARTILHAMENTO_ED2K'=> $compartilhamento_ed2k,
));
if($name == "music") {
return $this->helper->render('codegenerator/music.html', $this->user->lang('CAT_MUSIC'));
}
if($name == "music_action") {
return $this->helper->render('codegenerator/form_action/music.html', $this->user->lang('CAT_MUSIC'));
}
if($name == "animation") {
return $this->helper->render('codegenerator/animation.html', $this->user->lang('CAT_ANIMATION'));
}
if($name == "animation_action") {
return $this->helper->render('codegenerator/form_action/animation.html', $this->user->lang('CAT_ANIMATION'));
}
if($name == "ebook") {
return $this->helper->render('codegenerator/ebook.html', $this->user->lang('CAT_BOOKS'));
}
if($name == "ebook_action") {
return $this->helper->render('codegenerator/form_action/ebook.html', $this->user->lang('CAT_BOOKS'));
}
if($name == "movies") {
return $this->helper->render('codegenerator/movies.html', $this->user->lang('CAT_MOVIE'));
}
if($name == "movies_action") {
return $this->helper->render('codegenerator/form_action/movies.html', $this->user->lang('CAT_MOVIE'));
}
if($name == "games") {
return $this->helper->render('codegenerator/games.html', $this->user->lang('CAT_GAMES'));
}
if($name == "games_action") {
return $this->helper->render('codegenerator/form_action/games.html', $this->user->lang('CAT_GAMES'));
}
if($name == "gamespc") {
return $this->helper->render('codegenerator/gamespc.html', $this->user->lang('CAT_GAMESPC'));
}
if($name == "gamespc_action") {
return $this->helper->render('codegenerator/form_action/gamespc.html', $this->user->lang('CAT_GAMESPC'));
}
if($name == "tvshow") {
return $this->helper->render('codegenerator/tvshow.html', $this->user->lang('CAT_TVSHOW'));
}
if($name == "tvshow_action") {
return $this->helper->render('codegenerator/form_action/tvshow.html', $this->user->lang('CAT_TVSHOW'));
}
if($name == "soft") {
return $this->helper->render('codegenerator/soft.html', $this->user->lang('CAT_SOFT'));
}
if($name == "soft_action") {
return $this->helper->render('codegenerator/form_action/soft.html', $this->user->lang('CAT_SOFT'));
}
if($name == "news") {
return $this->helper->render('codegenerator/news.html', $this->user->lang('CAT_NEWS'));
}
if($name == "news_action") {
return $this->helper->render('codegenerator/form_action/news.html', $this->user->lang('CAT_NEWS'));
}
if($name == "portal") {
return $this->helper->render('codegenerator/portal.html', $this->user->lang('CAT_PORTAL'));
}
if($name == "portal_action") {
return $this->helper->render('codegenerator/form_action/portal.html', $this->user->lang('CAT_PORTAL'));
}
return $this->helper->render('codegenerator.html', $this->user->lang('CODEGENERATOR_PAGE'));
}
}
Code: Select all
services:
hs11.codegenerator.controller:
class: hs11\codegenerator\controller\main
arguments:
- '@config' # Serviço de configuração
- '@controller.helper' # Helper do controlador
- '@request' # Gerenciador de requisições
- '@template' # Gerenciador de templates
- '@user' # Serviço de usuário
- '@profilefields.manager' # Gerenciador de campos personalizados
hs11.codegenerator.listener:
class: hs11\codegenerator\event\main_listener
arguments:
- '@controller.helper'
- '@template'
- '@user'
- '%core.php_ext%' # Parâmetro de extensão de arquivo
- '@?files.factory' # Dependência opcional
tags:
- { name: event.listener }