Пример #1
0
 /**
  * @param ScaffoldFieldRendererConfig|DataRendererConfig $rendererConfig
  * @param ScaffoldFieldConfig|ItemDetailsFieldConfig $fieldConfig
  */
 protected function configureDefaultRenderer(ScaffoldFieldRendererConfig $rendererConfig, ScaffoldFieldConfig $fieldConfig)
 {
     switch ($fieldConfig->getType()) {
         case $fieldConfig::TYPE_IMAGE:
             $rendererConfig->setView('cmf::details.image');
             break;
         case $fieldConfig::TYPE_BOOL:
             $rendererConfig->setView('cmf::details.bool');
             break;
         case $fieldConfig::TYPE_JSON_TREE:
             $rendererConfig->setView('cmf::details.json_tree');
             break;
         default:
             $rendererConfig->setView('cmf::details.text');
     }
 }
Пример #2
0
 /**
  * @param string $type
  * @return $this
  */
 public function setType($type)
 {
     parent::setType($type);
     switch ($this->type) {
         case self::TYPE_BOOL:
             $this->setValueConverter(function ($value) {
                 return CmfConfig::transBase('.datagrid.field.bool.' . ($value ? 'yes' : 'no'));
             });
             break;
     }
     return $this;
 }
Пример #3
0
 public function setIsDbField($isDbField)
 {
     if (!$isDbField) {
         $this->setIsSortable(false);
     }
     return parent::setIsDbField($isDbField);
 }
Пример #4
0
 /**
  * @param ScaffoldFieldConfig|DataGridFieldConfig $fieldConfig
  * @return int
  */
 protected function getNextFieldPosition(ScaffoldFieldConfig $fieldConfig)
 {
     if ($fieldConfig->isVisible()) {
         /** @var DataGridFieldConfig $otherFieldConfig */
         $count = 0;
         foreach ($this->fields as $otherFieldConfig) {
             if ($otherFieldConfig->isVisible()) {
                 $count++;
             }
         }
         return $count;
     } else {
         return -1;
     }
 }
Пример #5
0
 /**
  * @param string $name
  * @param null|ScaffoldFieldConfig $config
  * @return $this
  * @throws \PeskyORM\Exception\DbModelException
  * @throws \PeskyCMF\Scaffold\ScaffoldException
  * @throws ScaffoldActionException
  */
 public function addField($name, $config = null)
 {
     if ((!$config || $config->isDbField()) && !$this->getModel()->hasTableColumn($name)) {
         throw new ScaffoldActionException($this, "Unknown table column [{$name}]");
     }
     if (empty($config)) {
         $config = $this->createFieldConfig();
     }
     $config->setName($name);
     $config->setPosition($this->getNextFieldPosition($config));
     $config->setScaffoldActionConfig($this);
     $this->fields[$name] = $config;
     return $this;
 }
Пример #6
0
 /**
  * @param InputRendererConfig|ScaffoldFieldRendererConfig $rendererConfig
  * @param FormFieldConfig|ScaffoldFieldConfig $fieldConfig
  * @throws \PeskyCMF\Scaffold\ScaffoldException
  * @throws \PeskyORM\Exception\DbColumnConfigException
  * @throws \PeskyCMF\Scaffold\ScaffoldFieldException
  */
 protected function configureDefaultRenderer(ScaffoldFieldRendererConfig $rendererConfig, ScaffoldFieldConfig $fieldConfig)
 {
     switch ($fieldConfig->getType()) {
         case $fieldConfig::TYPE_BOOL:
             $rendererConfig->setView('cmf::input/trigger');
             break;
         case $fieldConfig::TYPE_HIDDEN:
             $rendererConfig->setView('cmf::input/hidden');
             break;
         case $fieldConfig::TYPE_TEXT:
             $rendererConfig->setView('cmf::input/textarea');
             break;
         case $fieldConfig::TYPE_WYSIWYG:
             $rendererConfig->setView('cmf::input/wysiwyg');
             break;
         case $fieldConfig::TYPE_SELECT:
             $rendererConfig->setView('cmf::input/select')->setOptions($fieldConfig->getOptions());
             break;
         case $fieldConfig::TYPE_MULTISELECT:
             $rendererConfig->setView('cmf::input/multiselect')->setOptions($fieldConfig->getOptions());
             if (!$fieldConfig->hasValueConverter() && in_array($fieldConfig->getTableColumnConfig()->getType(), [FormFieldConfig::TYPE_JSON, FormFieldConfig::TYPE_JSONB], true)) {
                 $fieldConfig->setValueConverter(function ($value) {
                     return $value;
                 });
             }
             break;
         case $fieldConfig::TYPE_TAGS:
             $rendererConfig->setView('cmf::input/tags');
             $options = $fieldConfig->getOptions();
             if (!empty($options)) {
                 $rendererConfig->setOptions($options);
             }
             if (!$fieldConfig->hasValueConverter() && in_array($fieldConfig->getTableColumnConfig()->getType(), [FormFieldConfig::TYPE_JSON, FormFieldConfig::TYPE_JSONB], true)) {
                 $fieldConfig->setValueConverter(function ($value) {
                     return $value;
                 });
             }
             break;
         case $fieldConfig::TYPE_IMAGE:
             $rendererConfig->setView('cmf::input/image');
             break;
         case $fieldConfig::TYPE_DATETIME:
             $rendererConfig->setView('cmf::input/datetime');
             break;
         case $fieldConfig::TYPE_DATE:
             $rendererConfig->setView('cmf::input/date');
             break;
         case $fieldConfig::TYPE_EMAIL:
             $rendererConfig->setView('cmf::input/text')->setAttributes(['type' => 'email']);
             break;
         case $fieldConfig::TYPE_PASSWORD:
             $rendererConfig->setView('cmf::input/password');
             break;
         default:
             $rendererConfig->setView('cmf::input/text');
     }
     if ($fieldConfig->isDbField()) {
         $this->configureRendererByColumnConfig($rendererConfig, $fieldConfig->getTableColumnConfig());
     }
     if ($fieldConfig->hasDefaultRendererConfigurator()) {
         call_user_func($fieldConfig->getDefaultRendererConfigurator(), $rendererConfig, $fieldConfig);
     }
 }