PHP code example of digipolisgent / setting-bundle
1. Go to this page and download the library: Download digipolisgent/setting-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digipolisgent / setting-bundle example snippets
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use DigipolisGent\SettingBundle\Entity\Traits\SettingImplementationTrait;
/**
* @ORM\Entity()
*/
class Foo
{
/**
* @ORM\Id
* @ORM\Column(type="guid")
* @ORM\GeneratedValue(strategy="UUID")
*/
protected $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
use SettingImplementationTrait;
/**
* @return string
*/
public static function getSettingImplementationName()
{
return 'foo';
}
}
namespace DigipolisGent\SettingBundle\FieldType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
/**
* Class StringFieldType
* @package DigipolisGent\SettingBundle\FieldType
*/
class StringFieldType extends AbstractFieldType
{
/**
* @return string
*/
public static function getName(): string
{
return 'string';
}
/**
* @return string
*/
public function getFormType(): string
{
return TextType::class;
}
/**
* @param $value
* @return array
*/
public function getOptions($value): array
{
$options = [];
$options['attr']['value'] = $value ? $value : '';
return $options;
}
/**
* @param $value
* @return mixed
*/
public function decodeValue($value)
{
return $value;
}
/**
* @param $value
* @return string
*/
public function encodeValue($value): string
{
return $value;
}
}
namespace AppBundle\Provider;
use DigipolisGent\SettingBundle\Provider\DataTypeProviderInterface;
class DataTypeProvider implements DataTypeProviderInterface
{
/**
* @return array
*/
public function getDataTypes()
{
return [
[
'key' => 'bar',
'label' => 'My foo label',
'
namespace AppBundle\Form\Type;
use DigipolisGent\SettingBundle\EventListener\SettingFormListener;
use DigipolisGent\SettingBundle\Service\FormService;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\AbstractType;
class YourFormType extends AbstractType
{
public $formService;
/**
* @param FormService $formService
*/
public function setFormService(FormService $formService)
{
$this->formService = $formService;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->addEventSubscriber(new SettingFormListener($this->formService));
}
}