XF 2.0 Why is $canInlineMod passed via $viewParams to templates?

nocte

Well-known member
e.g. action View in Member Controller:

PHP:
$canInlineMod = false;
        foreach ($profilePosts AS $profilePost)
        {
            if ($profilePost->canUseInlineModeration())
            {
                $canInlineMod = true;
                break;
            }
        }

       $viewParams = [
           'user' => $user,

           'profilePosts' => $profilePosts,
           'canInlineMod' => $canInlineMod,
           'page' => $page,
           'perPage' => $perPage,
           'total' => $total
       ];

and ProfilePost Entity:
PHP:
public function canUseInlineModeration(&$error = null)
    {
        $visitor = \XF::visitor();
        return ($visitor->user_id && $visitor->hasPermission('profilePost', 'inlineMod'));
    }
This seem to happen in all Controllers that use inline moderation.

Why is not profilePosts.canUseInlineModeration() used in the templates like it is with other permissions done?

Edit: oh, I think I found the reason. We also need the Permission for the "check all" checkbox and such things..
 
.. but why is not Entity/User used? There could be a method like canUseProfilePostsInlineModeration()
 
A moderator might be able to use inline moderation for one piece of content on a page, but not another piece of content on the same page. I think this applies more to threads and posts since permissions can vary by node, but it could still happen with other content types when taking into consideration an add-on might extend canUseInlineModeration() for one reason or another.

The global flag is used to determine whether or not to enable inline moderation globally (by pulling in the JS and adding initializers where appropriate), and the per-entity method is used to determine whether to enable it for a particular piece of content.
 
Yeah, in the meantime I also found XF\Pub\Controller\Search::actionResults() where it also makes sense to me.
 
Yeah, mixed content type lists or mixed node thread lists (searches, the 'What's New' system, etc) are where it's most applicable in the core. And it keeps the door open for add-ons to do things like enable inline moderation for profile posts posted to a member's own profile, for example.
 
Top Bottom