Skip to content

Commit

Permalink
Rework more code.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Nov 27, 2023
1 parent 779a0c5 commit d5bec54
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"require": {
"php": ">=8.1",
"oomphinc/composer-installers-extender": "^2.0",
"php-forge/html": "dev-main",
"yii2-extensions/asset-bootstrap5": "dev-main",
"yiisoft/yii2": "*"
},
Expand Down
21 changes: 5 additions & 16 deletions src/Summernote.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
namespace Yii2\Extensions\Summernote;

use JsonException;
use PHPForge\Html\Helper\Utils;
use PHPForge\Html\TextArea;
use Yii2\Extensions\Summernote\Asset\SummernoteAsset;
use Yii;
use yii\helpers\Html;
use yii\widgets\InputWidget;

final class Summernote extends InputWidget
Expand All @@ -29,7 +28,7 @@ public function init(): void

$this->config = array_merge(['lang' => Yii::$app->language], $this->config);
$this->id = $this->hasModel()
? Utils::generateInputId($this->model->formName(), $this->attribute)
? Html::getInputId($this->model, $this->attribute)
: $this->getId() . '-summernote';
}

Expand Down Expand Up @@ -76,21 +75,11 @@ private function registerClientScript(): void
*/
private function renderTextArea(): string
{
unset($this->options['id']);

$textArea = TextArea::widget()->attributes($this->options);
$this->options['id'] = $this->id;

return match ($this->hasModel()) {
true => $textArea
->content((string) $this->model->{$this->attribute})
->id($this->id)
->name(Utils::generateInputName($this->model->formName(), $this->attribute))
->render(),
default => $textArea
->content((string) $this->value)
->id($this->id)
->name($this->name)
->render(),
true => Html::activeTextArea($this->model, $this->attribute, $this->options),
default => Html::textArea($this->name, $this->value, $this->options),
};
}
}
2 changes: 1 addition & 1 deletion tests/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function testOptions(): void

$this->assertSame(
<<<HTML
<textarea class="test-class" id="testform-content" name="TestForm[content]"></textarea>
<textarea id="testform-content" class="test-class" name="TestForm[content]"></textarea>
HTML,
$filePond,
);
Expand Down

0 comments on commit d5bec54

Please sign in to comment.