Devise\Pages\Fields\Handlers\ImageFieldUpdated::handle PHP Method

handle() public method

This is called anytime after we update an image field in devise
public handle ( Field $field, array $input, $beforeChanges ) : array
$field Field
$input array
return array
    public function handle($field, $input, $beforeChanges)
    {
        $imageVersion = $this->createVersionOfImage($field, $input);
        $thumbnailVersion = $this->createThumbnailOfImage($field, $input);
        $this->saveCaption($imageVersion, $input);
        $field->values->merge(['has_thumbnail' => array_get($input, 'has_thumbnail', false), 'original' => array_get($input, 'image', ''), 'image' => $imageVersion, 'image_url' => $imageVersion, 'thumbnail' => $thumbnailVersion, 'thumbnail_url' => $thumbnailVersion]);
        $field->json_value = $field->values->toJSON();
        $field->save();
    }

Usage Example

Beispiel #1
0
 public function test_it_handles_provided_image_update()
 {
     $Images = m::mock('Devise\\Media\\Images\\Images');
     $MediaPathHelper = m::mock('Devise\\Media\\MediaPaths');
     $DvsField = m::mock('DvsField');
     $FieldValue = new FieldValue('{"image" : "/some/path/to/file.jpg"}');
     $MediaPathHelper->shouldReceive('basePath')->times(1)->andReturn('/');
     $MediaPathHelper->shouldReceive('isUrlPath')->andReturn(true);
     $DvsField->shouldReceive('getAttribute')->with('values')->andReturn($FieldValue);
     $DvsField->shouldReceive('setAttribute');
     $DvsField->shouldReceive('save')->times(1);
     $ImageFieldUpdated = new ImageFieldUpdated($Images, $MediaPathHelper);
     $ImageFieldUpdated->handle($DvsField, [], $DvsField);
     assertEquals('/some/path/to/file.jpg', $FieldValue->image_url);
 }