XF 2.1 Pass node_id to addon

Cupara

Well-known member
I'm utilizing a class extension that extends XF\Pub\Controller\Forum.php and in this I have added a confirmation page that once they click confirm, it updates the user table that they have confirmed. But right now it redirects to the main site, I need it to redirect back to the same forum they are currently viewing thread list.

I have tried
PHP:
$node_id
as well
PHP:
$forum['node_id']
and
PHP:
$node['node_id']
 
How are you generating the return link? I'm assuming you have access to the Forum entity that you're working with. Normally you'd return a redirect response.

PHP:
return $this->redirect($this->buildLink('forums', $forum));
 
@Liam W Right, I tried that but it errors with undefined variable referring to $forum.

Here is my code
PHP:
    protected function contentSave(User $visitor)
    {
        $visitor = \XF::visitor();
       
        $form = $this->formAction();
       
        $entityInput = $this->filter([
            'gt_ag_mature' => 'uint',
            'gt_ag_mature_time' => 'uint'
        ]);

        $form->basicEntitySave($visitor, $entityInput);

        return $this->redirect($this->buildLink('forums', $forum));
    }

I have it using ajax so it stays on the page but that is failing.
 
You need to define the content of the $forum variable somewhere, and you need to return this from an action - that isn't an action.
 
@Liam W here is my template modification.
HTML:
<xf:if is="!$xf.visitor.user_id">
    <div class="blockMessage blockMessage--important">
        <xf:fa icon="fa-info-circle fa-7x" style="float: left;" /> <span style="padding: 10px; vertical-align: top;">{{ phrase('gt_ag_visitor_text') }}</span>
    </div>
<xf:else />
    <xf:if is="$forum.gt_ag_agegate AND $xf.visitor.Profile.getAge(true) < $forum.gt_ag_agelimit">
        <xf:if is="$forum.gt_ag_agegate AND $forum.gt_ag_banner">
            <div class="blockMessage blockMessage--important">
                <xf:fa icon="fa-{$forum.gt_ag_banner_icon} {$forum.gt_ag_banner_icon} fa-7x" style="float: left;" /> <span style="padding: 10px; vertical-align: top;">{$forum.gt_ag_banner_text}</span>
            </div>
        </xf:if>
    <xf:elseif is="$forum.gt_ag_mature_o" />
        <xf:if is="!$xf.visitor.gt_ag_mature OR $xf.time > $xf.visitor.gt_ag_mature_time">
            <xf:form action="{{ link('forums/mature') }}" class="block" ajax="true" data-force-flash-message="true">
                <div class="block-container">
                    <ul class="block-body">
                        <li class="block-row block-row--separated avatarControl">
                            <xf:fa icon="fa-exclamation-triangle fa-7x" style="float: left;" /> <span style="padding: 10px; vertical-align: top;">{{ phrase('gt_ag_mature_content') }}</span>
                        </li>
                    </ul>
                    <xf:hiddenval name="gt_ag_mature">1</xf:hiddenval>
                    <xf:if is="$forum.gt_ag_mature_time_o==0">
                        <xf:hiddenval name="gt_ag_mature_time">{{$xf.time+315360000}}</xf:hiddenval>
                    <xf:else />
                        <xf:hiddenval name="gt_ag_mature_time">{{$xf.time+60*60*24*$forum.gt_ag_mature_time_o}}</xf:hiddenval>
                    </xf:if>
                    <xf:hiddenval name="node_id">{$forum.node_id}</xf:hiddenval>
                    <xf:hiddenval name="node_name">{$forum.node_name}</xf:hiddenval>
                    <xf:submitrow icon="confirm" sticky="true" action="{{ link('forums/{id}/') }}" />
                </div>
            </xf:form>
        </xf:if>
    </xf:if>
    <xf:if is="$xf.visitor.Profile.dob_day == '0' AND $xf.visitor.Profile.dob_month == '0' AND $xf.visitor.Profile.dob_year == '0' AND $forum.gt_ag_agegate">
        <div class="blockMessage blockMessage--important">
            <xf:fa icon="fa-exclamation-triangle fa-7x" style="float: left;" /> <span style="padding: 10px; vertical-align: top;">{{ phrase('gt_ag_no_birthday') }}</span>
        </div>
    </xf:if>
</xf:if>
$0

I'm passing a hiddenval for node_id but I'm not sure how to grab it in the php code above I showed you.
 
I figured it out. I was looking at the wrong action plus had too many redirects that was causing issues as well.
 
Back
Top Bottom