TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3562352. --> Reported by: [harivansh](https://www.drupal.org/user/3678656) Related to !64 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>When AI agents use the entity_load_by_property tool to retrieve entities, the tool returns an array of entities rather than a single entity object. However, the ToolPluginBase class in the tool_ai_connector module attempts to call method_exists() on the output without first checking if it's an object, causing a TypeError when the output is an array.<br> if (method_exists($entity, 'language')) {</p> <pre>TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, array given</pre><h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>Create an AI agent that uses the entity_load_by_property tool or use the tool directly using the explorer </p> <p>Configure the agent to load taxonomy terms by property (e.g., name)</p> <p>Execute the agent workflow</p> <p>Observe the TypeError when the tool attempts to process the array output</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Add validation in ToolPluginBase::getReadableOutput() to check if the entity output is an object before calling method_exists(). If the output is not an object (e.g., an array as returned by entity_load_by_property), skip artifact creation for that output.</p> <p>The fix involves adding an is_object() check before line 165 and using the existing continue statement to skip non-object outputs.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <h3 id="summary-ui-changes">User interface changes</h3> <h3 id="summary-api-changes">API changes</h3> <h3 id="summary-data-model-changes">Data model changes</h3>
issue