Build widget for Diem Project
File: config/dm/widget_types.yml
dmWidgetMyGroupWidgetName:
abcxyz:
name: "My Widget Name"
form_class: huypvMWNForm
view_class: huypvMWNView
#zzzbla:
#name: "My Second Widget Name"
#form_class: huypvMSWNForm
#view_class: huypvMSWNView
File: lib/huypvMWNForm.php
class huypvMWNForm extends dmWidgetPluginForm {
public function configure() {
parent::configure();
$this->widgetSchema['yourname'] = new sfWidgetFormInput(
array('default' => 'Your name',
'label' => 'Enter your name'));
$options = array('required' => true);
$messages = array('required' => 'Name is required');
$this->validatorSchema['yourname'] = new sfValidatorString($options, $messages);
}
public function renderContent($attributes) {
return $this->getHelper()->renderPartial('dmWidget', 'forms/huypvMWNForm', array(
'form' => $this,
'baseTabId' => 'huypvMWN_' . $this->dmWidget->get('id')
));
}
}
File: lib/huypvMWNView.php
class huypvMWNView extends dmWidgetPluginView {
public function doRender() {
$vars = $this->getViewVars();
$yourName = isset($vars['yourname']) ? $vars['yourname'] : 'anonymous';
return 'Hi, ' . $yourName;
}
}
File: front/modules/dmWidget/templates/forms/huypvMWNForm.php
echo $form->renderGlobalErrors();
echo
_open('div.dm_tabbed_form'),
_tag('div#' . $baseTabId . '_base.drop_zone',
_tag('ul.dm_form_elements',
$form['cssClass']->renderRow() .
$form['yourname']->renderRow() .
'<li><br />
</li>'
)
),
_close('div');