51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Picea\Ui\Form;
|
|
|
|
use Picea\Ui\Common\UiElement;
|
|
use Picea\Extension\Extension;
|
|
use Picea\Extension\ExtensionTrait;
|
|
|
|
class UiImage extends UiElement implements Extension {
|
|
use ExtensionTrait;
|
|
|
|
public array $tokens = [ "ui:img", "ui:image" ];
|
|
|
|
public string $tag = "img";
|
|
|
|
public array $attributes = [
|
|
'class' => 'ui-image',
|
|
];
|
|
|
|
public array $options = [
|
|
'tag-type' => "single",
|
|
];
|
|
|
|
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
|
{
|
|
return "<?php echo ( new \\" . static::class . "() )->buildHtml($arguments) ?>";
|
|
}
|
|
|
|
public function buildHtml(string $source, array $attributes = [], array $options = []) : string
|
|
{
|
|
if ($options) {
|
|
$this->options += $options;
|
|
}
|
|
|
|
if ($attributes['class'] ?? false) {
|
|
$attributes['class'] .= " {$this->attributes['class']}";
|
|
|
|
unset($this->attributes['class']);
|
|
}
|
|
|
|
$this->attributes([ 'src' => $source ] + $attributes + $this->attributes + $this->objectAttribute());
|
|
|
|
return $this->render();
|
|
}
|
|
|
|
protected function objectAttribute() : array
|
|
{
|
|
return [];
|
|
}
|
|
}
|