XF 2.0 Create a custom Nodes field (How to get the new field in database?)

Hey, guys,
I have a little problem right now.....
I tried to add a new field to "nodes" in the admin interface, so that I can write something into a text box and use it as a variable for each category/forum. Screenshot-2018-4-8 Add forum Craftonia net - Admin control panel.webp

Adding a new field wasn't that hard. I simply created a macro for the new field "background" in the "node_edit_macros" template
HTML:
<xf:macro name="background" arg-node="!">
    <xf:textboxrow name="node[background]" value="{$node.background}" label="{{ phrase('node_background') }}" />
</xf:macro>
and then linked this macro in the "forum_edit" template
HTML:
<xf:macro template="node_edit_macros" name="background" arg-node="{$node}" />
. So the first step was taken. Now an error message Fehlermeldung.webp appeared, which I could fix by adding a "background" function dad.webp into the "Node.php" which is in the path /src/XF/Entity/.

Everything now looks as if it could work, but the text I enter in the field does not save itself. This is also relatively logical, since no new entry has been created in the database. After several tests, this error message appeared: daaa.webp

I think the problem seems to be that no new field was created in the database....
Can you give me a hint what I did wrong or what I have to add in order for the field to appear in the database?

Thank you!
Justus
 
Haha thanks for your answer.. seems so that you are the only one who can help me every time ^^ :)
mm yes I've created the row in xf_node table and if i add some text via the database the text get's displayed in the field in the xenforo interface... The Problem is that I can't save something in the Interface so if I wrote something in the field and hit the save button the text doesn't get saved...
 
If I remove the default => '' from my Node.php from 'background' => ['type' => self::STR, 'default' => ''] to 'background' => ['type' => self::STR]
I'm getting a error code that the default value is not defined:

Code:
XF\Db\Exception: MySQL query error [1364]: Field 'background' doesn't have a default value in src\XF\Db\AbstractStatement.php at line 212

    XF\Db\AbstractStatement->getException() in src\XF\Db\Mysqli\Statement.php at line 196
    XF\Db\Mysqli\Statement->getException() in src\XF\Db\Mysqli\Statement.php at line 77
    XF\Db\Mysqli\Statement->execute() in src\XF\Db\AbstractAdapter.php at line 79
    XF\Db\AbstractAdapter->query() in src\XF\Db\AbstractAdapter.php at line 160
    XF\Db\AbstractAdapter->insert() in src\XF\Mvc\Entity\Entity.php at line 1389
    XF\Mvc\Entity\Entity->_saveToSource() in src\XF\Mvc\Entity\Entity.php at line 1121
    XF\Mvc\Entity\Entity->save() in src\XF\Mvc\FormAction.php at line 69
    XF\Mvc\FormAction->XF\Mvc\{closure}() in src\XF\Mvc\FormAction.php at line 159
    XF\Mvc\FormAction->run() in src\XF\Admin\Controller\AbstractNode.php at line 110
    XF\Admin\Controller\AbstractNode->actionSave() in src\XF\Mvc\Dispatcher.php at line 249
    XF\Mvc\Dispatcher->dispatchClass() in src\XF\Mvc\Dispatcher.php at line 88
    XF\Mvc\Dispatcher->dispatchLoop() in src\XF\Mvc\Dispatcher.php at line 41
    XF\Mvc\Dispatcher->run() in src\XF\App.php at line 1891
    XF\App->run() in src\XF.php at line 328
    XF::runApp() in admin.php at line 13

Any other ideas?
Thanks!
 
Firstly I've tried to make it with the tutorial so create a addon but i didn't got it working, because of that I've eddited the core files like i described in #1 . Nearly everything works (Connection to the database ...) the only Problem is that I can't save it throught the xenforo interface. (So the input in the field doesn't get written into the database) But if I put something in the field via the database it works fine and gets displayed in the xenforo interface.
 
Last edited:
That seems to be the right way! Already thought about that but didn't found the function... :)
Thanks!

Can you give me a little hint what I have to add there? (Thought about something like the code in the tutorial but it didn't worked... :)
 
Top Bottom