Skip to content

Commit

Permalink
Use absolute path for dragText with parent #2003
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico Hoffmann committed Sep 14, 2019
1 parent 9bb2a44 commit 6b2157a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/fields/files.php
Expand Up @@ -112,7 +112,7 @@
$field = $this->field();
$uploads = $field->uploads();

return $field->upload($this, $uploads, function ($file) use ($field) {
return $field->upload($this, $uploads, function ($file, $parent) use ($field) {
return $file->panelPickerData([
'image' => $field->image(),
'info' => $field->info(),
Expand Down
2 changes: 1 addition & 1 deletion config/fields/mixins/upload.php
Expand Up @@ -64,7 +64,7 @@
throw new Exception('The file could not be uploaded');
}

return $map($file);
return $map($file, $parent);
});
}
]
Expand Down
11 changes: 9 additions & 2 deletions config/fields/textarea.php
Expand Up @@ -95,10 +95,17 @@
[
'pattern' => 'upload',
'action' => function () {
return $this->field()->upload($this, $this->field()->uploads(), function ($file) {
$field = $this->field();
$uploads = $field->uploads();

return $this->field()->upload($this, $uploads, function ($file, $parent) use ($field) {

$dragTextType = (option('panel.kirbytext') ?? true) ? 'kirbytext' : 'markdown';
$dragTextAbsolute = $field->model()->is($parent) === false;

return [
'filename' => $file->filename(),
'dragText' => $file->dragText(),
'dragText' => $file->dragText($dragTextType, $dragTextAbsolute),
];
});
}
Expand Down
14 changes: 12 additions & 2 deletions tests/Form/Fields/TextareaFieldTest.php
Expand Up @@ -2,8 +2,6 @@

namespace Kirby\Form\Fields;

use Kirby\Form\Field;

class TextareaFieldTest extends TestCase
{
public function testDefaultProps()
Expand Down Expand Up @@ -129,6 +127,18 @@ public function testUploadsDisabled()
$this->assertFalse($field->uploads());
}

public function testUploadsParent()
{
$field = $this->field('textarea', [
'value' => 'test',
'uploads' => [
'parent' => 'page.parent'
]
]);

$this->assertEquals(['parent' => 'page.parent', 'accept' => '*'], $field->uploads());
}

public function testUploadsTemplate()
{
$field = $this->field('textarea', [
Expand Down

0 comments on commit 6b2157a

Please sign in to comment.