示例#1
0
文件: Date.php 项目: deadem/djem
 public function prepareUserValue($value, $getValue = null)
 {
     if (empty($value)) {
         $value = null;
     }
     return parent::prepareUserValue($value, $getValue);
 }
示例#2
0
文件: RichText.php 项目: deadem/djem
 public function prepareUserValue($value, $getValue = null)
 {
     if (empty($this->images) || empty($this->imageSaveHandler)) {
         return parent::prepareUserValue($value, $getValue);
     }
     $value = preg_replace_callback('/(<img.*?src=\\s*([\'"]))(.*?)(\\2)/is', function ($matches) use($getValue) {
         if (preg_match('/^blob:http.*?#(.+)$/i', $matches[3], $urls)) {
             $relation = call_user_func($getValue->relation, $this->images);
             $file = $this->normalizeImageExtension($this->getFilePath($urls[1]));
             $value = call_user_func($this->imageSaveHandler, ['file' => $file], $relation->getRelated(), $getValue);
             if ($value) {
                 $this->relatedData[] = ['relation' => $relation, 'value' => $value];
                 return $matches[1] . htmlentities($value->url) . $matches[4];
             }
         }
         return $matches[0];
     }, $value);
     parent::prepareUserValue($value, $getValue);
 }
示例#3
0
文件: Image.php 项目: deadem/djem
 public function prepareUserValue($value, $getValue = null)
 {
     if (is_array($value)) {
         $value = array_shift($value);
     }
     if (empty($value)) {
         foreach ($this->copy as $field) {
             $parentValue = call_user_func($getValue->field, $field);
             if (is_array($parentValue)) {
                 $parentValue = array_shift($parentValue);
             }
             if (!empty($parentValue) && isset($parentValue['file'])) {
                 $value = $parentValue;
                 break;
             }
         }
     }
     if (!empty($value)) {
         if (isset($value['file'])) {
             // если указан файл - это новая картинка, загружаем
             $value['file'] = $this->normalizeImageExtension($this->getFilePath($value['file']));
             foreach ($this->images as $image) {
                 $image->setUserValue($this->prepareUserSaveValue($value, $image->getName(), $getValue));
             }
             return parent::prepareUserValue($value, $getValue);
         }
         // если файл не указан, значит нужно обновить данные уже подцепленной картинки
         foreach ($this->images as $image) {
             $relation = call_user_func($getValue->relation, $image->getName());
             $image->setUserValue($relation->first());
         }
         $relation = call_user_func($getValue->relation, $this->getName());
         return $this->setUserValue($relation->first());
     }
     return $this;
 }