Have a rule component that uses the 'Set data value' for a text field in a node that has a chatroom field. Get this error when I try to run the rule.
Fatal error: Cannot use object of type Chatroom as array in /home/edelib/public_html/sites/all/modules/chatroom/chatroom.module on line 226
works fine if I delete the chatroom field from the node.
Thanks

Comments

Anonymous’s picture

can you post more information for me to reproduce?

i'm unfamiliar with rules.

blackclover’s picture

Sure. Thanks appreciate the quick response.
1. add a chatroom field to a content type.
2. Create a VBO (views bulk operations module) view page that includes that content type / node.
3. Navigate to admin/config/workflow/rules/components and + Add new component.
4. Component plugin select 'Rule' -> Continue
5. Name the component "Chatroom test"
6. Under Variables -> Data type = node, label = node, machine name = node -> Continue

Under Conditions
7. + Add Condition -> "Content is of Type" then select the content type with the chatroom field -> Save

Under Actions
8. + Add action -> "Set data value" -> Data Selector node:body (or some other text field in the node) -> Value 'type in some text' -> Save

This creates a simple component that adds the text to the field and saves the node when it's executed from a VBO view.

Navigate to admin/structure/views

Edit the VBO view page you created earlier -> Go to the Bulk Operations Content column (under fields) and select your "Chatroom Test" component from the pick list.
Apply and save the view - > should redirect you to the view page with your node and a checkbox on that row. Check the box and pick "Chatroom test" from the Operations select list -> Execute

The component should fire and the error should trigger. If you remove the chatroom field the component works.

Hope this helps.

eDeliberation’s picture

I work with blackclover - we're still stuck with this.

One question we had was why Rules is calling the module since we aren't updating the Chatroom field.

Another related question was what must be done to a module to allow it to be Rules enabled? This is related to issue http://drupal.org/node/1783218 "Make the chatroom field available in rules" Wondering if there is a connection.

Does an expert on Rules have an insight on this?

michlis’s picture

I think this issue is not specific to Rules, because I had same problem when trying to apply actions (publish/unpublish etc.) from content admin page on node with chatroom field .

I believe the problem is in chatroom_field_update() which expects $item['chatroom'] to be array.

function chatroom_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
global $user;
foreach ($items as &$item) {
$chatroom = new Chatroom($item['chatroom']['chatroom_cid']);
...
}}

This is true when you create/edit node with chatroom, but not when you modify node e.g. from content admin page (most likely Rules too). Then $item['chatroom'] is an object and not all properties names match keys from array.

This is $item['chatroom'] dump from later case, which gives error.

items: Array
(
    [0] => Array
        (
            [cid] => 14
            [chatroom] => Chatroom Object
                (
                    [changedAttributes:protected] => Array
                        (
                        )

                    [format:protected] => filtered_html
                    [allowedRids:protected] => Array
                        (
                            [1] => stdClass Object
                                (
                                    [rid] => 1
                                    [read_only] => 1
                                )

                            [2] => stdClass Object
                                (
                                    [rid] => 2
                                    [read_only] => 0
                                )

                        )

                    [allowedUids:protected] => Array
                        (
                        )
                    [archived:protected] => 0
                    [cid:protected] => 14
                    [uid:protected] => 0
                    [public:protected] => 0
                    [title:protected] =>
                    [latestMessage:protected] =>
                    [onlineUsers:protected] => Array
                        (
                        )
                )
        )
)

This is $item['chatroom'] dump when creating/editing node, works fine

items: Array
(
    [0] => Array
        (
            [chatroom] => Array
                (
                    [chatroom_title] =>
                    [chatroom_public] => 0
                    [chatroom_cid] => 14
                    [chatroom_read_only_roles] => Array
                        (
                            [1] => 1
                        )

                    [chatroom_write_roles] => Array
                        (
                            [2] => 2
                        )

                    [chatroom_archived] => 0
                    [chatroom_format] => filtered_html
                    [chatroom_moderated] => 0
                )
        )
)

I assume (at least for now) that chatroom update is needed only when you create/edit node with chatroom, so my workaround for this issue is to proceed with update only if $item['chatroom'] is array, by adding if (is_array($item['chatroom'])) right after foreach and before creating $chatroom variable.
Tested to remove the error and doesn't break node create/edit process.
However, this is definitely not a proper solution, so I hope someone with Chatroom and Field API knowledge can fix it properly.

Anonymous’s picture

Title: Fatal error: Cannot use object of type Chatroom as array when updating a node using rules. » Fatal error: Cannot use object of type Chatroom as array when updating a node via the node admin form

retitling, because i care less about rules than the core node admin screen.

Anonymous’s picture

Status: Active » Fixed

fixed with this commit:

http://drupalcode.org/project/chatroom.git/commitdiff/fe48064

not convinced i'm not doing something else wrong, but one fix at a time.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.