Update page description from block

Permalink 1 user found helpful
Can this be achieved?

I know how to update an attribute.

eg $page->setAttribute('my_attribute', $args['field_2_textbox_text']);
But what about the page description?

I know how to show it. eg
$description = $c->getCollectionDescription();

is there an equivalent setDescription() or setCollectionDescription() available to use? If so how would this be implemented in a block?

 
nebuleu replied on at Permalink Best Answer Reply
nebuleu
Page description can be modified with the $page->update($data) function. More details here :
http://www.concrete5.org/documentation/developers/pages/overview...

The description can be updated if you add $data['cDescription'] to the $data array.
https://github.com/concrete5/concrete5/blob/master/web/concrete/core...

The implementation could be done for example by calling this update function in the save() function of the block controller.
michaelDotco replied on at Permalink Reply
thanks for this,

so what would be wrong with this then? It doesn't seem to be updating.

public function save($args) {
$page = Page::getCurrentPage();
$description = $page->getCollectionDescription();
if ($description == '')
{
$data = array(
'cDescription' => $args['field_2_textbox_text']
);

$page->update($data) ;
}
}
michaelDotco replied on at Permalink Reply
Sorry it works,
but it seemed a bit hit and miss - maybe something to do with description variable.