Created
March 25, 2015 08:55
-
-
Save avanzu/bb2d4b12113ed907b5ff to your computer and use it in GitHub Desktop.
Restrictable date type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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