Duplicate 2.0 Handling Input & DataWriters - Development Request

Daniel Hood

Well-known member
Something that I'm sure all developers have struggled with is implementing additional fields on default XenForo content types. Currently, you have to extend the actionSave() function, get the content id, basically update the row twice (once for the core and once for the add-on field). I think it'd be nice to plan for most controllers that are saving forms to be extended. I think the two following implementations could help a lot but you guys may already have this worked out another way.

My ideas are:

Changing lines such as:

PHP:
$dwInput = $this->_input->filter(array(
            'title' => XenForo_Input::STRING,
            'prefix_id' => XenForo_Input::UINT,
            'discussion_state' => XenForo_Input::STRING,
            'discussion_open' => XenForo_Input::UINT,
            'sticky' => XenForo_Input::UINT
        ));

to:

PHP:
$dwInput = $this->filterInput(array(
            'title' => XenForo_Input::STRING,
            'prefix_id' => XenForo_Input::UINT,
            'discussion_state' => XenForo_Input::STRING,
            'discussion_open' => XenForo_Input::UINT,
            'sticky' => XenForo_Input::UINT
        ));

With a new function that can be extended, something like:

PHP:
public function filterInput($fields)
{
           return $this->_input->filter($fields);
}

This would let me do something like:

PHP:
public function filterInput($fields)
{
           $fields['prefix_id'] => XenForo_Input::XenForo_Input::ARRAY_SIMPLE;
           return parent::filterInput($fields);
}

Additionally, having a way to add last second data to the datawriter would be nice. I'm not sure the best way to go about this but I was originally thinking a function in the controller to submit the datawriter.

Example:

PHP:
protected function _submitDw(XenForo_DataWriter $dw)
{
$dw->save();
}

Changing:
PHP:
$dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
        $dw->setExistingData($threadId);
        $dw->bulkSet($dwInput);
        $dw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum);
        $dw->save();

to

PHP:
$dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
        $dw->setExistingData($threadId);
        $dw->bulkSet($dwInput);
        $dw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum);
        $this->_submitDw($dw);

I just know these things would have helped me on occasion. Who knows though, maybe you guys already have something planned to help with this problem :)
 
Upvote 0
This suggestion has been closed. Votes are no longer accepted.
Worth noting that there's actually some other workarounds there that may be worth looking at to avoid re-saving the record.
 
Woah, the double triple posting man... :p

My bad on the duplicate post. Either way, the import thing is you read it and made a note of it and are going to implement it... right? ;)

Worth noting that there's actually some other workarounds there that may be worth looking at to avoid re-saving the record.

True. It made my point though ;)
 
Top Bottom