Forums | Mahara Community

Developers /
[PHP] Creating a textbox block through code


anonymous profile picture
Account deleted
Posts: 4

15 August 2014, 0:04

Hi everyone, 

 

I've been struggling to create a  textbox block through PHP code. At first I thought something like this would be enough:

 foreach ($data as $key => $valor){

         $posts = new BlockInstance(0, array(
                   'blocktype' => 'textbox',
                   'title' => $key,
                   'row' => 1,
                   'column' => 1,
                   'order' => $i,
                   'configdata' => array(
                           'text' => $value
                           ),
                   );

         i++;

        $view->addblockinstance($posts);
 }

but as it turns out, that doesn't work, it only gives me empty blocks with titles because, apparently, I need to create a textbox artefact first. Would you be so kind to guide me through the process? I think it should be pretty simple.

Thank you in advance.

Tobias Zeuch's profile picture
Posts: 111

19 August 2014, 18:29

Hi Daniel,

have a look at artefact/internal/blocktype/textbox/db/upgrade.php

Before that upgrade, text boxes were just block types but then, note-artefacts were introduced, so for each text box, the note artefact was created in the update script. Besides the artefact and the block-element, you should also create an entry in view_artefact. 

Tobias

2 results