Skip to content

Commit e941b10

Browse files
author
antoine
committed
Merge branch 'master' of https://github.com/code16/sharp
2 parents d192b36 + c9af58f commit e941b10

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed

docs/guide/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,15 @@ As we can see, each `entity` (like `spaceship`, here), can define:
5656
- and a `policy` class, for authorization.
5757

5858
We'll get into all those classes in this document. The important thing to notice is that Sharp provides base classes to handle all the wiring (and more), but as we'll see, the applicative code is totally up to you.
59+
60+
## Access to Sharp
61+
62+
Once installed, Sharp is accessible via the url `/sharp`, by default. If you wish to change this default value, you'll need to define the `custom_url_segment` config value, in `config/sharp.php`:
63+
64+
```php
65+
return [
66+
"name" => "Saturn",
67+
"custom_url_segment" => "admin",
68+
[...]
69+
]
70+
```

saturn/config/sharp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"url" => "https://google.com"
147147
],
148148
[
149-
"label" => "Features",
149+
"label" => "Some powerful Features",
150150
"icon" => "fa-superpowers",
151151
"entity" => "feature"
152152
]

src/Form/SharpForm.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Code16\Sharp\Form;
44

55
use Code16\Sharp\Exceptions\Form\SharpFormUpdateException;
6-
use Code16\Sharp\Form\Fields\SharpFormField;
76
use Code16\Sharp\Form\Layout\FormLayoutColumn;
87
use Code16\Sharp\Form\Layout\FormLayoutTab;
98
use Code16\Sharp\Utils\SharpNotification;
@@ -83,10 +82,10 @@ public function newInstance()
8382
public function hasDataLocalizations()
8483
{
8584
return collect($this->fields())
86-
->filter(function($field) {
87-
return $field["localized"] ?? false;
88-
})
89-
->count() > 0;
85+
->filter(function($field) {
86+
return $field["localized"] ?? false;
87+
})
88+
->count() > 0;
9089
}
9190

9291
/**
@@ -224,7 +223,18 @@ public function __construct($attributes)
224223
$this->attributes = $attributes;
225224

226225
foreach($attributes as $name => $value) {
227-
$this->$name = $value;
226+
if(strpos($name, ':')) {
227+
list($subModel, $attr) = explode(':', $name);
228+
229+
if(!isset($this->$subModel)) {
230+
$this->$subModel = new \stdClass();
231+
}
232+
233+
$this->$subModel->$attr = $value;
234+
235+
} else {
236+
$this->$name = $value;
237+
}
228238
}
229239
}
230240
public function toArray()

src/SharpServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class SharpServiceProvider extends ServiceProvider
2727
{
2828
/** @var string */
29-
const VERSION = '4.1.13';
29+
const VERSION = '4.1.14';
3030

3131
public function boot()
3232
{

tests/Unit/Form/SharpFormTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ function buildFormFields()
3535
], $sharpForm->newInstance());
3636
}
3737

38+
/** @test */
39+
function we_get_formatted_data_in_creation_with_the_default_create_function_with_subclasses()
40+
{
41+
$sharpForm = new class extends BaseSharpForm {
42+
function buildFormFields()
43+
{
44+
$this->addField(
45+
SharpFormTextField::make("name")
46+
)->addField(
47+
SharpFormMarkdownField::make("subclass:company")
48+
);
49+
}
50+
};
51+
52+
$this->assertEquals([
53+
"name" => "",
54+
"subclass:company" => ["text" => null],
55+
], $sharpForm->newInstance());
56+
}
57+
3858
/** @test */
3959
function if_the_field_formatter_needs_it_we_can_delay_its_execution_after_first_save()
4060
{

0 commit comments

Comments
 (0)