Source of file FormSection.php

Size: 1,731 Bytes - Last Modified: 2021-12-24T06:43:00+00:00

/var/www/docs.ssmods.com/process/src/code/sections/FormSection.php

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
<?php
/**
 *
 *
 * @package silverstripe
 * @subpackage sections
 */
class FormSection extends Section
{
    private static $title = "Page userform";

    private static $description = "Displays userform from a specified page";

    private static $limit = 1;

    /**
     * Database fields
     * @var array
     */
    private static $db = array();

    /**
     * Has_one relationship
     * @var array
     */
    private static $has_one = array(
        'FormPage' => 'UserDefinedForm'
    );

    /**
     * CMS Fields
     * @return FieldList
     */
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->addFieldsToTab(
            "Root.Main",
            array(
                DropdownField::create(
                    'FormPageID',
                    'Select a page',
                    UserDefinedForm::get()->map('ID', 'Title')
                )
            )
        );

        $this->extend('updateCMSFields', $fields);

        return $fields;
    }

    public function ReferencedPage(){
        if ($this->FormPage()) {
            $result = new UserDefinedForm_Controller($this->FormPage());
            $result->init();
            return $result;
        }
    }

    public function Title()
    {
        if ($this->ReferencedPage()) {
            return $this->ReferencedPage()->Title;
        }
        return false;
    }

    public function Content()
    {
        if ($this->ReferencedPage()) {
            return $this->ReferencedPage()->Content;
        }
        return false;
    }

    public function Form()
    {
        if ($this->ReferencedPage()) {
            return $this->ReferencedPage()->Form();
        }
        return false;
    }
}