Exemple #1
0
 protected function renderItem($options, $templateData)
 {
     //if editable set to false --> not editable
     $isEditable = array_key_exists('editable', $options) && $options['editable'] !== false;
     //if name not defined or it is not safe --> not editable
     $isEditable = !empty($options['name']) && $this->data->isAttributeSafe($options['name']);
     if ($isEditable) {
         //ensure $options['editable'] is array
         if (!array_key_exists('editable', $options) || !is_array($options['editable'])) {
             $options['editable'] = array();
         }
         //take common url
         if (!array_key_exists('url', $options['editable'])) {
             $options['editable']['url'] = $this->url;
         }
         $editableOptions = CMap::mergeArray($options['editable'], array('model' => $this->data, 'attribute' => $options['name'], 'emptytext' => $this->nullDisplay === null ? Yii::t('zii', 'Not set') : strip_tags($this->nullDisplay)));
         //if value in detailview options provided, set text directly
         if (array_key_exists('value', $options) && $options['value'] !== null) {
             $editableOptions['text'] = $templateData['{value}'];
             $editableOptions['encode'] = false;
         }
         $templateData['{value}'] = $this->controller->widget('EditableField', $editableOptions, true);
     }
     parent::renderItem($options, $templateData);
 }
 protected function renderItem($options, $templateData)
 {
     //apply editable if not set 'editable' params or set and not false
     $apply = !empty($options['name']) && (!isset($options['editable']) || $options['editable'] !== false);
     if ($apply) {
         //ensure $options['editable'] is array
         if (!isset($options['editable'])) {
             $options['editable'] = array();
         }
         //merge options with defaults: url, params, etc.
         $options['editable'] = CMap::mergeArray($this->_data, $options['editable']);
         //options to be passed into EditableField (constructed from $options['editable'])
         $widgetOptions = array('model' => $this->data, 'attribute' => $options['name']);
         //if value in detailview options provided, set text directly (as value here means text)
         if (isset($options['value']) && $options['value'] !== null) {
             $widgetOptions['text'] = $templateData['{value}'];
             $widgetOptions['encode'] = false;
         }
         $widgetOptions = CMap::mergeArray($widgetOptions, $options['editable']);
         $widget = $this->controller->createWidget('EditableField', $widgetOptions);
         //'apply' maybe changed during init of widget (e.g. if related model has unsafe attribute)
         if ($widget->apply) {
             ob_start();
             $widget->run();
             $templateData['{value}'] = ob_get_clean();
         }
     }
     parent::renderItem($options, $templateData);
 }
 protected function renderItem($options, $templateData)
 {
     //apply editable if not set 'editable' params or set and not false
     $apply = !empty($options['name']) && (!isset($options['editable']) || $options['editable'] !== false);
     if ($apply) {
         //ensure $options['editable'] is array
         if (!isset($options['editable'])) {
             $options['editable'] = array();
         }
         //take common url if not defined for particular item and not related model
         if (!isset($options['editable']['url']) && strpos($options['name'], '.') === false) {
             $options['editable']['url'] = $this->url;
         }
         //take common params if not defined for particular item
         if (!isset($options['editable']['params'])) {
             $options['editable']['params'] = $this->params;
         }
         $editableOptions = CMap::mergeArray($options['editable'], array('model' => $this->data, 'attribute' => $options['name'], 'emptytext' => $this->nullDisplay === null ? Yii::t('zii', 'Not set') : strip_tags($this->nullDisplay)));
         //if value in detailview options provided, set text directly (as value means text)
         if (isset($options['value']) && $options['value'] !== null) {
             $editableOptions['text'] = $templateData['{value}'];
             $editableOptions['encode'] = false;
         }
         $widget = $this->controller->createWidget('EditableField', $editableOptions);
         //'apply' can be changed during init of widget (e.g. if related model and unsafe attribute)
         if ($widget->apply) {
             ob_start();
             $widget->run();
             $templateData['{value}'] = ob_get_clean();
         }
     }
     parent::renderItem($options, $templateData);
 }