public function WebformTableRow::getConfigurationFormProperties in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/WebformTableRow.php \Drupal\webform\Plugin\WebformElement\WebformTableRow::getConfigurationFormProperties()
Get an associative array of element properties from configuration webform.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array An associative array of element properties.
Overrides WebformElementBase::getConfigurationFormProperties
File
- src/
Plugin/ WebformElement/ WebformTableRow.php, line 259
Class
- WebformTableRow
- Provides a 'webform_table_row' element.
Namespace
Drupal\webform\Plugin\WebformElementCode
public function getConfigurationFormProperties(array &$form, FormStateInterface $form_state) {
$properties = parent::getConfigurationFormProperties($form, $form_state);
/** @var \Drupal\webform_ui\Form\WebformUiElementFormInterface $form_object */
$form_object = $form_state
->getFormObject();
if (!$form_object
->isNew()) {
return $properties;
}
// Get and unset the #duplicate property.
$duplicate = !empty($properties['#duplicate']);
unset($properties['#duplicate']);
// If $duplicate is FALSE don't duplicate the child elements.
if (!$duplicate) {
return $properties;
}
// This is the only way to get the row key for a new element.
$key = $_POST['key'];
$parent_key = \Drupal::request()->query
->get('parent');
if (!$form_object
->isNew() || !$parent_key) {
return $properties;
}
$row_index = preg_match('/\\d+/', $key, $match) ? intval($match[0]) : NULL;
$table_element = $this
->getWebform()
->getElement($parent_key);
if (!$table_element['#webform_children']) {
return $properties;
}
$row_key = reset($table_element['#webform_children']);
$children_elements = $this
->getChildrenElements($row_key, $row_index);
if ($children_elements === FALSE) {
$this
->messenger()
->addWarning("Unable to append child elements from @row because a child element's key do not include any index/number.", [
'@row' => $row_key,
]);
}
else {
$properties += $children_elements;
}
return $properties;
}