Is there a better way to extend this datawriter?

Nudaii

Well-known member
Howdy i am extending

with this, however not sure if there is a better way to do it, it adds one extra checkbox to the forum_edit, is this part correct/optimal

Code:
<?php

class Nudaii_ContentControl_DataWriter_CCDW extends XFCP_Nudaii_ContentControl_DataWriter_CCDW
{
    protected function _getFields()
    {
       $fields = parent::_getFields();

       $fields['xf_forum']['nudaii_do_not_index'] = array('type' => self::TYPE_UINT, 'default' => 0);

       return $fields;
    }

    protected function _preSave()
    {
        $parent = parent::_preSave();
        if (isset($GLOBALS['nudaii_do_not_index']))
        {
            $this->set('nudaii_do_not_index', $GLOBALS['nudaii_do_not_index']->getInput()->filterSingle('nudaii_do_not_index', XenForo_Input::UINT));

            }
        return $parent;
    }

}
 
Certainly it's true that there isn't really many other approaches aside from setting a value somewhere and then reading it later. This is one of the things we've improved from XF2, see the "Form actions" section here: https://xf2demo.xenforo.com/threads/whats-new-for-developers-in-xenforo-2-part-1.1297/

I am slightly curious about the specific way you're setting the value though. It seems as though you're setting the entire Controller into the GLOBALS var. I guess it works, though probably not ideal.

In your controller, I would recommend just setting the 'nudaii_do_not_index' key of GLOBALS to be simply the value you want to set in the DW, e.g.

PHP:
$GLOBALS['nudaii_do_not_index'] = $this->_input->filterSingle('nudaii_do_not_index', XenForo_Input::UINT);

And then in your DW simply:

PHP:
$this->set('nudaii_do_not_index', $GLOBALS['nudaii_do_not_index']);
 
thanks for the help, its my first time relaly working with a DW, as for the controller i hadnt got to that part yet, was doing temp core edits for eveyrthing else on a throw away dev site before porting changes to the proper format/addon

will use your suggested methods for controller!
 
Top Bottom