Skip to content

Instantly share code, notes, and snippets.

View tristanbes's full-sized avatar

Tristan Bessoussa tristanbes

View GitHub Profile
@webmozart
webmozart / array-validation-error-mapping.php
Last active June 25, 2023 23:30
A little experiment: Validating (potentially multi-leveled) arrays with the Symfony2 Validator component and returning the errors in the same data structure as the validated array by using the Symfony2 PropertyAccess component.
<?php
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Validator\Constraints\All;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Optional;
use Symfony\Component\Validator\Constraints\Required;
@havvg
havvg / DateRange.php
Last active October 24, 2021 10:33
Symfony2: poor man's date_range form type
<?php
namespace Ormigo\Bundle\OrmigoBundle\Form\Model;
use DateTime;
class DateRange
{
/**
* @var DateTime
@havvg
havvg / wizard.html.twig
Created March 15, 2012 10:41
Symfony2 Form CollectionType remove
{% extends '::base.html.twig' %}
{% from 'MopaBootstrapBundle::icons.html.twig' import icon %}
{% macro widget_prototype(widget, remove_text) %}
{% from 'MopaBootstrapBundle::icons.html.twig' import icon %}
{% if widget.get('prototype') %}
{% set form = widget.get('prototype') %}
{% set name = widget.get('prototype').get('name') %}