1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Duplicate 2.0 Handling Input & DataWriters - Development Request

Discussion in 'Closed Suggestions' started by Daniel Hood, Jun 9, 2015.

  1. Daniel Hood

    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 :)
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    This is actually a duplicate if I have read correctly...
     
  3. Chris D

    Chris D XenForo Developer Staff Member

  4. Chris D

    Chris D XenForo Developer Staff Member

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

    Daniel Hood Well-Known Member

    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? ;)

    True. It made my point though ;)
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    It's all noted :)
     

Share This Page