View file upload/src/addons/AddonsLab/Core/Xf2/Admin/Form.php

File size: 3.17Kb
<?php
/** 
This software is furnished under a license and may be used and copied
only  in  accordance  with  the  terms  of such  license and with the
inclusion of the above copyright notice.  This software  or any other
copies thereof may not be provided or otherwise made available to any
other person.  No title to and  ownership of the  software is  hereby
transferred.                                                         
                                                                     
You may not reverse  engineer, decompile, defeat  license  encryption
mechanisms, or  disassemble this software product or software product
license.  AddonsLab may terminate this license if you don't comply with
any of these terms and conditions.  In such event,  licensee  agrees 
to return licensor  or destroy  all copies of software  upon termination 
of the license.
*/


namespace AddonsLab\Core\Xf2\Admin;

use AddonsLab\Core\Xf2\Admin\Field\AbstractRow;

class Form
{
    /**
     * @var EntityConfig
     */
    protected $config;
    /**
     * @var AbstractRow[]
     */
    protected $fields = array();

    /**
     * @var string The prefix to use for auto-generated field templates
     */
    protected $template_prefix = 'row';

    /**
     * @var string The name to use for $item which should provide the value and other fields of the option
     */
    protected $item_name = 'item';

    protected $name_prefix = ''; // if empty, entity/relation name is used

    /**
     * Form constructor.
     * @param EntityConfig $config
     */
    public function __construct(EntityConfig $config)
    {
        $this->config = $config;
    }

    public function addField(AbstractRow $field)
    {
        $field->setForm($this);
        $this->fields[$field->getId()] = $field;

        return $this;
    }

    public function addFields(array $fields)
    {
        foreach ($fields AS $field)
        {
            $this->addField($field);
        }

        return $this;
    }


    public function getFields()
    {
        return $this->fields;
    }

    public function getFormatParams($fieldId, $paramName)
    {
        return $this->fields[$fieldId]->getFormatParam($paramName);
    }

    /**
     * @return string
     */
    public function getTemplatePrefix()
    {
        return $this->template_prefix;
    }

    /**
     * @param string $template_prefix
     */
    public function setTemplatePrefix($template_prefix)
    {
        $this->template_prefix = $template_prefix;
        return $this;
    }

    /**
     * @return string
     */
    public function getItemVariableName()
    {
        return $this->item_name;
    }

    /**
     * @param string $item_name
     * @return Form
     */
    public function setItemName($item_name)
    {
        $this->item_name = $item_name;
        return $this;
    }

    /**
     * @return EntityConfig
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * @return string
     */
    public function getNamePrefix()
    {
        return $this->name_prefix;
    }

    /**
     * @param string $name_prefix
     */
    public function setNamePrefix($name_prefix)
    {
        $this->name_prefix = $name_prefix;
    }

}