mirror of
https://github.com/cjango/dcat-vue.git
synced 2025-12-07 15:10:04 +08:00
新增(覆盖)tags表单组件
This commit is contained in:
77
src/Field/Tag.php
Normal file
77
src/Field/Tag.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
|
||||
class Tag extends Field\Tags
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::tag';
|
||||
|
||||
public function render()
|
||||
{
|
||||
/****************************** parent ************************************/
|
||||
$value = Helper::array($this->value());
|
||||
|
||||
if ($this->options instanceof \Closure) {
|
||||
$this->options(
|
||||
$this->options->call($this->values(), $value, $this)
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->keyAsValue) {
|
||||
$options = $value + $this->options;
|
||||
} else {
|
||||
$options = array_unique(array_merge($value, (array) $this->options));
|
||||
}
|
||||
|
||||
$this->addVariables([
|
||||
'options' => $options,
|
||||
'keyAsValue' => $this->keyAsValue,
|
||||
]);
|
||||
|
||||
/****************************** end parent ************************************/
|
||||
|
||||
/****************************** field ************************************/
|
||||
|
||||
if (!$this->shouldRender()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->setDefaultClass();
|
||||
|
||||
$this->callComposing();
|
||||
|
||||
$this->withScript();
|
||||
|
||||
/****************************** end field ************************************/
|
||||
|
||||
$this->withProvides();
|
||||
|
||||
$this->addVariables([
|
||||
'provides' => $this->variables(),
|
||||
]);
|
||||
|
||||
return view($this->view(), $this->variables());
|
||||
}
|
||||
|
||||
protected function formatAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
protected function withProvides()
|
||||
{
|
||||
$this->addVariables([
|
||||
'component' => 'Tag',
|
||||
]);
|
||||
}
|
||||
|
||||
public function max(int $max): self
|
||||
{
|
||||
$this->addVariables(['max' => $max]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user