XF 2.2 Argument #1 error... help?

DreamNetworks

Active member
Hi All,

I'm trying to add a code event listener to an option.

But now I'm getting the following error:
PHP:
ErrorException: [E_WARNING]...Listener::resourceItemEntityStructure(): Argument #1 ($xfrmop) must be of type XF\Mvc\Entity\Structure, int given, called in /src/XF/Entity/Option.php on line 208 in [B]Listener.php[/B] at line [B]9[/B]

This is my Listener.php

PHP:
use \XF\Mvc\Entity\Structure;

class Listener
{
   public static function resourceItemEntityStructure(\XF\Mvc\Entity\Structure &$xfrmop)
{
    unset($xfrmop->columns['tag_line']['required']);

}
}

I have tried to find a solution and googling, but I don't get any smarter from it. Someone willing to help me in this one?
 
Last edited:

Jeremy P

XenForo developer
Staff member
It looks like you're passing an event listener to the validation callback setting for an option?

Set up code events in: Control panel > Development > Code event listener

For your code event, use the entity_structure event, presumably with XFRM\Entity\ResourceItem as a the event hint.
 

Jeremy P

XenForo developer
Staff member
To be clear, you are creating a code event (and aren't using the validation callback for an option -- which is a different mechanism entirely)? Can you post the full stack trace?
 

DreamNetworks

Active member
To be clear, you are creating a code event (and aren't using the validation callback for an option -- which is a different mechanism entirely)? Can you post the full stack trace?
Hmm, im a starting developer so doesnt have that much knowledge.

PHP:
[HEADING=2]Stack trace[/HEADING]
#0 src/XF/Extension.php(52): XFF\XFRMOptions\Listener::entityStructureResourceItem(Object(XF\Mvc\Entity\Manager), Object(XF\Mvc\Entity\Structure))
#1 src/XF/Mvc/Entity/Manager.php(78): XF\Extension->fire('entity_structur...', Array, 'XFRM\\Entity\\Res...')
#2 src/XF/Mvc/Entity/Manager.php(225): XF\Mvc\Entity\Manager->getEntityStructure('XFRM:ResourceIt...')
#3 src/XF/App.php(2751): XF\Mvc\Entity\Manager->getFinder('XFRM:ResourceIt...')
#4 src/addons/XFRM/Sitemap/ResourceItem.php(16): XF\App->finder('XFRM:ResourceIt...')
#5 src/XF/Sitemap/Builder.php(171): XFRM\Sitemap\ResourceItem->getRecords(0)
#6 src/XF/Sitemap/Builder.php(149): XF\Sitemap\Builder->writeContentTypeData('resource', 0, 7.57544)
#7 src/XF/Sitemap/Builder.php(84): XF\Sitemap\Builder->buildType('resource', 7.57544)
#8 src/XF/Job/Sitemap.php(27): XF\Sitemap\Builder->build(7.57544)
#9 src/XF/Job/Manager.php(260): XF\Job\Sitemap->run(7.57544)
#10 src/XF/Job/Manager.php(202): XF\Job\Manager->runJobInternal(Array, 7.57544)
#11 src/XF/Job/Manager.php(86): XF\Job\Manager->runJobEntry(Array, 7.57544)
#12 job.php(43): XF\Job\Manager->runQueue(false, 8)
#13 {main}
 

Jeremy P

XenForo developer
Staff member
That stack trace seems to correspond to a different error than the one you originally posted.

In any case, your listener should be:
PHP:
<?php

namespace XFF\XFRMOptions;

class Listener
{
   public static function resourceItemEntityStructure(
        \XF\Mvc\Entity\Manager $em, 
        \XF\Mvc\Entity\Structure &$structure
    ): void
    {
        unset($structure->columns['tag_line']['required']);
    }
}
 

DreamNetworks

Active member
I have made an option, and added the callback. But receive this error, can you please explain what I do wrong?

PHP:
[B]ErrorException[/B]: [E_WARNING] XFF\XFRMOptions\Listener::resourceItemEntityStructure(): Argument #2 ($structure) must be passed by reference, value given in [B]src/XF/Entity/Option.php[/B] at line [B]208[/B]
[LIST=1]
[*][B]XF::handlePhpError()[/B] in [B]src/XF/Entity/Option.php[/B] at line [B]208[/B]
[*][B]XF\Entity\Option->verifyOptionValue()[/B] in [B]src/XF/Mvc/Entity/Entity.php[/B] at line [B]789[/B]
[*][B]XF\Mvc\Entity\Entity->_verifyValueCustom()[/B] in [B]src/XF/Mvc/Entity/Entity.php[/B] at line [B]634[/B]
[*][B]XF\Mvc\Entity\Entity->set()[/B] in [B]src/XF/Mvc/Entity/Entity.php[/B] at line [B]569[/B]
[*][B]XF\Mvc\Entity\Entity->__set()[/B] in [B]src/XF/Repository/Option.php[/B] at line [B]113[/B]
[*][B]XF\Repository\Option->updateOptions()[/B] in [B]src/XF/Admin/Controller/Option.php[/B] at line [B]84[/B]
[*][B]XF\Admin\Controller\Option->actionUpdate()[/B] in [B]src/XF/Mvc/Dispatcher.php[/B] at line [B]352[/B]
[*][B]XF\Mvc\Dispatcher->dispatchClass()[/B] in [B]src/XF/Mvc/Dispatcher.php[/B] at line [B]259[/B]
[*][B]XF\Mvc\Dispatcher->dispatchFromMatch()[/B] in [B]src/XF/Mvc/Dispatcher.php[/B] at line [B]115[/B]
[*][B]XF\Mvc\Dispatcher->dispatchLoop()[/B] in [B]src/XF/Mvc/Dispatcher.php[/B] at line [B]57[/B]
[*][B]XF\Mvc\Dispatcher->run()[/B] in [B]src/XF/App.php[/B] at line [B]2345[/B]
[*][B]XF\App->run()[/B] in [B]src/XF.php[/B] at line [B]512[/B]
[*][B]XF::runApp()[/B] in [B]admin.php[/B] at line [B]13
[/B]
[/LIST]
 

Jeremy P

XenForo developer
Staff member
What is your purpose for making an option? You only need to add a code event listener. Using a code event listener in an option validation callback will not work.
 

DreamNetworks

Active member
What is your purpose for making an option? You only need to add a code event listener. Using a code event listener in an option validation callback will not work.
I want the option, so they can decide wether the tagline need to be disabled or not. As well i'm implementing this to an already existing addon from me with other already containing options.
 

Jeremy P

XenForo developer
Staff member
You'll need to reference the option in the listener itself then, rather than using it as a validation callback. Validation callbacks are used for determining whether a given option is valid or not, nothing else. You won't need to use validation callbacks at all for most simple options.


PHP:
<?php

namespace XFF\XFRMOptions;

class Listener
{
    public static function resourceItemEntityStructure(
        \XF\Mvc\Entity\Manager $em,
        \XF\Mvc\Entity\Structure &$structure
    ): void {
        if (\XF::options()->yourOptionId) {
            unset($structure->columns['tag_line']['required']);
        }
    }
}
 
Last edited:

DreamNetworks

Active member
Thanks for your help :)

Now I receive this error:
  • ErrorException: [E_WARNING] Undefined array key "conditions"
  • src/XF/Mvc/Entity/Entity.php:912
Code:
[HEADING=2]Stack trace[/HEADING]
#0 src/XF/Mvc/Entity/Entity.php(912): XF::handlePhpError(2, '[E_WARNING] Und...', '/var/www/vhosts...', 912)
#1 src/XF/Mvc/Entity/Entity.php(867): XF\Mvc\Entity\Entity->_invalidateCachesOnChange('resource_catego...')
#2 src/XF/Mvc/Entity/Entity.php(671): XF\Mvc\Entity\Entity->_setInternal('resource_catego...', 1)
#3 src/XF/Mvc/Entity/Entity.php(569): XF\Mvc\Entity\Entity->set('resource_catego...', 1)
#4 src/addons/XFRM/Entity/Category.php(287): XF\Mvc\Entity\Entity->__set('resource_catego...', 1)
#5 src/addons/XFRM/Pub/Controller/Category.php(318): XFRM\Entity\Category->getNewResource()
#6 src/XF/Mvc/Dispatcher.php(352): XFRM\Pub\Controller\Category->actionAdd(Object(XF\Mvc\ParameterBag))
#7 src/XF/Mvc/Dispatcher.php(259): XF\Mvc\Dispatcher->dispatchClass('XFRM:Category', 'Add', Object(XF\Mvc\RouteMatch), Object(XFRM\Pub\Controller\Category), NULL)
#8 src/XF/Mvc/Dispatcher.php(115): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XFRM\Pub\Controller\Category), NULL)
#9 src/XF/Mvc/Dispatcher.php(57): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#10 src/XF/App.php(2345): XF\Mvc\Dispatcher->run()
#11 src/XF.php(512): XF\App->run()
#12 index.php(20): XF::runApp('XF\\Pub\\App')
#13 {main}
 

Jeremy P

XenForo developer
Staff member
That wouldn't be related to the above code event alone unless you've added or modified it. It looks like your XFRM\Entity\ReourceItem is missing the conditions for a relation. Are you unsetting other values in your code event (or elsewhere in your add-on)?
 

DreamNetworks

Active member
I have found the issue, some wrong coding from me in another ResourceItem.php, so that has been fixed now thanks!

The only problem now is, that it doesn't matter if the box is checked or unchecked but the validation is on both options not needed, how is that possible? xD

In the meanwhile I also found the solution.. the Option ID doesn't allow to have _ in the listener :)
 
Last edited:
Top