示例#1
0
 /**
  * Load entity data by ID
  *
  * @param int|null $id
  * @return $this
  */
 public function loadEntityData($id = null)
 {
     if (is_null($id)) {
         return $this;
     }
     $this->model = $this->model->getOrm()->whereEq($this->model->getIdField(), $id)->fetchModel();
     if (empty($this->model)) {
         return $this;
     }
     $this->setFormValues($this->model->asArray());
     foreach ($this->scaffold->getEntityFields($this->entity) as $field) {
         $fieldConfig = $this->scaffold->getEntityFieldConfig($this->entity, $field);
         if ((bool) (string) $fieldConfig->allow_null) {
             if (is_null($this->model->{$field})) {
                 $checkboxNull = $this->getElementByName("set-null[{$field}]");
                 if ($checkboxNull instanceof \Magelight\Webform\Blocks\Elements\Checkbox) {
                     $checkboxNull->setChecked();
                 }
             }
         }
     }
     return $this;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function beforeToHtml()
 {
     $this->tableFields = $this->scaffold->getEntityFields($this->entity);
     return parent::beforeToHtml();
 }