XF 2.1 XF:Delete plugin code not able to identify local variables

asprin

Active member
I've this in the template:
HTML:
<xf:delete href="{{ link('foo/bar/delete', $foo, {'source':'a1'}) }}" />

My public controller looks like the following:

PHP:
public function actionDelete(ParameterBag $params)
{
    $foo = $this->assertFooExists($params->sys_id);
  
    if(!$foo->canDelete($error))
    {
        return $this->noPermission($error);
    }

    $source = trim($this->filter('source', 'str'));

    if($source == 'b1')
    {
        $path = 'foo/bar/about';
        $entity = $foo->About;         
    }
    else if($source == 'a1')
    {
        $path = 'foo/bar/home';
        $entity = $foo->Home;               
    }
    //return $this->error($path); <-- this is printing foo/bar/home in the popup, so I've confirmation that it went into the correct if/else block
    $link =  $this->buildLink($path, $entity);

    $plugin = $this->plugin('XF:Delete');
    return $plugin->actionDelete(
        $foo,
        $this->buildLink('foo/bar/delete', $foo),
        null,
        $link,
        $foo->title
    );
}

After clicking the delete icon from the UI, I'm getting the initial popup that says "Please confirm that you want to delete the following:". However, after clicking the "Delete" button, I'm getting an error that says the following:
1672637453447.png


Now this has me stumped as it's printing the correct value a line before that (line 22) but somehow doesn't seem to be recognizing it post that. Anything silly that I'm missing here?
 
Solution
Figured it out. I realized that when the Delete button is clicked, it becomes a POST and I just needed to pass the source parameter to the $confirmURL variable that becomes the action part of the form. Hence,

Code:
return $plugin->actionDelete(
    $foo,
    $this->buildLink('foo/bar/delete', $foo, ['source' => $source]),
    null,
    $link,
    $foo->title
 );
Figured it out. I realized that when the Delete button is clicked, it becomes a POST and I just needed to pass the source parameter to the $confirmURL variable that becomes the action part of the form. Hence,

Code:
return $plugin->actionDelete(
    $foo,
    $this->buildLink('foo/bar/delete', $foo, ['source' => $source]),
    null,
    $link,
    $foo->title
 );
 
Solution
Back
Top Bottom