XF 2.2 Extend a class and nothing happens?

Robert9

Well-known member
Are there classes, i can not extend?
How can I check if a class is extended?

Real world example:

XML:
<?xml version="1.0" encoding="utf-8"?>
<class_extensions>
  <extension from_class="XF\ForumType\AbstractHandler" to_class="Xencafe\Lala\XF\ForumType\AbstractHandler" execute_order="1000" active="1"/>
 </class_extensions>

Code:
<?php
namespace Xencafe\Lala\XF\ForumType;

use XF\Entity\Forum;

class AbstractHandler extends XFCP_AbstractHandler
{
    public function getThreadListSortOptions(Forum $forum, bool $forAdminConfig = false): array
    {
        $sorts = \XF::repository('XF:Thread')->getDefaultThreadListSortOptions($forAdminConfig);

     Please, show me an error now!!!

        return $sorts;
    }

}

Normally the program should spit an error now, right?
If I copy that Please, show me an error now!!! to the original class, i get me error.
Also I can manipulate $sorts there. When i watch /admin.php?class-extensions/ it says that the class is extended.


What I can do now? Xdebug and follow the steps? But if it is not jumping to my class ... what can I do?
 
You can't extend abstract classes via class proxy, you have to extend to individual child classes instead.
 
Somehow I dont like that.
I can't inject the repository because I have no node_id;
I cant inject the abstract class, ok.

Is there another way to add a sort option, please?

The problem is, just to repeat it, that i have

hasPermission (no problem to manipulate the repository->thread),
but also hasNodePermission only; and for this i need a nodeId.
 
Is there another way to add a sort option, please?
I don't see any clean way to implement node-dependent sort options for all forum types (wtihout extending each child class).

A hacky approach could be to make a backtrace in \XF\Repository\Thread::getDefaultThreadListSortOptions and check the params.

A clean solution probably would require changes to standard XenForo code, for example by introducing a code event or by passing down the node entity to the repository.
 
Thank you, very much.
I have no idea what is a backtrace, but maybe something to fetch my forumId?

I have changed the four files in ForumTypes. So, this is solved now.
A minute ago, I have also solved how to pass a checkbox to the "remove filter" function.

I hope the add-on is now finished.



Can you please confirm that

hasPermission(forum, permission_name)

sets all

hasNodePermission(nodeId, permission_name)


I don't know it, but I have tested different setting for this permission and It seems that hasNodePermissions(...) is enough to ask for.
 
I have no idea what is a backtrace, but maybe something to fetch my forumId?

Can you please confirm that

hasPermission(forum, permission_name)

sets all

hasNodePermission(nodeId, permission_name)
I have no idea what you are asking here?

If \XF::visitor()->hasPermission('forum', 'viewContent') is true, this doesn't mean that \XF::visitor()->hasNodePermission($nodeId, 'viewContent') is true as well for all node IDs - it fact it could be false for all node ids.
 
We can set all nodes to no and hasPermission to yes.
But this is not the point. The point is:

Do I need

if hasNodepermission ...

AND

if hasPermission


or is it enough to do

if hasNodepermission ...

because all hasNodePermission are set to yes, when hasPermission is set to yes, as long we don't set them to no.
 
I am sorry, but I don't understand your question :(

Rule of thumb: Check non-nodebased permissions with hasPermission, check nodebased permissions with hasNodePermission.

Oder ausnahmsweise auf Deutsch falls das einfacher ist (aber eigentlich ist das dann eher ein Fall für xendach.de):
Mit hasPermission prüfst Du ob ein User (auf Grund seiner Benutzergruppen bzw. individueller Benutzerrechte) eine bestimmte Berechtigung hat; dies trifft bei nodebasierten Berechtigungen keine Aussage darüber ob er diese Berechtigung in einem spezifischen Node hat oder nicht.
Wenn Du nodebasierte Berechtigungen für einen spezifischen Node prüfen möchtest musst Du hasNodePermission nutzen.
Du könntest in diesem Fall natürlich zusätzlich hasPermission prüfen, das ergibt aber eigentlich keinen Sinn - Du willst ja wissen ob das Recht in einem spezifischen Node gesetzt ist oder nicht (und der Standard-Code prüft nodebasierte Berechtigungen auch nur für den jeweiligen Node)
 
Yesterday I had both; then i have searched examples and ound only
if hasNodePermissions,
then I tried and

PHP:
            if ($visitor->hasNodePermission($nodeId, 'editPost'))
            {

works for:

user group yes, forum nothing
user group nothing, forum yes
user group no, forum yes
...
I have not tried all of them
 
Last edited:
As I already tried to explain in my previous post(s):
The question is what exactly do you want to check?

Do you want to check if the visitor has permission editOwnPost in $nodeId? Use hasNodePermission.
Do you want to check if the visitor (by its usergroup or individual permissions) has permission editOwnPost (which might or might not be overridden by specific node permissions)? Use hasPermission.
 
Last edited:
There is a post.
There is a permission "editPost";

you can set this permission to "user group users" and/or you can set this permission to forum x -> user group users

everything I need is

class post
canEditPost = yes, if ... and it seems to me, that it is enough to ask for nodePerms.
From the logic, I would ask for both.

But I will try all cases

user group yes, no, nothing, never
forum > usergroup yes, no, nothing, never

then I will see.

I have tried the class itself, but also the test function in the acp.
 
you can set this permission to "user group users"
Yes. If you check hasPermission it will check this combined permission from all usergroups (+ individual permissions).

hasNodePermission will return the same result unless
you set this permission to forum x -> user group users
as this will override the inherited permission.

If your intent is to check if a user has permission editPost in a specific node you have to use hasNodePermission and nothing else.

From the logic, I would ask for both.
No, this makes no sense :)

Example
I am in Usergroup Registered only and I have no idivididual permissions.
Permission Edit post is set to No for usergroup Registered.

You've got a Forum Editing Allowed where you set permission Edit posts for usergroup Registered to Yes.

What do you expect now, should I be able to edit posts in this forum?

hasNodePermission would return true, hasPermission would return false.
So if you check both, eg. hasNodePermission($nodeId, 'editOwnPost') && hasPermission('forum', 'editOwnPost') the result would be false.
 
Last edited:
Back
Top Bottom