<?php
/**
 * Configuration object for Form CK Editor Widget Provider
 *
 * @author Elze Kool <info@visualmedia.nl>
 */

namespace VisualM\FormBundle\CkWidget\Configuration;

use Symfony\Component\Validator\Constraints as Assert;

/**
 * Configuration object for Form CK Editor Widget Provider
 *
 * @author Elze Kool <info@visualmedia.nl>
 */
class FormConfiguration
{

    /**
     * Formulier referentie
     * @var string
     * @Assert\NotBlank(message = "ckeditor_widget.form.form_referentie.not_blank")
     */
    private $formReferentie;

    /**
     * Create configuration from current data
     *
     * @param string $data Data
     */
    public function __construct($data)
    {
        // Format of data is in form [form|<referentie>]
        if (preg_match('/^\[form\|(?P<slug>[^\|\]]+)\]$/', $data, $m)) {
        	$this->formReferentie = $m['slug'];
        }
    }

    /**
     * Convert current configuration to the needed Widget Data
     * 
     * @return string
     */
    public function getData()
    {
        return sprintf('[form|%s]', $this->formReferentie);
    }


    /**
     * Get Form Referentie
     *
     * @return string Form Referentie
     **/
    public function getFormReferentie()
    {
        return $this->formReferentie;
    }

    /**
     * Set Form Referentie
     *
     * @param string $formReferentie Form Referentie
     **/
    public function setFormReferentie($formReferentie)
    {
        $this->formReferentie = $formReferentie;
    }

}