Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By claudiu.cristea on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
Site builders are able now to add 'alt' and 'title' attributes to the default image of an image field. The image field formatter will output the 'alt' and 'title' attributes along with 'width' and 'height' that are computed.
Internally the default image is represented now as an associative array instead of a file id reference integer. The default_image
field and instance setting is an associative array having the next keys:
fid
: File ID reference.alt
: The 'alt' attribute.title
: The 'title' attribute.width
: The default image width (computed).height
: The default image height (computed).
Drupal 7
function image_field_info() {
return array(
'image' => array(
...
'settings' => array(
...
'default_image' => 0,
),
'instance_settings' => array(
...
'default_image' => 0,
),
...
),
);
}
Drupal 8
/**
* Plugin implementation of the 'image' field type.
*
* @FieldType(
* id = "image",
...
* settings = {
...
* "default_image" = {
* "fid" = NULL,
* "alt" = "",
* "title" = "",
* "width" = NULL,
* "height" = NULL
* },
...
* },
* instance_settings = {
...
* "default_image" = {
* "fid" = NULL,
* "alt" = "",
* "title" = "",
* "width" = NULL,
* "height" = NULL
* }
* },
...
* )
*/
class ImageItem extends FileItem {
...
}
Impacts:
Site builders, administrators, editors
Module developers
Themers