XF 2.3 Adding Entity Items to a Category

mjda

Well-known member
This might not be the correct forum for this. If it's not, please move it.

Anyways, I'm wanting to add a new database row to a RM category. I know how to do most of it. I have the field in the form, and the row is added to the database, and it's added to the entity. However, I'm wondering what's the proper way to get that to save when I submit the form? I could just overwrite the categorySaveProcess to add my row here:

PHP:
protected function categorySaveProcess(\XFRM\Entity\Category $category)
    {
        $entityInput = $this->filter([
            'title' => 'str',
            'description' => 'str',
            'parent_category_id' => 'uint',
            'display_order' => 'uint',
            'allow_local' => 'bool',
            'allow_external' => 'bool',
            'allow_commercial_external' => 'bool',
            'allow_fileless' => 'bool',
            'enable_versioning' => 'bool',
            'enable_support_url' => 'bool',
            'always_moderate_create' => 'bool',
            'always_moderate_update' => 'bool',
            'min_tags' => 'uint',
            'thread_node_id' => 'uint',
            'thread_prefix_id' => 'uint',
            'require_prefix' => 'bool',
            'auto_feature' => 'bool',
        ]);

However, I'm thinking there has to be a better way to do it, right?
 
No, that would be the function to use.
Do not overwrite it completely though, you can overload it.

It returns a form element where you can add data to, let's say you have your new fields in an inputData var, you could use the following code bit

PHP:
protected function categorySaveProcess(\XFRM\Entity\Category $category)
{
    $form = parent::categorySaveProcess($category);
    $inputData = $this->filter([
    ...
    ]);

    $form->setup(function() use ($category, $inputData)
    {
        $category->bulkSet($inputData);
    });
}
 
Back
Top Bottom