Version: current

     1 <?php
     2 // Виджет заказа обратного звонка - показываем выбранную UserDefinedForm
     3 class FeedbackHomepageWidget extends HomepageWidget {
     4     static $db = array(
     5         'Text' => 'HTMLText',
     6     );
     7
     8     static $has_one = array(
     9         'Holder' => 'UserDefinedForm',
    10     );
    11
    12     public $needObjects = array(
    13         'UserDefinedForm' => 'Page'
    14     );
    15
    16     function getCMSFields() {
    17         if (!$this->canCreate()) {
    18             return $this->getFailCMSFields();
    19         }
    20
    21         $fields = parent::getCMSFields();
    22         $holders = DataObject::get('UserDefinedForm');
    23         if ($holders) {
    24             $holders = $holders->map();
    25         } else {
    26             $holders = array();
    27         }
    28         $fields->addFieldToTab('Root.Main', new DropdownField("HolderID", $this->fieldLabel('Holder'), $holders));
    29         return $fields;
    30     }
    31
    32     function WidgetForm() {
    33         if ($this->HolderID && ($form = $this->Holder())) {
    34             $controller = new UserDefinedForm_Controller($form);
    35             $controller->init();
    36             $form = $controller->Form();
    37             $suffix = "w{$this->ID}";
    38             $form->loadDataFrom(array('HtmlIDSuffix' => $suffix));
    39             $form->setHtmlID("{$controller->generateFormID()}_{$suffix}");
    40             return $form;
    41         }
    42         return false;
    43     }
    44
    45     function FormWithContent() {
    46         if ($this->HolderID && ($form = $this->Holder())) {
    47             $controller = new UserDefinedForm_Controller($form);
    48             $controller->init();
    49             return new ArrayData($controller->index());
    50         }
    51         return false;
    52     }
    53 }
    54
    55

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -