Saves elements.
Description
See also
Parameters
- $elements
-
(array) (Required) Array of
$element_id => $element_data
pairs. - $mappings
-
(array) (Required) Array of mappings to pass-through and modify.
- $errors
-
(WP_Error) (Required) Error object to append errors to.
Return
(array) Modified mappings.
Source
File: src/db-objects/forms/form-edit-page-handler.php
private function save_elements( $elements, $mappings, $errors ) { $element_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' ); foreach ( $elements as $id => $data ) { if ( empty( $data['container_id'] ) || ! isset( $mappings['containers'][ $data['container_id'] ] ) ) { continue; } $data['container_id'] = $mappings['containers'][ $data['container_id'] ]; if ( $this->is_temp_id( $id ) ) { $element = $element_manager->create(); } else { $element = $element_manager->get( $id ); if ( ! $element ) { $element = $element_manager->create(); } } foreach ( $data as $key => $value ) { $element->$key = $value; } $status = $element->sync_upstream(); if ( is_wp_error( $status ) ) { $errors->add( $status->get_error_code(), $status->get_error_message(), array( 'id' => $id, 'data' => $data, ) ); } else { $mappings['elements'][ $id ] = $element->id; } } return $mappings; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |