Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit fd54126

Browse files
committed
Fix PropertyAccessor trying to get value on null relation
1 parent e2f44a3 commit fd54126

File tree

5 files changed

+152
-112
lines changed

5 files changed

+152
-112
lines changed

Datatable/Column/BooleanColumn.php

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,17 @@ public function renderSingleField(array &$row)
8888
{
8989
$path = Helper::getDataPropertyPath($this->data);
9090

91-
if (true === $this->isEditableContentRequired($row)) {
92-
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
93-
} else {
94-
$content = $this->renderTemplate($this->accessor->getValue($row, $path));
95-
}
91+
if ($this->accessor->isReadable($row, $path)) {
92+
93+
if (true === $this->isEditableContentRequired($row)) {
94+
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
95+
} else {
96+
$content = $this->renderTemplate($this->accessor->getValue($row, $path));
97+
}
9698

97-
$this->accessor->setValue($row, $path, $content);
99+
$this->accessor->setValue($row, $path, $content);
100+
101+
}
98102

99103
return $this;
100104
}
@@ -107,27 +111,31 @@ public function renderToMany(array &$row)
107111
$value = null;
108112
$path = Helper::getDataPropertyPath($this->data, $value);
109113

110-
$entries = $this->accessor->getValue($row, $path);
111-
112-
if (count($entries) > 0) {
113-
foreach ($entries as $key => $entry) {
114-
$currentPath = $path.'['.$key.']'.$value;
115-
$currentObjectPath = Helper::getPropertyPathObjectNotation($path, $key, $value);
116-
117-
if (true === $this->isEditableContentRequired($row)) {
118-
$content = $this->renderTemplate(
119-
$this->accessor->getValue($row, $currentPath),
120-
$row[$this->editable->getPk()],
121-
$currentObjectPath
122-
);
123-
} else {
124-
$content = $this->renderTemplate($this->accessor->getValue($row, $currentPath));
125-
}
114+
if ($this->accessor->isReadable($row, $path)) {
126115

127-
$this->accessor->setValue($row, $currentPath, $content);
116+
$entries = $this->accessor->getValue($row, $path);
117+
118+
if (count($entries) > 0) {
119+
foreach ($entries as $key => $entry) {
120+
$currentPath = $path . '[' . $key . ']' . $value;
121+
$currentObjectPath = Helper::getPropertyPathObjectNotation($path, $key, $value);
122+
123+
if (true === $this->isEditableContentRequired($row)) {
124+
$content = $this->renderTemplate(
125+
$this->accessor->getValue($row, $currentPath),
126+
$row[$this->editable->getPk()],
127+
$currentObjectPath
128+
);
129+
} else {
130+
$content = $this->renderTemplate($this->accessor->getValue($row, $currentPath));
131+
}
132+
133+
$this->accessor->setValue($row, $currentPath, $content);
134+
}
135+
} else {
136+
// no placeholder - leave this blank
128137
}
129-
} else {
130-
// no placeholder - leave this blank
138+
131139
}
132140

133141
return $this;

Datatable/Column/Column.php

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ class Column extends AbstractColumn
4343
*/
4444
public function renderSingleField(array &$row)
4545
{
46-
if ($this->isEditableContentRequired($row)) {
47-
$path = Helper::getDataPropertyPath($this->data);
46+
$path = Helper::getDataPropertyPath($this->data);
4847

49-
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
48+
if ($this->accessor->isReadable($row, $path)) {
49+
50+
if ($this->isEditableContentRequired($row)) {
51+
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
52+
$this->accessor->setValue($row, $path, $content);
53+
}
5054

51-
$this->accessor->setValue($row, $path, $content);
5255
}
5356

5457
return $this;
@@ -59,31 +62,36 @@ public function renderSingleField(array &$row)
5962
*/
6063
public function renderToMany(array &$row)
6164
{
62-
if ($this->isEditableContentRequired($row)) {
63-
// e.g. comments[ ].createdBy.username
64-
// => $path = [comments]
65-
// => $value = [createdBy][username]
66-
$value = null;
67-
$path = Helper::getDataPropertyPath($this->data, $value);
68-
69-
$entries = $this->accessor->getValue($row, $path);
70-
71-
if (count($entries) > 0) {
72-
foreach ($entries as $key => $entry) {
73-
$currentPath = $path.'['.$key.']'.$value;
74-
$currentObjectPath = Helper::getPropertyPathObjectNotation($path, $key, $value);
75-
76-
$content = $this->renderTemplate(
77-
$this->accessor->getValue($row, $currentPath),
78-
$row[$this->editable->getPk()],
79-
$currentObjectPath
80-
);
81-
82-
$this->accessor->setValue($row, $currentPath, $content);
65+
$value = null;
66+
$path = Helper::getDataPropertyPath($this->data, $value);
67+
68+
if ($this->accessor->isReadable($row, $path)) {
69+
70+
if ($this->isEditableContentRequired($row)) {
71+
// e.g. comments[ ].createdBy.username
72+
// => $path = [comments]
73+
// => $value = [createdBy][username]
74+
75+
$entries = $this->accessor->getValue($row, $path);
76+
77+
if (count($entries) > 0) {
78+
foreach ($entries as $key => $entry) {
79+
$currentPath = $path . '[' . $key . ']' . $value;
80+
$currentObjectPath = Helper::getPropertyPathObjectNotation($path, $key, $value);
81+
82+
$content = $this->renderTemplate(
83+
$this->accessor->getValue($row, $currentPath),
84+
$row[$this->editable->getPk()],
85+
$currentObjectPath
86+
);
87+
88+
$this->accessor->setValue($row, $currentPath, $content);
89+
}
90+
} else {
91+
// no placeholder - leave this blank
8392
}
84-
} else {
85-
// no placeholder - leave this blank
8693
}
94+
8795
}
8896

8997
return $this;

Datatable/Column/DateTimeColumn.php

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,17 @@ public function renderSingleField(array &$row)
6464
{
6565
$path = Helper::getDataPropertyPath($this->data);
6666

67-
if (true === $this->isEditableContentRequired($row)) {
68-
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
69-
} else {
70-
$content = $this->renderTemplate($this->accessor->getValue($row, $path));
71-
}
67+
if ($this->accessor->isReadable($row, $path)) {
68+
69+
if (true === $this->isEditableContentRequired($row)) {
70+
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
71+
} else {
72+
$content = $this->renderTemplate($this->accessor->getValue($row, $path));
73+
}
7274

73-
$this->accessor->setValue($row, $path, $content);
75+
$this->accessor->setValue($row, $path, $content);
76+
77+
}
7478

7579
return $this;
7680
}
@@ -83,27 +87,31 @@ public function renderToMany(array &$row)
8387
$value = null;
8488
$path = Helper::getDataPropertyPath($this->data, $value);
8589

86-
$entries = $this->accessor->getValue($row, $path);
87-
88-
if (count($entries) > 0) {
89-
foreach ($entries as $key => $entry) {
90-
$currentPath = $path.'['.$key.']'.$value;
91-
$currentObjectPath = Helper::getPropertyPathObjectNotation($path, $key, $value);
92-
93-
if (true === $this->isEditableContentRequired($row)) {
94-
$content = $this->renderTemplate(
95-
$this->accessor->getValue($row, $currentPath),
96-
$row[$this->editable->getPk()],
97-
$currentObjectPath
98-
);
99-
} else {
100-
$content = $this->renderTemplate($this->accessor->getValue($row, $currentPath));
101-
}
90+
if ($this->accessor->isReadable($row, $path)) {
10291

103-
$this->accessor->setValue($row, $currentPath, $content);
92+
$entries = $this->accessor->getValue($row, $path);
93+
94+
if (count($entries) > 0) {
95+
foreach ($entries as $key => $entry) {
96+
$currentPath = $path . '[' . $key . ']' . $value;
97+
$currentObjectPath = Helper::getPropertyPathObjectNotation($path, $key, $value);
98+
99+
if (true === $this->isEditableContentRequired($row)) {
100+
$content = $this->renderTemplate(
101+
$this->accessor->getValue($row, $currentPath),
102+
$row[$this->editable->getPk()],
103+
$currentObjectPath
104+
);
105+
} else {
106+
$content = $this->renderTemplate($this->accessor->getValue($row, $currentPath));
107+
}
108+
109+
$this->accessor->setValue($row, $currentPath, $content);
110+
}
111+
} else {
112+
// no placeholder - leave this blank
104113
}
105-
} else {
106-
// no placeholder - leave this blank
114+
107115
}
108116

109117
return $this;

Datatable/Column/ImageColumn.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ public function renderSingleField(array &$row)
104104
{
105105
$path = Helper::getDataPropertyPath($this->data);
106106

107-
$content = $this->renderImageTemplate($this->accessor->getValue($row, $path), '-image');
107+
if ($this->accessor->isReadable($row, $path)) {
108108

109-
$this->accessor->setValue($row, $path, $content);
109+
$content = $this->renderImageTemplate($this->accessor->getValue($row, $path), '-image');
110+
111+
$this->accessor->setValue($row, $path, $content);
112+
113+
}
110114

111115
return $this;
112116
}
@@ -122,19 +126,23 @@ public function renderToMany(array &$row)
122126
$value = null;
123127
$path = Helper::getDataPropertyPath($this->data, $value);
124128

125-
$images = $this->accessor->getValue($row, $path);
129+
if ($this->accessor->isReadable($row, $path)) {
126130

127-
if (count($images) > 0) {
128-
foreach ($images as $key => $image) {
129-
$currentPath = $path.'['.$key.']'.$value;
130-
$content = $this->renderImageTemplate($this->accessor->getValue($row, $currentPath), '-gallery-image');
131+
$images = $this->accessor->getValue($row, $path);
132+
133+
if (count($images) > 0) {
134+
foreach ($images as $key => $image) {
135+
$currentPath = $path . '[' . $key . ']' . $value;
136+
$content = $this->renderImageTemplate($this->accessor->getValue($row, $currentPath), '-gallery-image');
137+
$this->accessor->setValue($row, $currentPath, $content);
138+
}
139+
} else {
140+
// create an entry for the placeholder image
141+
$currentPath = $path . '[0]' . $value;
142+
$content = $this->renderImageTemplate(null, '-gallery-image');
131143
$this->accessor->setValue($row, $currentPath, $content);
132144
}
133-
} else {
134-
// create an entry for the placeholder image
135-
$currentPath = $path.'[0]'.$value;
136-
$content = $this->renderImageTemplate(null, '-gallery-image');
137-
$this->accessor->setValue($row, $currentPath, $content);
145+
138146
}
139147

140148
return $this;

Datatable/Column/NumberColumn.php

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ public function renderSingleField(array &$row)
5757
{
5858
$path = Helper::getDataPropertyPath($this->data);
5959

60-
if (true === $this->isEditableContentRequired($row)) {
61-
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
62-
} else {
63-
$content = $this->renderTemplate($this->accessor->getValue($row, $path));
64-
}
60+
if ($this->accessor->isReadable($row, $path)) {
61+
62+
if (true === $this->isEditableContentRequired($row)) {
63+
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
64+
} else {
65+
$content = $this->renderTemplate($this->accessor->getValue($row, $path));
66+
}
67+
68+
$this->accessor->setValue($row, $path, $content);
6569

66-
$this->accessor->setValue($row, $path, $content);
70+
}
6771

6872
return $this;
6973
}
@@ -78,25 +82,29 @@ public function renderToMany(array &$row)
7882

7983
$entries = $this->accessor->getValue($row, $path);
8084

81-
if (count($entries) > 0) {
82-
foreach ($entries as $key => $entry) {
83-
$currentPath = $path.'['.$key.']'.$value;
84-
$currentObjectPath = Helper::getPropertyPathObjectNotation($path, $key, $value);
85-
86-
if (true === $this->isEditableContentRequired($row)) {
87-
$content = $this->renderTemplate(
88-
$this->accessor->getValue($row, $currentPath),
89-
$row[$this->editable->getPk()],
90-
$currentObjectPath
91-
);
92-
} else {
93-
$content = $this->renderTemplate($this->accessor->getValue($row, $currentPath));
94-
}
85+
if ($this->accessor->isReadable($row, $path)) {
86+
87+
if (count($entries) > 0) {
88+
foreach ($entries as $key => $entry) {
89+
$currentPath = $path . '[' . $key . ']' . $value;
90+
$currentObjectPath = Helper::getPropertyPathObjectNotation($path, $key, $value);
91+
92+
if (true === $this->isEditableContentRequired($row)) {
93+
$content = $this->renderTemplate(
94+
$this->accessor->getValue($row, $currentPath),
95+
$row[$this->editable->getPk()],
96+
$currentObjectPath
97+
);
98+
} else {
99+
$content = $this->renderTemplate($this->accessor->getValue($row, $currentPath));
100+
}
95101

96-
$this->accessor->setValue($row, $currentPath, $content);
102+
$this->accessor->setValue($row, $currentPath, $content);
103+
}
104+
} else {
105+
// no placeholder - leave this blank
97106
}
98-
} else {
99-
// no placeholder - leave this blank
107+
100108
}
101109

102110
return $this;

0 commit comments

Comments
 (0)