Datawriter: 'Gets the actual existing.....' - What does it actually mean?

TheBigK

Well-known member
So far, I've been blindly following the DataWriter creation for my simpler addons; but have decided to figure out what's really happening behind the scenes. I see this explanation (comment)
Code:
/*** Gets the actual existing data out of data that was passed in. See parent for explanation.** @param mixed** @return array|false*/protected function _getExistingData($data)
{
if (!$id = $this->_getExistingPrimaryKey($data, 'note_id'))
{
return false;}

return array('scratchpad_note' => $this->getModelFromCache('Scratchpad_Model_Note')->getNoteById($id));}

The words "gets the actual existing data out of data that was passed in" confuse me.

1. Where is this $data coming from? What does it contain when being passed on to the function?
2. Why is it mandatory to define this function in any data writer?
 
The callee may use something like this

PHP:
$dw = XenForo_DataWriter::create('Something');
$dw->setExistingData($data);

That is the $data that is being used in the quoted lines. It can be an array or an ID. The method "_getExistingPrimaryKey" will extract "note_id" if $data is an array and has that key. Or it will just return $data if it is a number itself.
 
Back
Top Bottom