Answers.Body: <p>I did the trick so here is the code if it can help someone else</p>
  
  <pre><code>craft()-&gt;on('users.onBeforeSaveUser', function(Event $event) {
  
     $matrixData = array();
     $matrix     = $event-&gt;params['user']-&gt;getContent()-&gt;children;
  
     foreach ($matrix as $block){
  
        $block-&gt;getContent()-&gt;childrenDateOfBirth = '2000-10-10';
        $matrixData[$block-&gt;id] = $block;                                     
  
     }
  
     $event-&gt;params['user']-&gt;getContent()-&gt;children = $matrixData;
  
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-21T10:58:09.057Z
Answers.LastActivityDate: 2015-10-21T10:58:09.057Z
Answers.UserDisplayName: Alex
Body: <p>I have a matrix block attached to my user, the block handler is children and has one field dob date filed something like this: </p>
  
  <pre><code>fields[children][420][fields][childrenDateOfBirth][date]
  </code></pre>
  
  <p>The problem is that I would like to update the date right before the user is saved. So I have an envent listener in my plugin</p>
  
  <pre><code>craft()-&gt;on('users.onBeforeSaveUser', function(Event $event) {
  
      $matrixData = array();
      $matrix     = $event-&gt;params['user']-&gt;getContent()-&gt;children;
  
        foreach ($matrix as $block){
  
          $blockData = array(
                              'type' =&gt; $block-&gt;getType()-&gt;handle,
                              'enabled' =&gt; $block-&gt;enabled
                             );   
  
           $blockData['fields'] = array(
                             'childrenDateOfBirth' =&gt; array('date'=&gt;'2000-10-10')
                          );
  
            $matrixData[$block-&gt;id] = $blockData;                                     
  
    }
  
   $event-&gt;params['user']-&gt;getContent()-&gt;children = $matrixData;
  
  }
    ...............
  </code></pre>
  
  <p>And I get this error : <code>Fatal error&lt;/b&gt;:  Call to a member function getType() on array</code> Is there a way to do this?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-20T19:13:28.080Z
Comments.Text: If you `var_dump($block);die()`; what is it? Is `children` the name of the Matrix field or is that the name of a Matrix block type?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-21T09:40:23.093Z
Comments.Text: Thank you Brad for your support, If I understood right, you wanted me to dump
  `foreach ($matrix as $block){
      var_dump($block);die();`
  so the $block seems to be `object(Craft\MatrixBlockModel)` I was following this example: https://gist.github.com/brandonkelly/8149062 My guess is in that $matrixData is an array, but `$event->params['user']->getContent()->children` expects some kind of object with `getType()` method, but I'm not sure :)
Comments.UserDisplayName: Alex
Tags: <plugin-development><matrix><craft-pro><updates>
Title: Update matrix onBeforeSaveUser
ThreadText: # Update matrix onBeforeSaveUser
  
  (Asked by: username_0 on 2015-10-20)
  
  I have a matrix block attached to my user, the block handler is children and has one field dob date filed something like this:
  
  ```
  fields[children][420][fields][childrenDateOfBirth][date]
  
  ```
  
  The problem is that I would like to update the date right before the user is saved. So I have an envent listener in my plugin
  
  ```
  craft()->on('users.onBeforeSaveUser', function(Event $event) {
  
      $matrixData = array();
      $matrix     = $event->params['user']->getContent()->children;
  
        foreach ($matrix as $block){
  
          $blockData = array(
                              'type' => $block->getType()->handle,
                              'enabled' => $block->enabled
                             );   
  
           $blockData['fields'] = array(
                             'childrenDateOfBirth' => array('date'=>'2000-10-10')
                          );
  
            $matrixData[$block->id] = $blockData;                                     
  
    }
  
   $event->params['user']->getContent()->children = $matrixData;
  
  }
    ...............
  
  ```
  
  And I get this error : `Fatal error</b>: Call to a member function getType() on array` Is there a way to do this?
  
  **Tags:** plugin-development, matrix, craft-pro, updates
  
  > **Comments:**
  > **username_1**: If you `var_dump($block);die()`; what is it? Is `children` the name of the Matrix field or is that the name of a Matrix block type?  
  > **username_0**: Thank you username_1 for your support, If I understood right, you wanted me to dump `foreach ($matrix as $block){     var_dump($block);die();` so the $block seems to be `object(Craft\MatrixBlockModel)` I was following this example: https://gist.github.com/brandonkelly/8149062 My guess is in that $matrixData is an array, but `$event->params['user']->getContent()->children` expects some kind of object with `getType()` method, but I'm not sure :)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-10-21. Score: 1 | Accepted answer
  
  I did the trick so here is the code if it can help someone else
  
  ```
  craft()->on('users.onBeforeSaveUser', function(Event $event) {
  
     $matrixData = array();
     $matrix     = $event->params['user']->getContent()->children;
  
     foreach ($matrix as $block){
  
        $block->getContent()->childrenDateOfBirth = '2000-10-10';
        $matrixData[$block->id] = $block;                                     
  
     }
  
     $event->params['user']->getContent()->children = $matrixData;
  
  }
  
  ```
  
  
  ---
  
  