diff --git a/classes/controllers/FrmStylesController.php b/classes/controllers/FrmStylesController.php index bc153d5622..2cb71178cb 100644 --- a/classes/controllers/FrmStylesController.php +++ b/classes/controllers/FrmStylesController.php @@ -20,6 +20,15 @@ class FrmStylesController { */ private static $message; + /** + * Cache of the active style object keyed by form ID. + * + * @since x.x + * + * @var array + */ + private static $active_style = array(); + /** * @return void */ @@ -1273,6 +1282,50 @@ public static function get_form_style( $form = 'default' ) { return $frm_style->get_one(); } + /** + * Get the active style object for a field's form. + * + * @since x.x + * + * @param array|int $field The 'field' array. + * + * @return object + */ + public static function get_active_style( $field ) { + if ( ! is_array( $field ) ) { + return new stdClass(); + } + + $form_id = $field['parent_form_id'] ?? $field['form_id']; + + if ( isset( self::$active_style[ $form_id ] ) ) { + return self::$active_style[ $form_id ]; + } + + $active_style = self::get_form_style( $form_id ); + + if ( ! is_object( $active_style ) ) { + $active_style = new stdClass(); + } + + self::$active_style[ $form_id ] = $active_style; + + return self::$active_style[ $form_id ]; + } + + /** + * Get the style setting key that stores the alignment for a field type. + * + * @since x.x + * + * @param string $field_type + * + * @return string + */ + public static function get_align_key_for_style_settings( $field_type ) { + return 'checkbox' === $field_type ? 'check_align' : 'radio_align'; + } + /** * @param string $class * @param string $style diff --git a/classes/models/fields/FrmFieldType.php b/classes/models/fields/FrmFieldType.php index 07075cd3d7..70bba2edce 100644 --- a/classes/models/fields/FrmFieldType.php +++ b/classes/models/fields/FrmFieldType.php @@ -1082,13 +1082,33 @@ public function get_container_class() { return ''; } - $align = FrmField::get_option( $this->field, 'align' ); + $align = FrmAppHelper::pro_is_installed() ? FrmField::get_option( $this->field, 'align' ) : ''; + + if ( ! $align ) { + $align = $this->get_align_class_from_style_settings(); + } $this->prepare_align_class( $align ); return $align ? ' ' . $align : ''; } + /** + * Get the alignment value from the active style settings. + * + * Used as the fallback when the field has no specific alignment option set. + * + * @since x.x + * + * @return string + */ + protected function get_align_class_from_style_settings() { + $key = FrmStylesController::get_align_key_for_style_settings( FrmField::get_field_type( $this->field ) ); + $active_style = FrmStylesController::get_active_style( $this->field ); + + return $active_style->post_content[ $key ] ?? ''; + } + /** * @since 4.0 *