• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 Tips on extending the approval-queue handler?

Jaxel

Well-known member
#1
I created a content type field:
  • ewr_rio_queue
  • approval_queue_handler_class
  • EWR\Rio\ApprovalQueue\Queue
I also added functions to my Entity:
Code:
    public function canApproveUnapprove(&$error = null)
    {
        $visitor = \XF::visitor();
        return ($visitor->user_id && $visitor->hasPermission('EWRrio', 'modChannels'));
    }
  
   protected function _postSave()
    {
        $approvalQueue = $this->getRelationOrDefault('ApprovalQueue', false);
        $approvalQueue->content_date = $this->queue_date;
        $approvalQueue->save();
    }

    protected function _postDelete()
    {
        if ($this->ApprovalQueue)
        {
            $this->ApprovalQueue->delete();
        }
    }
 
    public static function getStructure(Structure $structure)
    {
        $structure->table = 'ewr_rio_queue';
        $structure->shortName = 'EWR\Rio:Queue';
        $structure->primaryKey = 'queue_id';
        $structure->columns = [
            'user_id'            => ['type' => self::UINT, 'required' => true],
            'queue_id'            => ['type' => self::UINT, 'autoIncrement' => true],
            'queue_url'            => ['type' => self::STR, 'required' => true],
            'queue_date'        => ['type' => self::UINT, 'required' => true],
        ];
        $structure->getters = [];
        $structure->relations = [
            'ApprovalQueue' => [
                'entity' => 'XF:ApprovalQueue',
                'type' => self::TO_ONE,
                'conditions' => [
                    ['content_type', '=', 'ewr_rio_queue'],
                    ['content_id', '=', '$queue_id']
                ],
                'primary' => true
            ]
        ];

        return $structure;
    }
Then I created my ApprovalQueue class:
Code:
<?php

namespace EWR\Rio\ApprovalQueue;

use XF\Mvc\Entity\Entity;

class Queue extends \XF\ApprovalQueue\AbstractHandler
{
    protected function canActionContent(Entity $content, &$error = null)
    {
        return $content->canApproveUnapprove($error);
    }

    public function actionApprove(\EWR\Rio\Entity\Queue $queue)
    {
        $channelRepo = \XF::repository('EWR\Rio:Channel');
        $channelRepo->fetchChannel($queue->queue_url, true, $queue->user_id);
       
        $queue->delete();
    }

    public function actionDelete(\EWR\Rio\Entity\Queue $queue)
    {
        $queue->delete();
    }
}
I don't know what to do at this point to get items to actually show up in the moderation queue.
 
Last edited:

Liam W

Well-known member
#2
Take a close look at the Post entity, everything you need is in there.

At the moment, all your content is being sent to the approval queue, even if it's already visible (your postsave method).

If you've setup the rest correctly, you should just have to create the approval_item_<content_type> (approval_item_ewr_rio_queue for you) public template, and put the approval UI in there.

Note: You'll probably want to put your content type in the entity structure as well.

Liam[/icode]
 

Jaxel

Well-known member
#3
Okay, I added $structure->contentType = 'ewr_rio_queue';. However, I am still getting this error on the approval queue page:
Code:
LogicException: Content type ewr_rio_queue must define an 'entity' value in src/XF/App.php at line 2254
 

Liam W

Well-known member
#4
Okay, I added $structure->contentType = 'ewr_rio_queue';. However, I am still getting this error on the approval queue page:
Code:
LogicException: Content type ewr_rio_queue must define an 'entity' value in src/XF/App.php at line 2254
Yeah, in your content types page, create a new field named entity with your entity class' short name (look at other fields for an example).

Liam
 

Jaxel

Well-known member
#5
Great! New error...
Code:
LogicException: Could not determine content viewability; please override in src/XF/ApprovalQueue/AbstractHandler.php at line 41
 

Liam W

Well-known member
#6
Great! New error...
Code:
LogicException: Could not determine content viewability; please override in src/XF/ApprovalQueue/AbstractHandler.php at line 41
You either need to have a canView method in your Entity, or override the canViewContent method in your handler.

