Skip to content

Instantly share code, notes, and snippets.

@avanzu
Created March 25, 2015 08:55
Show Gist options
  • Save avanzu/bb2d4b12113ed907b5ff to your computer and use it in GitHub Desktop.
Save avanzu/bb2d4b12113ed907b5ff to your computer and use it in GitHub Desktop.
Restrictable date type
class RestrictedDateType extends DateType {
public function buildView(FormView $view, FormInterface $form, array $options)
{
parent::buildView($view, $form, $options);
// transport the option into the form block
$view->vars['restricted'] = $options['restricted'];
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
parent::setDefaultOptions($resolver);
/* add the "restricted" option to allow configuration during form generation
$builder->add('restrict', new RestrictedDateType(), array(
'widget' => 'single_text',
'restricted' => array('2014-01-03')
))
*/
$resolver->setDefaults(array(
'restricted' => array()
));
}
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
public function getName()
{
return 'restricted_date';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment