Skip to content

Commit c8614f8

Browse files
authored
Merge branch 'master' into feature/third-party-integrations
2 parents c5fb85a + c531c9b commit c8614f8

10 files changed

Lines changed: 42 additions & 21 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
[![Latest Version on Packagist](https://img.shields.io/packagist/v/kirschbaum-development/nova-inline-relationship.svg)](https://packagist.org/packages/kirschbaum-development/nova-inline-relationship)
66
[![Total Downloads](https://img.shields.io/packagist/dt/kirschbaum-development/nova-inline-relationship.svg)](https://packagist.org/packages/kirschbaum-development/nova-inline-relationship)
7+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/56297e6b77604f37a505edf234ca2a4b)](https://www.codacy.com/manual/Kirschbaum/nova-inline-relationship?utm_source=github.com&utm_medium=referral&utm_content=kirschbaum-development/nova-inline-relationship&utm_campaign=Badge_Grade)
78
[![Actions Status](https://github.com/kirschbaum-development/nova-inline-relationship/workflows/CI/badge.svg)](https://github.com/kirschbaum-development/nova-inline-relationship/actions)
89

910
Nova Inline Relationship allows you to manage (add/edit/update/delete/reorder) an object's relationships directly from the parent object's create/edit screens. By presenting relationships as inline properties you can provide content editors with a streamlined and efficient workflow for managing complex data.

resources/js/field.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Nova.booting((Vue, router, store) => {
2-
Vue.component('index-nova-inline-relationship', require('./components/IndexField'))
3-
Vue.component('detail-nova-inline-relationship', require('./components/DetailField'))
4-
Vue.component('form-nova-inline-relationship', require('./components/FormField'))
1+
Nova.booting(Vue => {
2+
Vue.component('index-nova-inline-relationship', require('./components/IndexField'));
3+
Vue.component('detail-nova-inline-relationship', require('./components/DetailField'));
4+
Vue.component('form-nova-inline-relationship', require('./components/FormField'));
55

6-
Vue.config.devtools = true
7-
})
6+
Vue.config.devtools = true;
7+
});

src/Exceptions/IncorrectRelationshipFormat.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class IncorrectRelationshipFormat extends InvalidArgumentException
1414
*/
1515
public static function create(string $key, string $value)
1616
{
17-
return new static(sprintf('Incorrect relationship attribute value (%s) for a key (%s). Please make sure that array returned by getPropertyMap function is in the following format: "relationship.attribute".', $key, $value));
17+
return new static(
18+
"Incorrect relationship attribute value [{$value}] for a key [{$key}]. Please make sure that array " .
19+
"returned by getPropertyMap function is in the following format: \"relationship.attribute\"."
20+
);
1821
}
1922
}

src/Exceptions/InvalidRelationshipName.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class InvalidRelationshipName extends InvalidArgumentException
1414
*/
1515
public static function create(string $key, string $value)
1616
{
17-
return new static(sprintf('Invalid relationship name (%s) for a key (%s) in array returned by getPropertyMap function. Please make sure that this relationship is defined on the model.', $value, $key));
17+
return new static(
18+
"Invalid relationship name [{$value}] for a key [{$key}] in array returned by getPropertyMap function. " .
19+
"Please make sure that this relationship is defined on the model."
20+
);
1821
}
1922
}

src/Exceptions/UnsupportedNestedRelationship.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class UnsupportedNestedRelationship extends InvalidArgumentException
1414
*/
1515
public static function create(string $key, string $value)
1616
{
17-
return new static(sprintf('Unsupported nested relationship attribute value (%s) for a key (%s). Please make sure that array returned by getPropertyMap function is in the following format: "relationship.attribute" and is only one level deep.', $key, $value));
17+
return new static(
18+
"Unsupported nested relationship attribute value [{$value}] for a key [{$key}]. Please make sure that " .
19+
"array returned by getPropertyMap function is in the following format: \"relationship.attribute\" and is " .
20+
"only one level deep."
21+
);
1822
}
1923
}

src/Exceptions/UnsupportedRelationshipType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class UnsupportedRelationshipType extends InvalidArgumentException
1414
*/
1515
public static function create(string $type, string $key)
1616
{
17-
return new static(sprintf('Unsupported Inline Relationship type (%s) for an attribute (%s).', $type, $key));
17+
return new static("Unsupported Inline Relationship type [{$type}] for an attribute [{$key}].");
1818
}
1919
}

src/NovaInlineRelationship.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ public function getDuplicateRequest(NovaRequest $request, array $item): NovaInli
208208
});
209209

210210
// Create a New Request
211-
$newRequest = NovaInlineRelationshipRequest::createFrom($request)->duplicate($item, array_merge($request->all(), $item));
211+
$newRequest = NovaInlineRelationshipRequest::createFrom($request)
212+
->duplicate($item, array_merge($request->all(), $item));
213+
212214
// Update List of converted Files
213215
$newRequest->updateConvertedFiles($files);
214216

@@ -244,12 +246,13 @@ public function getValueFromField(Field $field, NovaInlineRelationshipRequest $r
244246
protected function resolveResourceFields($resource, $attribute, $properties)
245247
{
246248
$this->rules = [$this->getRelationshipRule($attribute, $properties)];
249+
$modelKey = optional($this->value)->first() ?? $resource->{$attribute}()->getRelated()->newInstance();
247250

248251
$this->withMeta([
249252
'defaults' => $this->getDefaultsFromProperties($properties)->all(),
250253
'settings' => $properties->all(),
251254
'models' => $this->modelIds(),
252-
'modelKey' => Str::plural(Str::kebab(class_basename(optional($this->value)->first() ?? $resource->{$attribute}()->getRelated()->newInstance()))),
255+
'modelKey' => Str::plural(Str::kebab(class_basename($modelKey))),
253256
'singularLabel' => Str::title(Str::singular($this->name)),
254257
'pluralLabel' => Str::title(Str::plural($this->name)),
255258
'singular' => $this->isSingularRelationship($resource, $attribute),
@@ -326,7 +329,9 @@ protected function setMetaFromClass(array $item, $attrib, $value = null)
326329
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
327330
{
328331
if ($request->exists($requestAttribute)) {
329-
$response = is_array($request[$requestAttribute]) ? $request[$requestAttribute] : json_decode($request[$requestAttribute], true);
332+
$response = is_array($request[$requestAttribute])
333+
? $request[$requestAttribute]
334+
: json_decode($request[$requestAttribute], true);
330335

331336
$properties = $this->getPropertiesFromResource($model, $attribute);
332337

@@ -482,7 +487,10 @@ protected function getResourceResponse(NovaRequest $request, $response, Collecti
482487
$field = $this->getResourceField($properties->get($key), $key);
483488
$newRequest = $this->getDuplicateRequest($request, $item);
484489

485-
return $this->getValueFromField($field, $newRequest, $key) ?? ((($field instanceof File) && ! empty($value)) ? $value : null);
490+
return $this->getValueFromField($field, $newRequest, $key)
491+
?? ($field instanceof File) && ! empty($value)
492+
? $value
493+
: null;
486494
}
487495

488496
return $value;

src/NovaInlineRelationshipRequest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ class NovaInlineRelationshipRequest extends NovaRequest
1212
/**
1313
* {@inheritdoc}
1414
*/
15-
public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
16-
{
15+
public function duplicate(
16+
array $query = null,
17+
array $request = null,
18+
array $attributes = null,
19+
array $cookies = null,
20+
array $files = null,
21+
array $server = null
22+
) {
1723
return parent::duplicate($query, $request, $attributes, $cookies, $files, $server);
1824
}
1925

tests/TestCase.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,9 @@ protected function createNovaRequestMock()
183183
/**
184184
* Load package service provider.
185185
*
186-
* @param Application $app
187-
*
188186
* @return array
189187
*/
190-
protected function getPackageProviders($app)
188+
protected function getPackageProviders()
191189
{
192190
return [NovaInlineRelationshipServiceProvider::class];
193191
}

tests/Unit/HasOneTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ public function testFillAttributeForDelete()
111111
$newEmployee = Employee::create(['name' => 'Test']);
112112
$newEmployee->profile()->save(Profile::make(['phone' => '123123123']));
113113

114-
$id = $newEmployee->fresh()->profile->id;
115-
116114
$updateRequest = [
117115
'name' => 'Test 2',
118116
'profile' => [

0 commit comments

Comments
 (0)