| @@ -619,10 +619,37 @@ | ||
| 619 | 619 | 'field_order' => (int) $field->field_order, |
| 620 | 620 | 'form_id' => (int) $form_id, |
| 621 | 621 | 'required' => (int) $field->required, |
| 622 | 622 | 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options ), |
| 623 | - 'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ), | |
| 623 | + 'field_options' => self::fill_field_options( $field ), | |
| 624 | 624 | ); |
| 625 | + } | |
| 626 | + | |
| 627 | + /** | |
| 628 | + * Reads a field's options out of the file as an array. | |
| 629 | + * | |
| 630 | + * Field options are a settings map, and every step of the import reads them | |
| 631 | + * as one. A file whose value there cannot be read, because it is empty or | |
| 632 | + * was written by something other than an export, used to end the whole | |
| 633 | + * import with a fatal error on the first field it reached. An empty set of | |
| 634 | + * options is recoverable, since the defaults for the field type fill the | |
| 635 | + * gaps, so prefer that over stopping. | |
| 636 | + * | |
| 637 | + * Unserialize is tried as well as JSON so options written by an older | |
| 638 | + * version are still read rather than thrown away. | |
| 639 | + * | |
| 640 | + * @since 6.35 | |
| 641 | + * | |
| 642 | + * @param object $field Field element from the file. | |
| 643 | + * | |
| 644 | + * @return array | |
| 645 | + */ | |
| 646 | + private static function fill_field_options( $field ) { | |
| 647 | + $options = (string) $field->field_options; | |
| 648 | + | |
| 649 | + FrmAppHelper::unserialize_or_decode( $options ); | |
| 650 | + | |
| 651 | + return is_array( $options ) ? $options : array(); | |
| 625 | 652 | } |
| 626 | 653 | |
| 627 | 654 | /** |
| 628 | 655 | * @since 4.06 |