XF 2.0 Using rich-text editor in inline-moderation

Rasmus Vind

Well-known member
I have a system where people submit content and in order for said content to be approved, a moderator approves/rejects it and posts a review at the same time. Similar to XF but it has more states and more options directed at this type of content.
Now, I wanted to make an inline-moderation version of this moderation but I have no good way to get the content of the editor because I am not able to get the controller from here.
Take a look at my example below:
PHP:
<?php

namespace VindIT\Repository\InlineMod\Bundle;

use XF\InlineMod\AbstractAction;
use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\AbstractCollection;
use XF\Http\Request;

class SetReviewState extends AbstractAction
{
    // [...]

    // This one displays an editor
    public function renderForm(AbstractCollection $entities, \XF\Mvc\Controller $controller)
    {
        $viewParams = [
            'threads' => $entities,
            'total' => count($entities),
        ];
        return $controller->view('VindIT\Repository:Public:InlineMod\Bundle\SetReviewState', 'ratory_moderate_bundle', $viewParams);
    }

    public function getFormOptions(AbstractCollection $entities, Request $request)
    {
        $app = $this->app();
        // Spoiler: This does not work
        $editorPlugin = $app->controller->plugin('XF:Editor')->fromInput('message');
        return [
            'state' => $request->filter('review_state', 'str'),
            'replace_reviews' => $request->filter('replace_reviews', 'str'),
            'send_alert' => $request->filter('send_alert', 'bool'),
            'message' => $editorPlugin->fromInput('message'),
        ];
    }
}
I am trying to get to the XF:Editor controller plugin by trying to get some global instance of a controller because at this stage, the controller we came from is not in scope.

So far, the best solution I can think of is to actually copy-paste the code from this plugin into my code but that seems dirty and a maintenance risk in case the editor changes in the future.

CC: @Mike, @Kier, @Chris D
 
I ended up creating a class extension on XF\Pub\Controller\InlineMod with this code:
PHP:
<?php
namespace VindIT\Repository\Extend\XF\Pub\Controller;
class InlineMod extends \XF\Pub\Controller\InlineMod
{
    public static $editorPlugin;
    public function actionPerform()
    {
        self::$editorPlugin = $this->plugin('XF:Editor');
        return parent::actionPerform();
    }
}
And had this in my inline-mod action:
PHP:
    public function getFormOptions(AbstractCollection $entities, Request $request)
    {
        $class = $this->app()->extendClass('XF\Pub\Controller\InlineMod');
        $plugin = $class::$editorPlugin;
        return [
            'state' => $request->filter('review_state', 'str'),
            'replace_reviews' => $request->filter('replace_reviews', 'str'),
            'send_alert' => $request->filter('send_alert', 'bool'),
            'message' => $plugin->fromInput('message'),
        ];
    }

This is a major hack and I feel like you should expose the current controller in ->app() or give it to the action handler.
 
Top Bottom