Skip to content
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

Seed Refactoring #50

Closed
romaninsh opened this issue Jul 28, 2017 · 2 comments
Closed

Seed Refactoring #50

romaninsh opened this issue Jul 28, 2017 · 2 comments
Assignees

Comments

@romaninsh
Copy link
Member

romaninsh commented Jul 28, 2017

The usage of "Seed" throughout the framework have been a bit inconsistent. This needs to be reviewed. Here is proposal on how seed should work:

$seed = ['Class', 'arg1', 'arg2', 'property'=>$val];
$layout->add($seed);

this would be identical to:

$object = new Class('arg1', 'arg2');
$object->property=$val;
$layout->add($object);

Usage

This format would be respected throghout the framework, for example:

$layout->add(['Button', 'Label', 'red']);

For this to work correctly, constructor of Button() should accept arguments like this:

$button = new Button('Label', 'red');

Although it would require some refactoring, this approach would help with consistency. Another example is current implementation of TableColumn/Link:

$link = new \atk4\ui\TableColumn\Link($url, $args);

would, without hacking, translate into

$table->addColumn('name', ['Link', $url, $args]);

In other cases, if something is inconsistent, it needs to be adjusted. Here is example with addField:

$model->addField('age', ['type'=>'integer']);

Currently there is some custom logic there, but what we would have to do inside addfield:

function addField('name', $data) {
   if (!isset($data[0])) { $data[0] = $this->default_field_class; }
}

In other words, the new implementation would allow this:

$model->addField('image', ['ImageField', 'width'=>100, 'height'=>100]);

and actually could also give us alternative option to create reference:

$model->addField('country_id', ['Reference_One', 'model'=>new Country()]);

This is a major change across all of ATK and would require new releases to be coordinated.

Prefixing

The benefit of using seed is automated prefixing. For instance:

$form->addField('due', ['Money']);

When looking for the class, it will actually prefix 'Money' with 'FieldDecorator'. If any slashes are specified then no prefixing will take place.

When this is passed to the factory routine, it will prepend class name with '\atk4\ui' as well.

For user-defined classes, it's easier just to pass the object, while 3rd party add-ons may add more ways to prepend things, e.g. \thirdparty\bootstrap\FieldDecorator\Money.

@DarkSide666
Copy link
Member

looks good

@romaninsh
Copy link
Member Author

Implemented in #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants