Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
78 changes: 0 additions & 78 deletions phpcs.xml

This file was deleted.

32 changes: 32 additions & 0 deletions src/Parsers/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Comment thread
rilwis marked this conversation as resolved.
unset( $this->datetime_format );

return $this;
}

private function parse_field_block_editor(): self {
if ( ! class_exists( '\MBB\Helpers\AllowedBlockLists' ) ) {
return $this;
Expand Down
38 changes: 38 additions & 0 deletions src/Unparsers/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading