-
-
Notifications
You must be signed in to change notification settings - Fork 177
Move field methods to Content\Field
class
#7082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v5/develop
Are you sure you want to change the base?
Conversation
6f3d1fb
to
55012fa
Compare
55012fa
to
d02ec9c
Compare
Not relevant, comment was based on incorrect assumptionOne behavior change not listed in the TODO section for this PR: Currently, method access with
This means that currently it's possible to write A way to keep this backwards-compatible would be to have a mapping of public methods, then in class Field
{
private static $builtinMethods = [
'isvalid' => 'isValid',
'kirbytext' => 'kirbytext',
// …
];
public function __call(string $method, array $arguments = []): mixed
{
$method = strtolower($method);
if ($this->hasMethod($method) === true) {
return $this->callMethod($method, [clone $this, ...$arguments]);
} else if (isset(static::$builtinMethods[$method])) {
return $this->{static::$builtinMethods[$method]}(...$arguments);
} else {
// TODO: throw deprecation, then exception
// when unknown method is called
}
return $this;
}
} (Alternatively, some of that logic — or something a bit more elaborate — could move to the |
@fvsch this is not needed. PHP Methods are case insensitive by default. |
@bastianallgeier Ha! I did not know that. 😅 |
Description
Todo
Ensure altering methods return clone, not alter current objectreplace
method even though this is in the core. Change?Summary of changes
config/methods.php
intoKirby\Content\Field
classKirby\Content\Field::$aliases
array and instead added aliases as actual methods that call the main methodsField::value($value)
is now bound to the cloned new field objectCore::fieldMethods()
andCore::fieldMethodsAliases()
Reasoning
Allows IDEs etc. to actually "understand" field methods, their parameter and return type hints etc.
Changelog
Refactoring
Kirby\Content\Field
Breaking changes
Kirby\Content\Field::$aliases
Kirby\Cms\Core::fieldMethods()
andKirby\Cms\Core::fieldMethodsAliases()
Ready?
For review team