diff --git a/AGENTS.md b/AGENTS.md index 1b20131..d10c793 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,12 +7,12 @@ PHP library for parsing and unparsing Meta Box settings from the builder (provid ### Lint ```bash -composer phpcs +composer phpcs src ``` ### Fix Auto-fixable Issues ```bash -composer phpcbf +composer phpcbf src ``` ### No Tests diff --git a/composer.json b/composer.json index 6d4421a..0f45379 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "riimu/kit-phpencoder": "^2.4" }, "scripts": { - "phpcs": "phpcs --standard=phpcs.xml src", - "phpcbf": "phpcbf --standard=phpcs.xml src" + "phpcs": "phpcs --standard=../meta-box-aio/phpcs.xml", + "phpcbf": "phpcbf --standard=../meta-box-aio/phpcs.xml" } } diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 712d8b7..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - . - - - /vendor/* - /tests/* - /.github/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Parsers/Field.php b/src/Parsers/Field.php index 24db32a..7ecc056 100644 --- a/src/Parsers/Field.php +++ b/src/Parsers/Field.php @@ -288,6 +288,38 @@ private function parse_text_limiter() { return $this; } + private function parse_field_datetime(): self { + if ( empty( $this->datetime_format ) ) { + return $this; + } + + $js_options = is_array( $this->js_options ) ? $this->js_options : []; + $separator = $js_options['separator'] ?? ' '; + $pos = strpos( $this->datetime_format, $separator ); + + // Split format (simple format rule: "date time") + $date_format = false !== $pos ? substr( $this->datetime_format, 0, $pos ) : $this->datetime_format; // If no separator, client setup for date format + $time_format = false !== $pos ? substr( $this->datetime_format, $pos + strlen( $separator ) ) : ''; + + if ( $date_format && empty( $js_options['dateFormat'] ) ) { + $js_options['dateFormat'] = $date_format; + } + + if ( $time_format && empty( $js_options['timeFormat'] ) ) { + $js_options['timeFormat'] = $time_format; + } + + if ( empty( $js_options['separator'] ) ) { + $js_options['separator'] = ' '; + } + + $this->js_options = $js_options; + + unset( $this->datetime_format ); + + return $this; + } + private function parse_field_block_editor(): self { if ( ! class_exists( '\MBB\Helpers\AllowedBlockLists' ) ) { return $this; diff --git a/src/Unparsers/Field.php b/src/Unparsers/Field.php index 103498e..17e90b6 100644 --- a/src/Unparsers/Field.php +++ b/src/Unparsers/Field.php @@ -273,4 +273,42 @@ protected function ensure_boolean( $key ) { } return $this; } + + private function unparse_field_datetime(): self { + if ( empty( $this->js_options ) ) { + return $this; + } + + $js_options = is_array( $this->js_options ) ? $this->js_options : []; + $date_format = $this->get_js_option_value( $js_options, 'dateFormat' ); + $time_format = $this->get_js_option_value( $js_options, 'timeFormat' ); + $separator = $this->get_js_option_value( $js_options, 'separator' ) ?? ' '; + + if ( $date_format && $time_format ) { + $this->datetime_format = "{$date_format}{$separator}{$time_format}"; + } elseif ( $date_format ) { + $this->datetime_format = $date_format; + } elseif ( $time_format ) { + $this->datetime_format = $time_format; + } + + foreach ( $js_options as $key => $option ) { + if ( isset( $option['key'] ) && in_array( $option['key'], [ 'dateFormat', 'timeFormat', 'separator' ], true ) ) { + unset( $js_options[ $key ] ); + } + } + $this->js_options = $js_options; + + return $this; + } + + private function get_js_option_value( array $js_options, string $key ) { + foreach ( $js_options as $option ) { + if ( isset( $option['key'] ) && $option['key'] === $key ) { + return $option['value'] ?? null; + } + } + + return null; + } }