Liam
 

Jaxel

Well-known member
#7
Okay, no more errors... However, I'm still not seeing anything in the queue (I made the template). And there is no alert bubble either.
 

Jaxel

Well-known member
#9
Yeah. I'm looking at my database right now too... and there is an entry in the xf_approval_queue table for it.
 

Liam W

Well-known member
#10
I'm assuming the canView method returns true?

And the content type & id in the approval queue table match up to the actual content?

Liam
 

Jaxel

Well-known member
#11
I'm assuming the canView method returns true?

And the content type & id in the approval queue table match up to the actual content?

Liam
Code:
    protected function canViewContent(Entity $content, &$error = null)
    {
        return true;
    }
And yes on the match.
 

Liam W

Well-known member
#12
Just a theory, but if you unapprove a random post, does that show it (I'm assuming you actually have content in the template).

Liam
 

Jaxel

Well-known member
#14
These are the things I've done...
  • created content type field for "approval_queue_handler_class"
  • created content type field for "entity"
  • created template for "approval_item_ewr_rio_queue"
  • created class for EWR\Rio\ApprovalQueue
  • added relevant functions to my EWR\Rio\Entity
Thats ALL I did... are there other steps I'm missing?
 

Jaxel

Well-known member
#16
That should work, if everything is done through the entity - that will update the queue count cache.



Are you referring to it showing correctly, or the template having content?

Liam
Huh? If a unapproved a post, it shows up in the queue.
 

Jaxel

Well-known member
#17
That should work, if everything is done through the entity - that will update the queue count cache.
What do you mean by this? This is my entity as of now:

Code:
<?php

namespace EWR\Rio\Entity;

use XF\Mvc\Entity\Structure;

class Queue extends \XF\Mvc\Entity\Entity
{
    public function canView(&$error = null)
    {
        $visitor = \XF::visitor();
        return ($visitor->user_id && $visitor->hasPermission('EWRrio', 'modChannels'));
    }
    
    public function canApproveUnapprove(&$error = null)
    {
        $visitor = \XF::visitor();
        return ($visitor->user_id && $visitor->hasPermission('EWRrio', 'modChannels'));
    }
    
    protected function _preSave()
    {
        $this->user_id = \XF::visitor()->user_id;
        $this->queue_date = \XF::$time;
    }
    
    protected function _postSave()
    {
        $approvalQueue = $this->getRelationOrDefault('ApprovalQueue', false);
        $approvalQueue->content_date = $this->queue_date;
        $approvalQueue->save();
    }

    protected function _postDelete()
    {
        if ($this->ApprovalQueue)
        {
            $this->ApprovalQueue->delete();
        }
    }
    
    public static function getStructure(Structure $structure)
    {
        $structure->table = 'ewr_rio_queue';
        $structure->contentType = 'ewr_rio_queue';
        $structure->shortName = 'EWR\Rio:Queue';
        $structure->primaryKey = 'queue_id';
        $structure->columns = [
            'user_id'            => ['type' => self::UINT, 'required' => true],
            'queue_id'            => ['type' => self::UINT, 'autoIncrement' => true],
            'queue_url'            => ['type' => self::STR, 'required' => true],
            'queue_date'        => ['type' => self::UINT, 'required' => true],
        ];
        $structure->getters = [];
        $structure->relations = [
            'User' => [
                'entity' => 'XF:User',
                'type' => self::TO_ONE,
                'conditions' => 'user_id',
                'primary' => true,
            ],
            'ApprovalQueue' => [
                'entity' => 'XF:ApprovalQueue',
                'type' => self::TO_ONE,
                'conditions' => [
                    ['content_type', '=', 'ewr_rio_queue'],
                    ['content_id', '=', '$queue_id']
                ],
                'primary' => true
            ]
        ];

        return $structure;
    }
}
 

Jaxel

Well-known member
#18
Tracing through XF\Repository\ApprovalQueue->filterViewableUnapprovedItems...

$handler->canView($content) always seems to turn up FALSE... even though I have it explicitly set to true.