You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The developer has to check if the entered values are plain or multilingual.
There is no real reason why the developer needs to check this, and it is not easy to safe the string in the database.
Possible new API class
classI18nField
{
publicfunction__construct(
public readonly string$fieldName,
public readonly string$pattern,
string|int$languageCategory,
string|int$package = PACKAGE_ID,
public readonly bool$requireI18n = false,
public readonly bool$permitEmptyValue = false,
);
/** * Initializes the values for this field. * If the given value is a string and matches the pattern, the values are loaded from the database, * otherwise, the given value is used as the non-multilingual value. */publicfunctioninitValues(string|array$value);
/** * Stores the values of this field in the database if the values are multilingual. * If the values are multilingual, the given objectID is replaced in the pattern and returned, * otherwise the plain value is returned. * * When the values are non-multilingual, the old language items are removed from the database. */publicfunctionsave(int$objectID): string;
/** * Removes language items from the database, matching the given objectIDs in the pattern. */publicstaticfunctionremove(
int|array$objectIDs,
string$pattern,
string|int$languageCategory,
string|int$package
): void;
/** * Returns true if the values are valid, otherwise a string with the error type is returned. * `empty` is returned if the field is required and the value is empty. * `multilingual` is returned if the field requires multilingual values and one or more values are missing. */publicfunctionvalidate(): string|bool;
/** * Reads the values from the given request data. * If the request data is `null`, the values are read from the `$_POST` array. */publicfunctionreadValues(?array$requestData = null): void;
/** * Resets the values of this field. */publicfunctionreset(): void;
publicfunctiongetValues(): array;
/** * If the values are multilingual, the value for the default language is returned, * otherwise the plain value is returned. */publicfunction__toString(): string;
}
This also allows bulk deleting and deleting only language items according to the given parameters. #4472
In many cases, working with the I18nHandler generates duplicate and unnecessary code. A new API can reduce this and prevent unnecessary errors.
Current using of I18nHandler
The developer has to check if the entered values are plain or multilingual.
There is no real reason why the developer needs to check this, and it is not easy to safe the string in the database.
Possible new API class
This also allows bulk deleting and deleting only language items according to the given parameters. #4472
Possible implementation
The text was updated successfully, but these errors were encountered: