I gather, from previous posts I have checked looking to see if anyone else has had similar problems, that either a link to somewhere so that the complete code can be seen or that complete code should be provided as the problems could stem from code not posted but exists.
To this end I have created a new extension using the skeleton (v 1.0.6) with the minimal content to show the problem I am having in the hope that someone can tell me what I am missing or doing incorrectly.
I'm using 3.2.1 on a LAMPP stack on my PC for testing.
Hopefully this will all go in one post and to that end I have omitted the 'Normal' parts of the files that have no impact upon the executing of the files such as the first few lines with the copyright and license stuff.
services.yml
Code: Select all
services.yml
services:
evo.confirmed..listener:
class: evo\confirmed\event\listener
arguments:
- '@dbal.conn'
- '@request'
- '%core.root_path%'
- '%core.php_ext%'
- '@user'
- '@template'
- '@config'
- '@dispatcher'
tags:
- { name: event.listener }
There are probably more services than needed as I have added some to see if anything obvious (to me) was missing. But it is quite possible that I am missing a needed one just don't know which one.
listener.php
Code: Select all
namespace evo\confirmed\event;
/**
* @ignore
*/
use phpbb\db\driver\driver_interface as db_interface;
use phpbb\request\request_interface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use phpbb\user;
use phpbb\template\template;
use phpbb\config\config;
/**
* Confirmed Event listener.
*/
class listener implements EventSubscriberInterface
{
/** @var db_interface */
protected $db;
/** @var request_interface */
protected $request;
/** @var string phpbb_root_path */
protected $phpbb_root_path;
/** @var string phpEx */
protected $php_ext;
/** @var functions */
protected $functions;
/** @var user */
protected $user;
/** @var \template */
protected $template;
/** @var config */
protected $config;
/** @var \phpbb\event\dispatcher_interface */
protected $phpbb_dispatcher;
/**
* Constructor
*
* @param db_interface $db
* @param request_interface $request
* @param string $phpbb_root_path
* @param string $php_ex
* @param user $user
* @param template $template
* @param config $config
* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher
*/
public function __construct(
db_interface $db,
request_interface $request,
$phpbb_root_path,
$php_ext,
user $user,
template $template,
config $config,
\phpbb\event\dispatcher_interface $phpbb_dispatcher
)
{
$this->db = $db;
$this->request = $request;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->user = $user;
$this->template = $template;
$this->config = $config;
$this->phpbb_dispatcher = $phpbb_dispatcher;
}
static public function getSubscribedEvents()
{
return array(
'core.user_setup' => 'load_language_on_setup',
'core.viewtopic_modify_post_row' => 'insert_post_buttons',
'core.modify_posting_parameters' => 'lb_move_post',
);
}
/**
*
* @param \phpbb\event\data $event Event object
*/
public function load_language_on_setup($event)
{
$lang_set_ext = $event['lang_set_ext'];
$lang_set_ext[] = array(
'ext_name' => 'evo/confirmed',
'lang_set' => 'common',
);
$event['lang_set_ext'] = $lang_set_ext;
}
public function insert_post_buttons($event)
{
$row = $event['row'];
$forum_id = (int) $row['forum_id'];
$post_id = (int) $row['post_id'];
$postrow = $event['post_row'];
$postrow = array_merge($postrow, array(
'U_DEADPOSTS' => append_sid("{$this->phpbb_root_path}posting.$this->php_ext", 'mode=move&f=' . $forum_id . '&p=' . $post_id . '&move_reason=Obsolete Post'),
));
$event['post_row'] = $postrow;
}
public function lb_move_post($event)
{
$move_reason = $this->request->variable('move_reason', '', true);
// Test to check if this event is for this extension
if ($move_reason != "Obsolete Post")
{
return; // Working as expected
}
// This extension's button was clicked so go ahead and do what needs to be done
$title = 'MOVE';
$redirect = append_sid("{$this->phpbb_root_path}viewtopic.$this->php_ext", 'f=' . $forum_id . '&p=' . $post_id . '&#p' . $post_id);
$s_hidden_fields = build_hidden_fields(array(
'post_id' => $post_id,
'to_topic_id' => 6149,
't' => $topic_id,
'submit' => true,
'redirect' => $redirect
));
if (!function_exists('confirm_box'))
{
include($this->phpbb_root_path . 'includes/functions.' . $this->php_ext);
}
//echo "here"; NO ERROR SHOWN AT THIS POINT 'here' DISPLAYED CORRECTLY
//die();
// $confirmed = confirm_box(false); CAUSES ERROR
// $confirmed = confirm_box(false, $title); CAUSES ERROR
$confirmed = confirm_box(false, $title, $s_hidden_fields); // CAUSES ERROR
//echo "here"; // NEVER GETS HERE
//die();
if ($confirmed)
{
echo "Do It"; // Code to perform the required actions - user clicked YES
}else{
echo "Cancel"; // Operation cancelled - user clicked NO
}
die();
}
}
As far as I can see from the documentation the confirm_box function should work with just the first three parameters passed but I cannot get the Box to appear.
The
$title
is passed correctly so it could be that there is something in the
$s_hidden_fields
that I am missing.
I have also tried to follow the examples in other working extensions but the
confirm_box(true)
part of the
if
condition never gets executed and it always fails on the
confirm_box(false)
line
All I am trying to achieve is to give the user the opportunity, after they have clicked my button, the chance to cancel the operation should they have clicked it in error.
Just to complete the code, although as the button appears and is recognised when clicked, I don't think this has any bearing on the problem, here is the rest of the code :-
language/en/common.php
Code: Select all
if (empty($lang) || !is_array($lang))
{
$lang = array();
}
$lang = array_merge($lang, array(
'DEADPOSTS' => 'Move post to All Dead Posts',
));
styles/prosilver/temlate/event/viewtopic_body_post_buttons_after.html
Code: Select all
<a href="{postrow.U_DEADPOSTS}" title="{L_DEADPOSTS}" class="button button-icon-only">
<i class="icon fa-chain-broken fa-fw" style="font-size:24px" aria-hidden="true"></i>
<span class="sr-only">{L_DEADPOSTS}</span>
</a>
The error I get is 26 lines of :-
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/user.php on line 619: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, null given
And then :-
Fatal error: Call to a member function getName() on null in /opt/lampp/htdocs/public_html/forum_new/includes/functions.php on line 4321
Any assistance will be greatly appreciated.