Question

I build a Widget for Socialengine 4 and build an Admin-Form to configure the Widget inside a page from the Layout - Editor. Everything works fine, except one thing - If I edit the Widget again without touching the file upload, the previously uploaded Image is gone.

Here is my manifest.php for the widget:

...
'adminForm' => array(
     'elements' => array(       
          array(
        "file",
        "image_upload",
        array(
            'label' => "Bild Upload",
            'destination' => 'upload'
        )
    ),
....

Here is my question how can I prevent this behaviour ? Is there an option inside the manifest.php ?

Thank you for your help and sorry for my bad english.

Was it helpful?

Solution

The simple answer is no your field will be update when you submit your form

The way it works is when you drag a widget if in content that widgets info has autoEdit true like this in application\modules\Core\settings\content.php

  array(
    'title' => 'Ad Campaign',
    'description' => 'Shows one of your ad banners. Requires that you have at least one active ad campaign.',
    'category' => 'Core',
    'type' => 'widget',
    'name' => 'core.ad-campaign',
   // 'special' => 1,
    'autoEdit' => true,
    'adminForm' => 'Core_Form_Admin_Widget_Ads',
  ),

than the widget form will be automatically loaded.

else when you will drag the widget with it's default value it will be saved temporarily in js and when you save layout it will save all the layout info to db.

now when you edit form it will open form in popup and will populate the form data using js(application\modules\Core\views\scripts\admin-content\widget.tpl)

      if( $type(value) == 'array' ) {
        value.each(function(svalue){
          if( $(key + '-' + svalue) ) {
            $(key + '-' + svalue).set('checked', true);
          }
        });
      } else if( $(key) ) {
        $(key).value = value;
      } else if( $(key + '-' + value) ) {
        $(key + '-' + value).set('checked', true);
      }

now you submit data it temporarily saves data to js and updates widget content to parent js file application\modules\Core\views\scripts\admin-content\widget.tpl

  <?php elseif( $this->values ): ?>

    <script type="text/javascript">
      parent.setWidgetParams(<?php echo Zend_Json::encode($this->values) ?>);
      parent.Smoothbox.close();
    </script>

  <?php else: ?>

when it gets form values it updates parent widget info

Hope this solves your issues widgets are not typically for file upload or it wasn't designed for that. I suggest you study application\modules\Core\controllers\AdminContentController.php this controller and application\modules\Core\views\scripts\admin-content\widget.tpl file than you will be more clear on this issue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top