null, 'starts_at' => null, 'ends_at' => null, 'block_type' => 'other', 'reason' => null, 'note' => null ], $current, $input ); $data['resource_id'] = ScheduleValidator::resource( $data['resource_id'], $this->resources ); $data['block_type'] = CatalogValidator::choice( $data['block_type'], 'block_type', self::TYPES ); foreach ( [ 'starts_at', 'ends_at' ] as $field ) { if ( null === $data[ $field ] ) { CatalogValidator::invalid( $field, __( 'This field is required.', 'abece-booking' ) ); } $data[ $field ] = MembershipValidator::instant( $data[ $field ], $field ); } if ( $data['starts_at'] >= $data['ends_at'] ) { CatalogValidator::invalid( 'ends_at', __( 'Block end must be after its start.', 'abece-booking' ) ); } $data['reason'] = MembershipValidator::text( $data['reason'], 'reason', 255, true ); if ( null !== $data['note'] && ! is_string( $data['note'] ) ) { CatalogValidator::invalid( 'note', __( 'A text value is required.', 'abece-booking' ) ); } $data['note'] = null === $data['note'] ? null : sanitize_textarea_field( $data['note'] ); if ( null !== $data['note'] && strlen( $data['note'] ) > 65535 ) { CatalogValidator::invalid( 'note', __( 'Block note is too long.', 'abece-booking' ) ); } return $data; } protected function persist( array $data, ?int $id ): array { if ( null === $id ) { $data['created_by_user_id'] = get_current_user_id() ?: null; } return parent::persist( $data, $id ); } }