Skip to content

ImageAsset Field Type

ImageAsset Field Type enables storing images in independent Content items of a generic Image Content Type, in the media library. It makes them reusable across system.

Input expectations

Example array:

Type Description Example
eZ\Publish\Core\FieldType\ImageAsset\Value ImageAsset Field Type value object. See below.
eZ\Publish\API\Repository\Values\Content\ContentInfo ContentInfo instance of the Asset Content item. n/a
string ID of the Asset Content item. "150"
integer ID of the Asset Content item. 150

Value object

Properties

Value object of ezimageasset contains the following properties:

Property Type Description
destinationContentId int Related content ID.
alternativeText string The alternative image text (for example "Picture of an apple.").
1
2
3
4
// Value object content example

$imageAssetValue->destinationContentId = $contentInfo->id;
$imageAssetValue->alternativeText = "Picture of an apple.";
Constructor

The ImageAsset\Value constructor will initialize a new value object with the value provided. It expects an ID of a Content item representing asset and the alternative text.

1
2
3
4
// Constructor example

// Instantiates a ImageAsset Value object
$imageAssetValue  = new ImageAsset\Value($contentInfo->id, "Picture of an apple.");

Validation

This Field Type validates if:

  • destinationContentId points to a Content item which has correct Content Type

Configuration

ImageAsset Field Type allows configuring the following options:

Name Description Default value
content_type_identifier Content Type used to store assets. image
content_field_identifier Field identifier used for asset data. image
name_field_identifier Field identifier used for asset name. name
parent_location_id Location where the assets are created. 51

Example configuration:

1
2
3
4
5
6
7
8
9
ezplatform:
    system:
       default:
            fieldtypes:
                ezimageasset:
                    content_type_identifier: photo
                    content_field_identifier: image
                    name_field_identifier: title
                    parent_location_id: 106

Customizing ImageAsset Field Type rendering

Internally the Image Asset Type is rendered via subrequest (similar to other relation types). Rendering customization is possible by configuring view type asset_image:

1
2
3
4
5
6
7
8
ezplatform:
    system:
       default:           
            content_view:
                asset_image:
                    default:
                        template: ::custom_image_asset_template.html.twig
                        match: []

Generating image variation from the Image Asset

Thanks to the eZ\Bundle\EzPublishCoreBundle\Imagine\ImageAsset\AliasGenerator decorator you can work with \eZ\Publish\SPI\Variation\VariationHandler in the same way as with Image Field Type.