data_type = 'enum'; $this->item_hide_icon = true; } /** * Overwrite method show_item: create listbox from enum */ protected function show_item() { if ( $this->is_key_column && ! $this->show_context_update_keys_allowed ) { // PROBLEM // Key columns are set to readonly. This will not work for listboxes. // Therefor listboxes need to be set to disabled. Disabled values however // are not available in a post ($_POST/$_REQUEST). // SOLUTION // Disable listbox (see JS when document is loaded) and add a hidden field // holding the key value (HERE). ?> is_nullable && ( '' === $this->item_value || null === $this->item_value ) ) { return true; } if ( 'enum' === substr( $this->column_type, 0, 4 ) ) { // Get enum from MySQL table. $allowed_values = explode( ',', str_replace( '\'', '', substr( substr( (string) $this->column_type, 5 ), 0, - 1 ) ) ); // phpcs:ignore -- 8.1 proof $value_found = false; // Check if value is in enum. foreach ( $allowed_values as $allowed_value ) { if ( $allowed_value === $this->item_value ) { $value_found = true; // Value allowed. } } if ( ! $value_found ) { // Value not in enum: inform user and set validation to failed. $msg = new WPDA_Message_Box( array( 'message_text' => 'Value for ' . str_replace( '_', ' ', $this->item_name ) . ' ' . __( 'not allowed', 'wp-data-access' ), 'message_type' => 'error', 'message_is_dismissible' => false, ) ); $msg->box(); return false; } } else { // TODO: how can I test the values of a manually created enum? } return true; } } }