Getting

TypeError: Argument 1 passed to Drupal\rules\Plugin\Condition\NodeIsOfType::doEvaluate() must implement interface Drupal\node\NodeInterface, string given in Drupal\rules\Plugin\Condition\NodeIsOfType->doEvaluate() (line 40 of modules/contrib/rules/src/Plugin/Condition/NodeIsOfType.php when i update content on my site.

I created a condition as 'node is of type' , attaching my condition page and rules page here. wondering if i am defining something wrongly? either ways i shudnt be seeing a php error like this when i update content on my site.

Comments

sukanya.ramakrishnan created an issue. See original summary.

sukanya.ramakrishnan’s picture

StatusFileSize
new137.42 KB
gnaman’s picture

Hi,

I have the same problem.

I done throubleshooting and I detected that args passed are:

array(2) {
["node"]=> string(4) "node"
["types"]=> array(1) { [0]=> string(7) "article" }
}

I believe that node param is bad, because the funtion is awaiting any structure of type $node. Of this reason when the function tries to execute $node->getType() drupal dies.

could you help us?

Thanks

juliencarnot’s picture

Reproduced with 8.x-3.0-alpha2. Haven't found a clear explanation of the data selection UI (or a description of what should work in this alpha version) so I could very well be trying something wrong, but it seems I'm not the only one...

ktch_my’s picture

Getting the same error, more info below:

Version: 8.x-3.0-alpha2
Event : After saving new content
Condition : WITH or WITHOUT node of type (to make sure node type is the culprit, but error occur anyway)
Action : Send email

intrafusion’s picture

I was having the same problem, but found that if you switch to Entity is of bundle, you have an option to select both the entity type and bundle, in the OP's instance they would enter:

ENTITY: node
TYPE: node
BUNDLE: idea

kniekel’s picture

Thank you @intrafusion. I tried that, but I still get the error "The website encountered an unexpected error. Please try again later." - which is of course not very helpful

kniekel’s picture

Or in case this helps:
TypeError: Argument 1 passed to Drupal\rules\Plugin\Condition\EntityIsOfBundle::doEvaluate() must implement interface Drupal\Core\Entity\EntityInterface, string given in Drupal\rules\Plugin\Condition\EntityIsOfBundle->doEvaluate() (line 49 of /www/htdocs/w00ad09e/d8/modules/rules/src/Plugin/Condition/EntityIsOfBundle.php) #0 [internal function]: Drupal\rules\Plugin\Condition\EntityIsOfBundle->doEvaluate('node', 'node', 'termin') #1 /www/htdocs/w00ad09e/d8/modules/rules/src/Core/RulesConditionBase.php(69): call_user_func_array(Array, Array) #2 /www/htdocs/w00ad09e/d8/modules/rules/src/Plugin/RulesExpression/RulesCondition.php(109): Drupal\rules\Core\RulesConditionBase->evaluate() #3 /www/htdocs/w00ad09e/d8/modules/rules/src/Plugin/RulesExpression/RulesAnd.php(36): Drupal\rules\Plugin\RulesExpression\RulesCondition->executeWithState(Object(Drupal\rules\Engine\ExecutionState)) #4 /www/htdocs/w00ad09e/d8/modules/rules/src/Engine/ConditionExpressionContainer.php(73): Drupal\rules\Plugin\RulesExpression\RulesAnd->evaluate(Object(Drupal\rules\Engine\ExecutionState)) #5 /www/htdocs/w00ad09e/d8/modules/rules/src/Plugin/RulesExpression/Rule.php(90): Drupal\rules\Engine\ConditionExpressionContainer->executeWithState(Object(Drupal\rules\Engine\ExecutionState)) #6 /www/htdocs/w00ad09e/d8/modules/rules/src/Plugin/RulesExpression/ActionSet.php(31): Drupal\rules\Plugin\RulesExpression\Rule->executeWithState(Object(Drupal\rules\Engine\ExecutionState)) #7 /www/htdocs/w00ad09e/d8/modules/rules/src/EventSubscriber/GenericEventSubscriber.php(131): Drupal\rules\Plugin\RulesExpression\ActionSet->executeWithState(Object(Drupal\rules\Engine\ExecutionState)) #8 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): Drupal\rules\EventSubscriber\GenericEventSubscriber->onRulesEvent(Object(Drupal\rules\Event\EntityEvent), 'rules_entity_in...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #9 /www/htdocs/w00ad09e/d8/modules/rules/rules.module(124): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('rules_entity_in...', Object(Drupal\rules\Event\EntityEvent)) #10 [internal function]: rules_entity_insert(Object(Drupal\node\Entity\Node)) #11 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Extension/ModuleHandler.php(402): call_user_func_array('rules_entity_in...', Array) #12 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Entity/EntityStorageBase.php(169): Drupal\Core\Extension\ModuleHandler->invokeAll('entity_insert', Array) #13 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(418): Drupal\Core\Entity\EntityStorageBase->invokeHook('insert', Object(Drupal\node\Entity\Node)) #14 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Entity/EntityStorageBase.php(470): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('insert', Object(Drupal\node\Entity\Node)) #15 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(304): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\node\Entity\Node), false) #16 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Entity/EntityStorageBase.php(395): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\node\Entity\Node), false) #17 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(761): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\node\Entity\Node)) #18 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Entity/Entity.php(364): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\node\Entity\Node)) #19 /www/htdocs/w00ad09e/d8/core/modules/node/src/NodeForm.php(356): Drupal\Core\Entity\Entity->save() #20 [internal function]: Drupal\node\NodeForm->save(Array, Object(Drupal\Core\Form\FormState)) #21 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array(Array, Array) #22 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #23 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Form/FormBuilder.php(585): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #24 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Form/FormBuilder.php(314): Drupal\Core\Form\FormBuilder->processForm('node_termin_for...', Array, Object(Drupal\Core\Form\FormState)) #25 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm('node_termin_for...', Object(Drupal\Core\Form\FormState)) #26 /www/htdocs/w00ad09e/d8/core/modules/node/src/Controller/NodeController.php(113): Drupal\Core\Entity\EntityFormBuilder->getForm(Object(Drupal\node\Entity\Node)) #27 [internal function]: Drupal\node\Controller\NodeController->add(Object(Drupal\node\Entity\NodeType)) #28 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #29 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/Render/Renderer.php(574): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #30 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #31 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #32 [internal function]: Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #33 /www/htdocs/w00ad09e/d8/vendor/symfony/http-kernel/HttpKernel.php(139): call_user_func_array(Object(Closure), Array) #34 /www/htdocs/w00ad09e/d8/vendor/symfony/http-kernel/HttpKernel.php(62): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #35 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #36 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #37 /www/htdocs/w00ad09e/d8/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #38 /www/htdocs/w00ad09e/d8/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #39 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #40 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #41 /www/htdocs/w00ad09e/d8/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #42 /www/htdocs/w00ad09e/d8/core/lib/Drupal/Core/DrupalKernel.php(652): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #43 /www/htdocs/w00ad09e/d8/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #44 {main}.

rjjakes’s picture

This may be related to https://www.drupal.org/node/2824360 depending on the errors you're getting.

kniekel’s picture

Thank you very much rjjakes. The error has gone with that patch. But it seems I can't get a reaction rule on "after saving new content" to do anything at all ...

Should we mark this thread as a duplicate of https://www.drupal.org/node/2824360 or are they still different?

rjjakes’s picture

I"d suggest we do the work on that other thread. So if you can mark this one duplicate and add your comment on the other one, I can work on the patch there.

hkirsman’s picture

The patch from https://www.drupal.org/node/2824360 didn't help for me.

hkirsman’s picture

Same problem with "Condition: Entity is of bundle". Tried both alpha2 and dev.

shabana.navas’s picture

StatusFileSize
new149.12 KB

Not sure if this is related but the condition 'Entity is of bundle' seems to not trigger at all. I've got a rule that triggers on node creation and sends an email. The only condition I have is the entity is of bundle one with the following params:

Entity: node
Type: node
Bundle: page

The condition never seems to trigger and the email is being sent out just fine. I put in debug statements in Rules\src\Plugin\Condition\EntityIsOfBundle.php in the doEvaluation() function but nothing is printed and the function is not even triggered it seems.

johnreytanquinco’s picture

Any update for this? Is sad that rules doesnt seem to be working properly even with simple configuration. Created my own thread. https://www.drupal.org/project/rules/issues/2929588

magick93’s picture

Also having same problem

nkoporec’s picture

Having the same problem here, running Drupal 8.5 and latest dev branch of rules.

nkoporec’s picture

Version: 8.x-3.x-dev » 8.x-1.x-dev
guillaumeduveau’s picture

Version: 8.x-1.x-dev » 8.x-3.x-dev

@nkoporec It makes no sense changing the branch of this issue to 8.x-1.x...

baikho’s picture

Status: Active » Needs review
StatusFileSize
new782 bytes

I'm also getting this error on Drupal 8.5.3 with the latest from Rules 3.x-dev unless I use the data selection mode. The working setup for Condition: Node is of type:

* NODE - Data selector: node (with data selection mode)
* CONTENT TYPES - Value: article (with direct input mode)

works for both node events with above mentioned versions of Drupal & Rules (& after cache clear):

* After saving new content (rules_entity_insert:node)
* After updating content (rules_entity_update:node)

Not sure but I think we need to allow the condition plugins to fail gracefully when doEvaluate() is called from RulesConditionBase::evaluate()? This is regarding line 69 in Drupal\rules\Core\RulesConditionBase:

    return call_user_func_array([$this, 'doEvaluate'], $args);

See attached patch for a fix to get rid of the uncaught error.

Status: Needs review » Needs work

The last submitted patch, 20: rules-fatal-php-error-2768737-20.patch, failed testing. View results

baikho’s picture

Status: Needs work » Needs review
StatusFileSize
new5.44 KB

Test failure fixed in new patch. Updated the InvalidArgumentException test in Drupal\Tests\rules\Unit\Integration\Condition\UserHasRoleTest & added a TypeError test to the Drupal\Tests\rules\Unit\Integration\Condition\NodeIsOfTypeTest as well (the one being replicated in this issue).

fonant’s picture

I hit this, with "node" as the node selector but with direct input mode. So it was a string. Changing to data selection mode fixed the problem.

drseussofporn’s picture

@Baik_Ho and @fonant: Holy hell, I love both of you. I have been hitting my head against a brick wall with Rules for Drupal 8 since early in development. And the whole time the secret was making sure that the correct data selection mode was used (even when entering items manually). Just like that, Rules works.

tr’s picture

Category: Bug report » Support request
Priority: Major » Normal
Status: Needs review » Active
Related issues: +#2998793: Node is of Type error

To summarize, the solution to the original problem is to use the Data selector mode to enter "node" as the first parameter of the " Node is of type" condition - don't use the (default) direct input mode. This solution is mentioned in #20, #23, and #24.

This problem and the solution is explained more compactly and with no extraneous information in #2998793: Node is of Type error.

@Baik Ho: In regards to the patch from #22:

Not sure but I think we need to allow the condition plugins to fail gracefully when doEvaluate() is called from RulesConditionBase::evaluate()?

Yes, we need better error handling to deal with bad input. Your patch is a good start. I think the bad input can be mostly avoided by front-end validation, which is part of the work that remains to be done on the still-incomplete UI. (See milestone 3 in #2245015: [META] Rules 8.x Roadmap). Specifically, the direct input mode should only be available when the context parameter can accept text input, otherwise the data selector mode should be the only choice. Likewise, the data selector should only display data that is type-appropriate - it should not let you choose a string value when a NodeInterface value is required. (When upcasting is implemented, then we would also accept an integer like a nid when a NodeInterface is required, and upcasting would automatically load the appropriate Node given that nid.).

Regardless, I think your patch from #22 should be in its own issue - if you could create that new issue and re-post your patch there I'd appreciate it.

I'm leaving this current issue open for the time being so we don't lose track of your patch, but otherwise I consider this issue closed and fixed.

boby_ui’s picture

confirmed that #22 works out, thank you!! @baik ho

rodmarasi’s picture

Status: Active » Reviewed & tested by the community
tr’s picture

Status: Reviewed & tested by the community » Active

@boby_ui
@rodmarasi
Huh? Did either of you read what I wrote in #25 and in #2998793: Node is of Type error which I referenced in #25?

boby_ui’s picture

@TR somehow I used the patch and its not throwing anymore of that error....

tr’s picture

Status: Active » Closed (works as designed)