You are here

protected static function WebformMultiple::setElementDefaultValue in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformMultiple.php \Drupal\webform\Element\WebformMultiple::setElementDefaultValue()

Set element row default value recursively.

Parameters

array $element: The element.

mixed $default_value: The default value.

2 calls to WebformMultiple::setElementDefaultValue()
WebformMultiple::buildElementRow in src/Element/WebformMultiple.php
Build a single element row.
WebformMultiple::setElementRowDefaultValueRecursive in src/Element/WebformMultiple.php
Set element row default value recursively.

File

src/Element/WebformMultiple.php, line 750

Class

WebformMultiple
Provides a webform element to assist in creation of multiple elements.

Namespace

Drupal\webform\Element

Code

protected static function setElementDefaultValue(array &$element, $default_value) {
  if ($element['#type'] === 'value') {
    $element['#value'] = $default_value;
  }
  else {
    $element['#default_value'] = $default_value;

    // Set default value.
    // @see \Drupal\webform\Plugin\WebformElementInterface::setDefaultValue
    // @see \Drupal\webform\Plugin\WebformElement\DateBase::setDefaultValue

    /** @var \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager */
    $element_manager = \Drupal::service('plugin.manager.webform.element');
    $element_plugin = $element_manager
      ->getElementInstance($element);
    $element_plugin
      ->setDefaultValue($element);
  }
}