public function DateBase::prepare in YAML Form 8
Prepare an element to be rendered within a form.
Parameters
array $element: An element.
\Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission: A form submission.
Overrides YamlFormElementBase::prepare
2 calls to DateBase::prepare()
- Date::prepare in src/
Plugin/ YamlFormElement/ Date.php - Prepare an element to be rendered within a form.
- DateTime::prepare in src/
Plugin/ YamlFormElement/ DateTime.php - Prepare an element to be rendered within a form.
2 methods override DateBase::prepare()
- Date::prepare in src/
Plugin/ YamlFormElement/ Date.php - Prepare an element to be rendered within a form.
- DateTime::prepare in src/
Plugin/ YamlFormElement/ DateTime.php - Prepare an element to be rendered within a form.
File
- src/
Plugin/ YamlFormElement/ DateBase.php, line 30
Class
- DateBase
- Provides a base 'date' class.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
// Don't used 'datetime_wrapper', instead use 'form_element' wrapper.
// Note: Below code must be executed before parent::prepare().
// @see \Drupal\Core\Datetime\Element\Datelist
// @see \Drupal\yamlform\Plugin\YamlFormElement\DateTime
$element['#theme_wrappers'] = [
'form_element',
];
// Must manually process #states.
// @see drupal_process_states().
if (isset($element['#states'])) {
$element['#attached']['library'][] = 'core/drupal.states';
$element['#wrapper_attributes']['data-drupal-states'] = Json::encode($element['#states']);
}
parent::prepare($element, $yamlform_submission);
// Parse #default_value date input format.
$this
->parseInputFormat($element, '#default_value');
// Parse #min and #max date input format.
$this
->parseInputFormat($element, '#min');
$this
->parseInputFormat($element, '#max');
// Override min/max attributes.
if (!empty($element['#min'])) {
$element['#attributes']['min'] = $element['#min'];
}
if (!empty($element['#max'])) {
$element['#attributes']['max'] = $element['#max'];
}
$element['#element_validate'][] = [
get_class($this),
'validateDate',
];
}