You are here

public function DateTime::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 DateBase::prepare

File

src/Plugin/YamlFormElement/DateTime.php, line 55

Class

DateTime
Provides a 'datetime' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
  parent::prepare($element, $yamlform_submission);

  // Must define a '#default_value' for Datetime element to prevent the
  // below error.
  // Notice: Undefined index: #default_value in Drupal\Core\Datetime\Element\Datetime::valueCallback().
  if (!isset($element['#default_value'])) {
    $element['#default_value'] = NULL;
  }

  // Issue #1838234 Add jQuery Timepicker for the Time element of the
  // datetime field.
  $element['#attached']['library'][] = 'yamlform/yamlform.element.time';
}