['user_id', 'user_ids', 'admin_id', 'admin_ids'], ]; /** * Selectpage对应的后缀 */ protected $selectpageSuffix = ['_id', '_ids']; /** * Selectpage多选对应的后缀 */ protected $selectpagesSuffix = ['_ids']; /** * 保留字段 */ protected $reservedField = ['admin_id']; /** * 排除字段 */ protected $ignoreFields = []; /** * 排序字段 */ protected $sortField = 'listorder'; /** * 以指定字符结尾的字段格式化函数 */ protected $fieldFormatterSuffix = [ 'status' => ['type' => ['varchar', 'enum'], 'name' => 'status'], 'icon' => 'icon', 'flag' => 'flag', 'url' => 'url', 'image' => 'image', 'images' => 'images', 'file' => 'file', 'files' => 'files', 'avatar' => 'image', 'switch' => 'switch', 'tag' => 'flag', 'tags' => 'flag', 'time' => ['type' => ['int', 'bigint', 'timestamp'], 'name' => 'datetime'], ]; /** * 识别为图片字段 */ protected $imageField = ['image', 'images', 'avatar', 'avatars', 'thumb']; /** * 识别为文件字段 */ protected $fileField = ['file', 'files']; /** * 筛选字段 * @var string */ protected $headingFilterField = 'status'; /** * 添加时间字段 * @var string */ protected $createTimeField = 'create_time'; /** * 更新时间字段 * @var string */ protected $updateTimeField = 'update_time'; /** * 软删除时间字段 * @var string */ protected $deleteTimeField = 'delete_time'; /** * 语言包 */ protected $langList = []; /** * 编辑器的Class */ protected $editorClass = 'editor'; /** * langList的key最长字节数 */ protected $fieldMaxLen = 0; protected function configure() { $this->setName('crud') ->addOption('table', 't', Option::VALUE_REQUIRED, 'table name without prefix', null) ->addOption('controller', 'c', Option::VALUE_OPTIONAL, 'controller name', null) ->addOption('model', 'm', Option::VALUE_OPTIONAL, 'model name', null) ->addOption('fields', 'i', Option::VALUE_OPTIONAL, 'model visible fields', null) ->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override or force delete,without tips', null) ->addOption('local', 'l', Option::VALUE_OPTIONAL, 'local model', 1) ->addOption('menu', 'u', Option::VALUE_OPTIONAL, 'create menu when CRUD completed', null) ->addOption('delete', 'd', Option::VALUE_OPTIONAL, 'delete all files generated by CRUD', null) ->addOption('relation', 'r', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'relation table name without prefix', null) ->addOption('relationmodel', 'e', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'relation model name', null) ->addOption('relationforeignkey', 'k', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'relation foreign key', null) ->addOption('relationprimarykey', 'p', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'relation primary key', null) ->addOption('relationfields', 's', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'relation table fields', null) ->addOption('relationmode', 'o', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'relation table mode,hasone/belongsto/hasmany', null) ->addOption('relationcontroller', 'w', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'relation table controller,only work at hasmany mode', null) ->addOption('setcheckboxsuffix', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate checkbox component with suffix', null) ->addOption('enumradiosuffix', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate radio component with suffix', null) ->addOption('imagefield', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate image component with suffix', null) ->addOption('filefield', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate file component with suffix', null) ->addOption('tagsuffix', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate tag component with suffix', null) ->addOption('intdatesuffix', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate date component with suffix', null) ->addOption('switchsuffix', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate switch component with suffix', null) ->addOption('editorsuffix', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate editor component with suffix', null) ->addOption('citysuffix', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate citypicker component with suffix', null) ->addOption('jsonsuffix', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate fieldlist component with suffix', null) ->addOption('selectpagesuffix', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate selectpage component with suffix', null) ->addOption('selectpagessuffix', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'automatically generate multiple selectpage component with suffix', null) ->addOption('editorclass', null, Option::VALUE_OPTIONAL, 'automatically generate editor class', null) ->addOption('sortfield', null, Option::VALUE_OPTIONAL, 'sort field', null) ->addOption('ignorefields', null, Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'ignore fields', null) ->addOption('db', null, Option::VALUE_OPTIONAL, 'database config name', 'database') ->setDescription('Build CRUD controller and model from table'); } protected function execute(Input $input, Output $output) { $adminPath = dirname(__DIR__) . DS; //数据库 $db = $input->getOption('db'); //表名 $table = $input->getOption('table') ?: ''; if (!$table) { throw new Exception('table name can\'t empty'); } //自定义控制器 $controller = $input->getOption('controller'); //自定义模型 $model = $input->getOption('model'); $model = $model ?: $controller; //验证器类 $validate = $model; //自定义显示字段 $fields = $input->getOption('fields'); //是否生成菜单 $menu = $input->getOption("menu"); //关联表 $relation = $input->getOption('relation'); //自定义关联表模型 $relationModels = $input->getOption('relationmodel'); //模式 $relationMode = $mode = $input->getOption('relationmode'); //外键 $relationForeignKey = $input->getOption('relationforeignkey'); //主键 $relationPrimaryKey = $input->getOption('relationprimarykey'); //关联表显示字段 $relationFields = $input->getOption('relationfields'); //关联表显示字段 $relationController = $input->getOption('relationcontroller'); //强制覆盖 $force = $input->getOption('force'); //是否为本地model,为0时表示为全局model将会把model放在app/common/model中 $local = $input->getOption('local'); //复选框后缀 $setcheckboxsuffix = $input->getOption('setcheckboxsuffix'); //单选框后缀 $enumradiosuffix = $input->getOption('enumradiosuffix'); //图片后缀 $imagefield = $input->getOption('imagefield'); //文件后缀 $filefield = $input->getOption('filefield'); //标签后缀 $tagsuffix = $input->getOption('tagsuffix'); //日期后缀 $intdatesuffix = $input->getOption('intdatesuffix'); //开关后缀 $switchsuffix = $input->getOption('switchsuffix'); //富文本编辑器 $editorsuffix = $input->getOption('editorsuffix'); //城市后缀 $citysuffix = $input->getOption('citysuffix'); //JSON配置后缀 $jsonsuffix = $input->getOption('jsonsuffix'); //selectpage后缀 $selectpagesuffix = $input->getOption('selectpagesuffix'); //selectpage多选后缀 $selectpagessuffix = $input->getOption('selectpagessuffix'); //排除字段 $ignoreFields = $input->getOption('ignorefields'); //排序字段 $sortfield = $input->getOption('sortfield'); //编辑器Class $editorclass = $input->getOption('editorclass'); if ($setcheckboxsuffix) { $this->setCheckboxSuffix = $setcheckboxsuffix; } if ($enumradiosuffix) { $this->enumRadioSuffix = $enumradiosuffix; } if ($imagefield) { $this->imageField = $imagefield; } if ($filefield) { $this->fileField = $filefield; } if ($tagsuffix) { $this->tagSuffix = $tagsuffix; } if ($intdatesuffix) { $this->intDateSuffix = $intdatesuffix; } if ($switchsuffix) { $this->switchSuffix = $switchsuffix; } if ($editorsuffix) { $this->editorSuffix = $editorsuffix; } if ($citysuffix) { $this->citySuffix = $citysuffix; } if ($jsonsuffix) { $this->jsonSuffix = $jsonsuffix; } if ($selectpagesuffix) { $this->selectpageSuffix = $selectpagesuffix; } if ($selectpagessuffix) { $this->selectpagesSuffix = $selectpagessuffix; } if ($ignoreFields) { $this->ignoreFields = $ignoreFields; } if ($editorclass) { $this->editorClass = $editorclass; } if ($sortfield) { $this->sortField = $sortfield; } $this->reservedField = array_merge($this->reservedField, [$this->createTimeField, $this->updateTimeField, $this->deleteTimeField]); $dbconnect = Db::connect('mysql'); $dbname = Config::get($db . '.database'); $prefix = Config::get($db . '.prefix'); //系统表无法生成,防止后台错乱 if (in_array(str_replace($prefix, "", $table), $this->systemTables)) { throw new Exception('system table can\'t be crud'); } //模块 $moduleName = 'admin'; $modelModuleName = $local ? $moduleName : 'common'; $validateModuleName = $local ? $moduleName : 'common'; //检查主表 $modelName = $table = stripos($table, $prefix) === 0 ? substr($table, strlen($prefix)) : $table; $modelTableType = 'table'; $modelTableTypeName = $modelTableName = $modelName; $modelTableInfo = $dbconnect->query("SHOW TABLE STATUS LIKE '{$modelTableName}'", [], true); if (!$modelTableInfo) { $modelTableType = 'name'; $modelTableName = $prefix . $modelName; $modelTableInfo = $dbconnect->query("SHOW TABLE STATUS LIKE '{$modelTableName}'", [], true); if (!$modelTableInfo) { throw new Exception("table not found"); } } $modelTableInfo = $modelTableInfo[0]; $relations = []; //检查关联表 if ($relation) { $relationArr = $relation; $relations = []; foreach ($relationArr as $index => $relationTable) { $relationName = stripos($relationTable, $prefix) === 0 ? substr($relationTable, strlen($prefix)) : $relationTable; $relationTableType = 'table'; $relationTableTypeName = $relationTableName = $relationName; $relationTableInfo = $dbconnect->query("SHOW TABLE STATUS LIKE '{$relationTableName}'", [], true); if (!$relationTableInfo) { $relationTableType = 'name'; $relationTableName = $prefix . $relationName; $relationTableInfo = $dbconnect->query("SHOW TABLE STATUS LIKE '{$relationTableName}'", [], true); if (!$relationTableInfo) { throw new Exception("relation table not found"); } } $relationTableInfo = $relationTableInfo[0]; $relationModel = $relationModels[$index] ?? ''; list($relationNamespace, $relationName, $relationFile) = $this->getModelData($modelModuleName, $relationModel, $relationName); $relations[] = [ //关联表基础名 'relationName' => $relationName, //关联表类命名空间 'relationNamespace' => $relationNamespace, //关联模型名 'relationModel' => $relationModel, //关联文件 'relationFile' => $relationFile, //关联表名称 'relationTableName' => $relationTableName, //关联表信息 'relationTableInfo' => $relationTableInfo, //关联模型表类型(name或table) 'relationTableType' => $relationTableType, //关联模型表类型名称 'relationTableTypeName' => $relationTableTypeName, //关联模式 'relationFields' => isset($relationFields[$index]) ? explode(',', $relationFields[$index]) : [], //关联模式 'relationMode' => $relationMode[$index] ?? 'belongsto', //关联模型控制器 'relationController' => $relationController[$index] ?? '', //关联表外键 'relationForeignKey' => $relationForeignKey[$index] ?? '', //关联表主键 'relationPrimaryKey' => $relationPrimaryKey[$index] ?? '', ]; } } //控制器 list($controllerNamespace, $controllerName, $controllerFile, $controllerArr) = $this->getControllerData($moduleName, $controller, $table); //模型 list($modelNamespace, $modelName, $modelFile, $modelArr) = $this->getModelData($modelModuleName, $model, $table); //验证器 list($validateNamespace, $validateName, $validateFile, $validateArr) = $this->getValidateData($validateModuleName, $validate, $table); //处理基础文件名,取消所有下划线并转换为小写 $baseNameArr = $controllerArr; $baseFileName = Loader::parseName(array_pop($baseNameArr), 0); array_push($baseNameArr, $baseFileName); $controllerUrl = $this->getControllerUrl($moduleName, $baseNameArr); //视图文件 $viewArr = $controllerArr; $lastValue = array_pop($viewArr); $viewArr[] = Loader::parseName($lastValue, 0); array_unshift($viewArr, 'view'); $viewDir = $adminPath . strtolower(implode(DS, $viewArr)) . DS; //最终将生成的文件路径 $addFile = $viewDir . 'add.html'; $editFile = $viewDir . 'edit.html'; $indexFile = $viewDir . 'index.html'; $recyclebinFile = $viewDir . 'recyclebin.html'; //是否为删除模式 $delete = $input->getOption('delete'); if ($delete) { $readyFiles = [$controllerFile, $modelFile, $validateFile, $addFile, $editFile, $indexFile, $recyclebinFile]; foreach ($readyFiles as $k => $v) { $output->warning($v); } if (!$force) { $question = $output->confirm($input, "Are you sure you want to delete all those files? Type 'yes' to continue: ", false); if (!$question) { throw new Exception("Operation is aborted!"); } } foreach ($readyFiles as $k => $v) { if (file_exists($v)) { unlink($v); } //删除空文件夹 switch ($v) { case $modelFile: $this->removeEmptyBaseDir($v, $modelArr); break; case $validateFile: $this->removeEmptyBaseDir($v, $validateArr); break; case $addFile: case $editFile: case $indexFile: case $recyclebinFile: $this->removeEmptyBaseDir($v, $viewArr); break; default: $this->removeEmptyBaseDir($v, $controllerArr); } } //继续删除菜单 if ($menu) { //exec("php think menu -c {$controllerUrl} -d 1 -f 1"); \think\Console::call('menu', ["--controller={$controllerUrl}", "--delete=1", "--force=1"]); } $output->info("Delete Successed"); return; } //非覆盖模式时如果存在控制器文件则报错 if (is_file($controllerFile) && !$force) { throw new Exception("controller already exists!\nIf you need to rebuild again, use the parameter --force=true "); } //非覆盖模式时如果存在模型文件则报错 if (is_file($modelFile) && !$force) { throw new Exception("model already exists!\nIf you need to rebuild again, use the parameter --force=true "); } //非覆盖模式时如果存在验证文件则报错 if (is_file($validateFile) && !$force) { throw new Exception("validate already exists!\nIf you need to rebuild again, use the parameter --force=true "); } //从数据库中获取表字段信息 $sql = "SELECT * FROM `information_schema`.`columns` " . "WHERE TABLE_SCHEMA = ? AND table_name = ? " . "ORDER BY ORDINAL_POSITION"; //加载主表的列 $columnList = $dbconnect->query($sql, [$dbname, $modelTableName]); $fieldArr = []; foreach ($columnList as $v) { $fieldArr[] = $v['COLUMN_NAME']; } // 加载关联表的列 foreach ($relations as &$relation) { $relationColumnList = $dbconnect->query($sql, [$dbname, $relation['relationTableName']]); $relationFieldList = []; foreach ($relationColumnList as $v) { $relationFieldList[] = $v['COLUMN_NAME']; } if (!$relation['relationPrimaryKey']) { foreach ($relationColumnList as $v) { if ($v['COLUMN_KEY'] == 'PRI') { $relation['relationPrimaryKey'] = $v['COLUMN_NAME']; break; } } } // 如果主键为空 if (!$relation['relationPrimaryKey']) { throw new Exception('Relation Primary key not found!'); } // 如果主键不在表字段中 if (!in_array($relation['relationPrimaryKey'], $relationFieldList)) { throw new Exception('Relation Primary key not found in table!'); } $relation['relationColumnList'] = $relationColumnList; $relation['relationFieldList'] = $relationFieldList; } unset($relation); $addList = []; $editList = []; $javascriptList = []; $field = 'id'; $order = 'id'; $priDefined = false; $priKeyArr = []; $relationPrimaryKey = ''; foreach ($columnList as $v) { if ($v['COLUMN_KEY'] == 'PRI') { $priKeyArr[] = $v['COLUMN_NAME']; } } if (!$priKeyArr) { throw new Exception('Primary key not found!'); } if (count($priKeyArr) > 1) { throw new Exception('Multiple primary key not support!'); } $priKey = reset($priKeyArr); $order = $priKey; //如果是关联模型 foreach ($relations as &$relation) { if ($relation['relationMode'] == 'hasone') { $relationForeignKey = $relation['relationForeignKey'] ?: $table . "_id"; $relationPrimaryKey = $relation['relationPrimaryKey'] ?: $priKey; if (!in_array($relationForeignKey, $relation['relationFieldList'])) { throw new Exception('relation table [' . $relation['relationTableName'] . '] must be contain field [' . $relationForeignKey . ']'); } if (!in_array($relationPrimaryKey, $fieldArr)) { throw new Exception('table [' . $modelTableName . '] must be contain field [' . $relationPrimaryKey . ']'); } } elseif ($relation['relationMode'] == 'belongsto') { $relationForeignKey = $relation['relationForeignKey'] ?: Loader::parseName($relation['relationName']) . "_id"; $relationPrimaryKey = $relation['relationPrimaryKey'] ?: $relation['relationPriKey']; if (!in_array($relationForeignKey, $fieldArr)) { throw new Exception('table [' . $modelTableName . '] must be contain field [' . $relationForeignKey . ']'); } if (!in_array($relationPrimaryKey, $relation['relationFieldList'])) { throw new Exception('relation table [' . $relation['relationTableName'] . '] must be contain field [' . $relationPrimaryKey . ']'); } } elseif ($relation['relationMode'] == 'hasmany') { $relationForeignKey = $relation['relationForeignKey'] ?: $table . "_id"; $relationPrimaryKey = $relation['relationPrimaryKey'] ?: $priKey; if (!in_array($relationForeignKey, $relation['relationFieldList'])) { throw new Exception('relation table [' . $relation['relationTableName'] . '] must be contain field [' . $relationForeignKey . ']'); } if (!in_array($relationPrimaryKey, $fieldArr)) { throw new Exception('table [' . $modelTableName . '] must be contain field [' . $relationPrimaryKey . ']'); } $relation['relationColumnList'] = []; $relation['relationFieldList'] = []; } $relation['relationForeignKey'] = $relationForeignKey; $relation['relationPrimaryKey'] = $relationPrimaryKey; $relation['relationClassName'] = $modelNamespace != $relation['relationNamespace'] ? $relation['relationNamespace'] . '\\' . $relation['relationName'] : $relation['relationName']; } unset($relation); try { $setAttrArr = []; $getAttrArr = []; $appendAttrList = []; $getEnumArr = []; $controllerAssignList = []; $recyclebinHtml = ""; foreach ($columnList as $v) { $field = $v['COLUMN_NAME']; $itemArr = []; // 这里构建Enum和Set类型的列表数据 if (in_array($v['DATA_TYPE'], ['enum', 'set', 'tinyint']) || $this->headingFilterField == $field) { if ($v['DATA_TYPE'] !== 'tinyint') { $itemArr = substr($v['COLUMN_TYPE'], strlen($v['DATA_TYPE']) + 1, -1); $itemArr = explode(',', str_replace("'", '', $itemArr)); } $itemArr = $this->getItemArray($itemArr, $field, $v['COLUMN_COMMENT']); //如果类型为tinyint且有使用备注数据 if ($itemArr && !in_array($v['DATA_TYPE'], ['enum', 'set'])) { $v['DATA_TYPE'] = 'enum'; } } // 语言列表 if ($v['COLUMN_COMMENT'] != '') { $this->getLangItem($field, $v['COLUMN_COMMENT']); } $inputType = ''; //保留字段不能修改和添加 if ($v['COLUMN_KEY'] != 'PRI' && !in_array($field, $this->reservedField) && !in_array($field, $this->ignoreFields)) { $inputType = $this->getFieldType($v); // 如果是number类型时增加一个步长 $step = $inputType == 'number' && $v['NUMERIC_SCALE'] > 0 ? "0." . str_repeat(0, $v['NUMERIC_SCALE'] - 1) . "1" : 0; $attrArr = ['id' => "c-{$field}"]; $cssClassArr = []; $fieldName = "row[{$field}]"; $defaultValue = $v['COLUMN_DEFAULT']; $editValue = "{\$data.{$field}}"; // 如果默认值非null,则是一个必选项 if ($v['IS_NULLABLE'] == 'NO') { $attrArr['lay-verify'] = 'required'; } //如果字段类型为无符号型,则设置 if (stripos($v['COLUMN_TYPE'], 'unsigned') !== false) { $attrArr['min'] = 0; } if ($inputType == 'select') { $templateName = $v['DATA_TYPE'] == 'set' ? 'selects' : 'select'; $fieldList = $this->getFieldListName($field); $attrArr['name'] = $fieldName; $this->getEnum($getEnumArr, $controllerAssignList, $field, $itemArr, $v['DATA_TYPE'] == 'set' ? 'multiple' : 'select'); //添加一个获取器 $this->getAttr($getAttrArr, $field, $v['DATA_TYPE'] == 'set' ? 'multiple' : 'select'); if ($v['DATA_TYPE'] == 'set') { $fieldList = '{$' . $fieldList . '|json_encode}'; $this->setAttr($setAttrArr, $field, $inputType); } $this->appendAttr($appendAttrList, $field); $formAddElement = $this->getReplacedStub('html/' . $templateName, ['field' => $field, 'fieldName' => $fieldName, 'fieldList' => $fieldList, 'attrStr' => \Form::attributes($attrArr), 'selectedValue' => $defaultValue]); $formEditElement = $this->getReplacedStub('html/' . $templateName, ['field' => $field, 'fieldName' => $fieldName, 'fieldList' => $fieldList, 'attrStr' => \Form::attributes($attrArr), 'selectedValue' => $editValue]); } elseif ($inputType == 'datetime') { $format = "YYYY-MM-DD HH:mm:ss"; $phpFormat = "Y-m-d H:i:s"; $fieldFunc = ''; switch ($v['DATA_TYPE']) { case 'year': $format = "YYYY"; $phpFormat = 'Y'; $attrArr['data-date-type'] = 'year'; break; case 'date': $format = "YYYY-MM-DD"; $phpFormat = 'Y-m-d'; $attrArr['data-date-type'] = 'date'; break; case 'time': $format = "HH:mm:ss"; $phpFormat = 'H:i:s'; $attrArr['data-date-type'] = 'time'; break; case 'timestamp': $fieldFunc = 'time_format'; $attrArr['data-date-type'] = 'datetime'; // no break case 'datetime': $format = "YYYY-MM-DD HH:mm:ss"; $phpFormat = 'Y-m-d H:i:s'; break; default: $fieldFunc = 'time_format'; $this->getAttr($getAttrArr, $field, $inputType); $this->setAttr($setAttrArr, $field, $inputType); $this->appendAttr($appendAttrList, $field); break; } $defaultDateTime = "{:date('{$phpFormat}')}"; $formAddElement = \Form::datetime($fieldName, $defaultDateTime, $attrArr); $formEditElement = \Form::datetime($fieldName, ($fieldFunc ? "{:\$data.{$field}?{$fieldFunc}(\$data.{$field}):''}" : "{\$data.{$field}{$fieldFunc}}"), $attrArr); } elseif ($inputType == 'datetimerange') { $attrArr['data-date-range'] = '-'; $defaultDateTime = ""; $formAddElement = \Form::datetime($fieldName, $defaultDateTime, $attrArr); $formEditElement = \Form::datetime($fieldName, $editValue, $attrArr); } elseif ($inputType == 'checkbox' || $inputType == 'radio') { unset($attrArr['lay-verify']); $fieldName = $inputType == 'checkbox' ? $fieldName .= "[]" : $fieldName; $attrArr['name'] = "row[{$fieldName}]"; $this->getEnum($getEnumArr, $controllerAssignList, $field, $itemArr, $inputType); //添加一个获取器 $this->getAttr($getAttrArr, $field, $inputType); if ($inputType == 'checkbox') { $this->setAttr($setAttrArr, $field, $inputType); } $this->appendAttr($appendAttrList, $field); $defaultValue = $inputType == 'radio' && !$defaultValue ? key($itemArr) : $defaultValue; $formAddElement = $this->getReplacedStub('html/' . $inputType, ['field' => $field, 'fieldName' => $fieldName, 'fieldList' => $this->getFieldListName($field), 'attrStr' => \Form::attributes($attrArr), 'selectedValue' => $defaultValue]); $formEditElement = $this->getReplacedStub('html/' . $inputType, ['field' => $field, 'fieldName' => $fieldName, 'fieldList' => $this->getFieldListName($field), 'attrStr' => \Form::attributes($attrArr), 'selectedValue' => "\$data.{$field}"]); } elseif ($inputType == 'textarea' && !$this->isMatchSuffix($field, $this->selectpagesSuffix) && !$this->isMatchSuffix($field, $this->imageField)) { $cssClassArr[] = $this->isMatchSuffix($field, $this->editorSuffix) ? $this->editorClass : ''; $attrArr['class'] = implode(' ', $cssClassArr); $attrArr['rows'] = 5; $formAddElement = \Form::textarea($fieldName, $defaultValue, $attrArr); $formEditElement = \Form::textarea($fieldName, $editValue, $attrArr); } elseif ($inputType == 'switch') { $formAddElement = $this->getReplacedStub('html/' . $inputType, ['field' => $field, 'fieldName' => $fieldName, 'attrStr' => \Form::attributes($attrArr), 'fieldValue' => $defaultValue]); $formEditElement = $this->getReplacedStub('html/' . $inputType, ['field' => $field, 'fieldName' => $fieldName, 'attrStr' => \Form::attributes($attrArr), 'fieldValue' => "data.{$field}"]); } elseif ($inputType == 'citypicker') { $attrArr['class'] = implode(' ', $cssClassArr); $attrArr['data-toggle'] = "city-picker"; $formAddElement = sprintf("