Repository: helsingborg-stad/Modularity
Pull request #836: fix: removes fields. Always use image contract.
Author: login: sebastianthulin
Created: 2025-04-02T09:28:54Z | Merged: 2025-04-02T11:45:41Z

This pull request includes significant changes to the handling of image fields and their associated metadata in the `mod-image` module. The changes involve updates to JSON and PHP files to streamline the image field definitions and remove unnecessary logic related to image size handling.

### Updates to image field definitions:

* [`source/php/AcfFields/json/mod-image.json`](diffhunk://#diff-e40cb5630e4a01775bccc61f32cb058af449dcaf8c51c3dceb862fa16fec116cR9): Updated field definitions to include `aria-label`, changed `return_format` from "array" to "id", and added `acfe_thumbnail` and `acfe_textarea_code` attributes. Removed fields related to custom image width, height, and size. [[1]](diffhunk://#diff-e40cb5630e4a01775bccc61f32cb058af449dcaf8c51c3dceb862fa16fec116cR9) [[2]](diffhunk://#diff-e40cb5630e4a01775bccc61f32cb058af449dcaf8c51c3dceb862fa16fec116cL18-R36) [[3]](diffhunk://#diff-e40cb5630e4a01775bccc61f32cb058af449dcaf8c51c3dceb862fa16fec116cL46-R57) [[4]](diffhunk://#diff-e40cb5630e4a01775bccc61f32cb058af449dcaf8c51c3dceb862fa16fec116cR83) [[5]](diffhunk://#diff-e40cb5630e4a01775bccc61f32cb058af449dcaf8c51c3dceb862fa16fec116cR108) [[6]](diffhunk://#diff-e40cb5630e4a01775bccc61f32cb058af449dcaf8c51c3dceb862fa16fec116cR141-R154)

* [`source/php/AcfFields/php/mod-image.php`](diffhunk://#diff-217fa24cbbeaad14717bf1df42b8a90d15d9454c5cf3ad0766c5365b8e36283bR12): Mirrored changes from the JSON file, including the addition of `aria-label`, changes to `return_format`, and the addition of `acfe_thumbnail` and `acfe_textarea_code`. Removed fields related to custom image width, height, and size. [[1]](diffhunk://#diff-217fa24cbbeaad14717bf1df42b8a90d15d9454c5cf3ad0766c5365b8e36283bR12) [[2]](diffhunk://#diff-217fa24cbbeaad14717bf1df42b8a90d15d9454c5cf3ad0766c5365b8e36283bL21-R39) [[3]](diffhunk://#diff-217fa24cbbeaad14717bf1df42b8a90d15d9454c5cf3ad0766c5365b8e36283bR54-R60) [[4]](diffhunk://#diff-217fa24cbbeaad14717bf1df42b8a90d15d9454c5cf3ad0766c5365b8e36283bL171-R86) [[5]](diffhunk://#diff-217fa24cbbeaad14717bf1df42b8a90d15d9454c5cf3ad0766c5365b8e36283bL195-R111) [[6]](diffhunk://#diff-217fa24cbbeaad14717bf1df42b8a90d15d9454c5cf3ad0766c5365b8e36283bR147-R160)

### Simplification of image handling logic:

* [`source/php/Module/Image/Image.php`](diffhunk://#diff-99229ed1d9c88af176ba198be682837b22b4d8b9689c13d2ddad90deca4ab39eL5): Removed the `appendImageSizes` method and related logic for handling custom image sizes. Simplified the `data` method to directly retrieve image data and metadata without checking for custom sizes. [[1]](diffhunk://#diff-99229ed1d9c88af176ba198be682837b22b4d8b9689c13d2ddad90deca4ab39eL5) [[2]](diffhunk://#diff-99229ed1d9c88af176ba198be682837b22b4d8b9689c13d2ddad90deca4ab39eL25-L26) [[3]](diffhunk://#diff-99229ed1d9c88af176ba198be682837b22b4d8b9689c13d2ddad90deca4ab39eL36-R94) [[4]](diffhunk://#diff-99229ed1d9c88af176ba198be682837b22b4d8b9689c13d2ddad90deca4ab39eL215-L229)

### Updates to image view:

* [`source/php/Module/Image/views/partials/image.blade.php`](diffhunk://#diff-d8c542aeb560f2e04cb348f6b4f58d2c1007190fed215897971d4f01b09bf4f3L2-R4): Simplified the image view by directly using the `image`, `caption`, and `byline` variables instead of accessing them from an array.


Diff:
diff --git a/source/php/AcfFields/json/mod-image.json b/source/php/AcfFields/json/mod-image.json
index a0d27d8a0..fd5e14e43 100644
--- a/source/php/AcfFields/json/mod-image.json
+++ b/source/php/AcfFields/json/mod-image.json
@@ -6,6 +6,7 @@
             "key": "field_570770b8e2e61",
             "label": "Image",
             "name": "mod_image_image",
+            "aria-label": "",
             "type": "image",
             "instructions": "Allowed file types: jpg, png, gif",
             "required": 1,
@@ -15,21 +16,24 @@
                 "class": "",
                 "id": ""
             },
-            "return_format": "array",
-            "preview_size": "medium",
-            "library": "all",
+            "uploader": "",
+            "return_format": "id",
+            "acfe_thumbnail": 0,
             "min_width": "",
             "min_height": "",
             "min_size": "",
             "max_width": "",
             "max_height": "",
             "max_size": "",
-            "mime_types": "jpg, png, gif"
+            "mime_types": "jpg, png, gif",
+            "preview_size": "medium",
+            "library": "all"
         },
         {
             "key": "field_587604df2975f",
             "label": "Image caption",
             "name": "mod_image_caption",
+            "aria-label": "",
             "type": "textarea",
             "instructions": "",
             "required": 0,
@@ -43,107 +47,14 @@
             "new_lines": "br",
             "maxlength": "",
             "placeholder": "",
-            "rows": 4
-        },
-        {
-            "key": "field_57077112e2e63",
-            "label": "Width",
-            "name": "mod_image_crop_width",
-            "type": "number",
-            "instructions": "",
-            "required": 1,
-            "conditional_logic": [
-                [
-                    {
-                        "field": "field_5707716fabf17",
-                        "operator": "==",
-                        "value": "custom"
-                    }
-                ]
-            ],
-            "wrapper": {
-                "width": "50",
-                "class": "",
-                "id": ""
-            },
-            "default_value": 1280,
-            "min": 1,
-            "max": "",
-            "placeholder": "",
-            "step": "",
-            "prepend": "",
-            "append": "pixels"
-        },
-        {
-            "key": "field_5707712be2e64",
-            "label": "Height",
-            "name": "mod_image_crop_height",
-            "type": "number",
-            "instructions": "",
-            "required": 1,
-            "conditional_logic": [
-                [
-                    {
-                        "field": "field_5707716fabf17",
-                        "operator": "==",
-                        "value": "custom"
-                    }
-                ]
-            ],
-            "wrapper": {
-                "width": "50",
-                "class": "",
-                "id": ""
-            },
-            "default_value": 720,
-            "min": 1,
-            "max": "",
-            "placeholder": "",
-            "step": "",
-            "prepend": "",
-            "append": "pixels"
-        },
-        {
-            "key": "field_5707716fabf17",
-            "label": "Image size",
-            "name": "mod_image_size",
-            "type": "select",
-            "instructions": "",
-            "required": 1,
-            "conditional_logic": [
-                [
-                    {
-                        "field": "field_570770b8e2e61",
-                        "operator": "!=empty"
-                    }
-                ]
-            ],
-            "wrapper": {
-                "width": "",
-                "class": "",
-                "id": ""
-            },
-            "choices": {
-                "thumbnail": "thumbnail",
-                "medium": "medium",
-                "medium_large": "medium_large",
-                "large": "large",
-                "1536x1536": "1536x1536",
-                "2048x2048": "2048x2048",
-                "custom": "Custom"
-            },
-            "default_value": false,
-            "return_format": "value",
-            "multiple": 0,
-            "allow_null": 0,
-            "ui": 0,
-            "ajax": 0,
-            "placeholder": ""
+            "rows": 4,
+            "acfe_textarea_code": 0
         },
         {
             "key": "field_577d07c8d72db",
             "label": "Link",
             "name": "mod_image_link",
+            "aria-label": "",
             "type": "radio",
             "instructions": "",
             "required": 1,
@@ -169,6 +80,7 @@
             "key": "field_577d0810d72dc",
             "label": "Link url",
             "name": "mod_image_link_url",
+            "aria-label": "",
             "type": "url",
             "instructions": "",
             "required": 1,
@@ -193,6 +105,7 @@
             "key": "field_577d0840d72dd",
             "label": "Link page",
             "name": "mod_image_link_url",
+            "aria-label": "",
             "type": "page_link",
             "instructions": "",
             "required": 1,
@@ -225,6 +138,20 @@
                 "value": "mod-image"
             }
         ],
+        [
+            {
+                "param": "block",
+                "operator": "==",
+                "value": "all"
+            }
+        ],
+        [
+            {
+                "param": "block",
+                "operator": "==",
+                "value": "all"
+            }
+        ],
         [
             {
                 "param": "block",
diff --git a/source/php/AcfFields/php/mod-image.php b/source/php/AcfFields/php/mod-image.php
index 56c444b79..1ced36e2f 100644
--- a/source/php/AcfFields/php/mod-image.php
+++ b/source/php/AcfFields/php/mod-image.php
@@ -9,6 +9,7 @@
             'key' => 'field_570770b8e2e61',
             'label' => __('Image', 'modularity'),
             'name' => 'mod_image_image',
+            'aria-label' => '',
             'type' => 'image',
             'instructions' => __('Allowed file types: jpg, png, gif', 'modularity'),
             'required' => 1,
@@ -18,9 +19,9 @@
                 'class' => '',
                 'id' => '',
             ),
-            'return_format' => 'array',
-            'preview_size' => 'medium',
-            'library' => 'all',
+            'uploader' => '',
+            'return_format' => 'id',
+            'acfe_thumbnail' => 0,
             'min_width' => '',
             'min_height' => '',
             'min_size' => '',
@@ -28,11 +29,14 @@
             'max_height' => '',
             'max_size' => '',
             'mime_types' => 'jpg, png, gif',
+            'preview_size' => 'medium',
+            'library' => 'all',
         ),
         1 => array(
             'key' => 'field_587604df2975f',
             'label' => __('Image caption', 'modularity'),
             'name' => 'mod_image_caption',
+            'aria-label' => '',
             'type' => 'textarea',
             'instructions' => '',
             'required' => 0,
@@ -47,106 +51,13 @@
             'maxlength' => '',
             'placeholder' => '',
             'rows' => 4,
+            'acfe_textarea_code' => 0,
         ),
         2 => array(
-            'key' => 'field_57077112e2e63',
-            'label' => __('Width', 'modularity'),
-            'name' => 'mod_image_crop_width',
-            'type' => 'number',
-            'instructions' => '',
-            'required' => 1,
-            'conditional_logic' => array(
-                0 => array(
-                    0 => array(
-                        'field' => 'field_5707716fabf17',
-                        'operator' => '==',
-                        'value' => 'custom',
-                    ),
-                ),
-            ),
-            'wrapper' => array(
-                'width' => '50',
-                'class' => '',
-                'id' => '',
-            ),
-            'default_value' => 1280,
-            'min' => 1,
-            'max' => '',
-            'placeholder' => '',
-            'step' => '',
-            'prepend' => '',
-            'append' => __('pixels', 'modularity'),
-        ),
-        3 => array(
-            'key' => 'field_5707712be2e64',
-            'label' => __('Height', 'modularity'),
-            'name' => 'mod_image_crop_height',
-            'type' => 'number',
-            'instructions' => '',
-            'required' => 1,
-            'conditional_logic' => array(
-                0 => array(
-                    0 => array(
-                        'field' => 'field_5707716fabf17',
-                        'operator' => '==',
-                        'value' => 'custom',
-                    ),
-                ),
-            ),
-            'wrapper' => array(
-                'width' => '50',
-                'class' => '',
-                'id' => '',
-            ),
-            'default_value' => 720,
-            'min' => 1,
-            'max' => '',
-            'placeholder' => '',
-            'step' => '',
-            'prepend' => '',
-            'append' => __('pixels', 'modularity'),
-        ),
-        4 => array(
-            'key' => 'field_5707716fabf17',
-            'label' => __('Image size', 'modularity'),
-            'name' => 'mod_image_size',
-            'type' => 'select',
-            'instructions' => '',
-            'required' => 1,
-            'conditional_logic' => array(
-                0 => array(
-                    0 => array(
-                        'field' => 'field_570770b8e2e61',
-                        'operator' => '!=empty',
-                    ),
-                ),
-            ),
-            'wrapper' => array(
-                'width' => '',
-                'class' => '',
-                'id' => '',
-            ),
-            'choices' => array(
-                'thumbnail' => __('thumbnail', 'modularity'),
-                'medium' => __('medium', 'modularity'),
-                'medium_large' => __('medium_large', 'modularity'),
-                'large' => __('large', 'modularity'),
-                '1536x1536' => __('1536x1536', 'modularity'),
-                '2048x2048' => __('2048x2048', 'modularity'),
-                'custom' => __('Custom', 'modularity'),
-            ),
-            'default_value' => false,
-            'return_format' => 'value',
-            'multiple' => 0,
-            'allow_null' => 0,
-            'ui' => 0,
-            'ajax' => 0,
-            'placeholder' => '',
-        ),
-        5 => array(
             'key' => 'field_577d07c8d72db',
             'label' => __('Link', 'modularity'),
             'name' => 'mod_image_link',
+            'aria-label' => '',
             'type' => 'radio',
             'instructions' => '',
             'required' => 1,
@@ -168,10 +79,11 @@
             'allow_null' => 0,
             'return_format' => 'value',
         ),
-        6 => array(
+        3 => array(
             'key' => 'field_577d0810d72dc',
             'label' => __('Link url', 'modularity'),
             'name' => 'mod_image_link_url',
+            'aria-label' => '',
             'type' => 'url',
             'instructions' => '',
             'required' => 1,
@@ -192,10 +104,11 @@
             'default_value' => '',
             'placeholder' => '',
         ),
-        7 => array(
+        4 => array(
             'key' => 'field_577d0840d72dd',
             'label' => __('Link page', 'modularity'),
             'name' => 'mod_image_link_url',
+            'aria-label' => '',
             'type' => 'page_link',
             'instructions' => '',
             'required' => 1,
@@ -231,6 +144,20 @@
             ),
         ),
         1 => array(
+            0 => array(
+                'param' => 'block',
+                'operator' => '==',
+                'value' => 'all',
+            ),
+        ),
+        2 => array(
+            0 => array(
+                'param' => 'block',
+                'operator' => '==',
+                'value' => 'all',
+            ),
+        ),
+        3 => array(
             0 => array(
                 'param' => 'block',
                 'operator' => '==',
diff --git a/source/php/Module/Image/Image.php b/source/php/Module/Image/Image.php
index 921f9f05b..2a60c1cae 100644
--- a/source/php/Module/Image/Image.php
+++ b/source/php/Module/Image/Image.php
@@ -2,7 +2,6 @@
 
 namespace Modularity\Module\Image;
 
-use Municipio\Helper\Image as ImageHelper;
 use Modularity\Integrations\Component\ImageResolver;
 use Modularity\Integrations\Component\ImageFocusResolver;
 use ComponentLibrary\Integrations\Image\Image as ImageComponentContract;
@@ -22,8 +21,6 @@ public function init()
         $this->nameSingular = __('Image', 'modularity');
         $this->namePlural = __('Images', 'modularity');
         $this->description = __('Outputs an image', 'modularity');
-
-        add_action('acf/load_field/name=mod_image_size', array($this, 'appendImageSizes'));
     }
 
     /**
@@ -33,173 +30,67 @@ public function init()
     public function data() : array
     {
 
-        //Get data
-        $data = [];
-        $fields = $this->getFields();
-
-        $image = $this->getImageData(
-            $fields, 
-            $this->getImageSize($fields)
-        ); 
+        //Declare default data
+        $data = [
+            'image' => false,
+            'link' => false,
+            'caption' => false,
+            'byline' => false,
+        ];
 
-        if($image) {
-            $data['image'] = $image;
-
-            //Resolve caption
-            $data['image']['caption'] = $this->getImageCaption(
-                $fields, 
-                $data['image']
-            );
-
-            //Get image size & id
-            $imageId = $this->getImageId($fields);
-            $imageSize = $this->getImageSize($fields);
-    
-            //Resolve image
-            if($imageSize !== null && $imageId !== null) {
-                $resolvedImage = ImageComponentContract::factory(
-                    $imageId,
-                    $imageSize,
-                    new ImageResolver(),
-                    new ImageFocusResolver('test')
-                );
-
-                $data['image']['src'] = $resolvedImage;
-            } else {
-                $data['image'] = false;
-            }
-        } else {
-            $data['image'] = false;
-        }
-        
-        $data['imageLink'] = $this->imageHasLink($fields) ? $fields['mod_image_link_url'] : false;
-
-        return $data;
-    }
+        // Get field definition
+        $fields = $this->getFields();
 
-    /**
-     * Get the image size
-     * 
-     * @param array $fields All the acf fields
-     * 
-     * @return array|null
-     */
-    private function getImageSize($fields): ?array {
-
-        //Return custom image size if set
-        if ($this->hasCustomImageSize($fields)) {
-            $size = [
-                $fields['mod_image_crop_width'] ?? false,
-                $fields['mod_image_crop_height'] ?? false
-            ];
+        // If the image is set, get the image data
+        $imageId = $fields['mod_image_image'] ?? null;
+        if(is_array($imageId)) {
+            $imageId = $imageId['ID'] ?? null;
         }
 
-        //Return predefined image size
-        if ($this->hasPredefinedImageSize($fields)) {
-            $size = $this->getRegisteredImageSize($fields['mod_image_size'], $fields);
-        }
+        if(is_numeric($imageId) && wp_attachment_is_image($imageId)) {
+            $data['image'] = ImageComponentContract::factory(
+                $imageId,
+                [1920, false],
+                new ImageResolver()
+            );
 
-        //Normalize types in array
-        if(is_array($size) && !empty($size)) {
-            array_walk($size, function(&$value) {
-                $value = is_numeric($value) ? (int)$value : (bool)$value;
-            });
-            return $size;
+            $data['caption']    = $this->getImageCaption($fields, $imageId);
+            $data['byline']     = $this->getImageByline($imageId);
         }
 
-        return null;
-    }
-
-    /**
-     * If the image has a predefined size.
-     * 
-     * @param array $fields All the acf fields
-     * @return bool
-     */
-    private function hasPredefinedImageSize(array $fields): bool {
-        return !empty($fields['mod_image_size']) && $fields['mod_image_size'] !== "custom";
-    }
+        //Get image link, if image is set and link is set
+        $data['link'] = $data['image'] && $this->imageHasLink($fields) ? $fields['mod_image_link_url'] : false;
 
-    /**
-     * Check if the image has a custom size.
-     *
-     * @param array $fields All the ACF fields.
-     * @return bool
-     */
-    private function hasCustomImageSize(array $fields): bool
-    {
-        // Check if 'mod_image_size' exists and is set to "custom"
-        $hasCustomSize = !empty($fields['mod_image_size']) && $fields['mod_image_size'] === "custom";
-
-        // Check if both width and height for the custom image crop are provided
-        $hasValidCropDimensions = !empty($fields['mod_image_crop_width']) && !empty($fields['mod_image_crop_height']);
-
-        // Return true only if both conditions are met
-        return $hasCustomSize && $hasValidCropDimensions;
+        return $data;
     }
 
     /**
-     * Get the registered image size.
+     * If the image should be a link or not.
      * 
-     * @param string $size The size to get
      * @param array $fields All the acf fields
-     * @return array|null
+     * @param array $imageId The image id
+     * @return string|false
      */
-    private function getRegisteredImageSize(?string $size, array $fields): ?array 
-    {
-        $sizes = $fields['mod_image_image']['sizes'] ?? []; 
-
-        if(array_key_exists($size, $sizes)) {
-            return [
-                $sizes[$size . '-width'],
-                $sizes[$size . '-height']
-            ];
+    private function getImageCaption(array $fields, int $imageId) {
+        $caption = wp_get_attachment_caption($imageId);
+        if (!empty($fields['mod_image_caption'])) {
+            $caption = $fields['mod_image_caption'];
         }
-        return null;
+        return strip_tags($caption);
     }
 
     /**
-     * Get the image id
+     * Get the byline for the image
      * 
-     * @param array $fields All the acf fields
-     * @return int|null
-     */
-    private function getImageId($fields): ?int {
-        return $fields['mod_image_image']['ID'] ?? null;
-    }
-
-    /**
-     * Get all data attached to the image.
-     * 
-     * @param array $fields All the acf fields
-     * @param array|string $size Array containing height and width OR predefined size as a string.
-     * @return array
-     */
-    private function getImageData(array $fields, $size)
-    {
-        $imageId = $fields['mod_image_image']['ID']; 
-        return ImageHelper::getImageAttachmentData($imageId, $size);
-    }
-
-    /**
-     * If the image should be a link or not.
-     * 
-     * @param array $fields All the acf fields
-     * @param array $image All the data attached to the image
+     * @param int $imageId The image id
      * @return string|false
      */
-    private function getImageCaption(array $fields, array $image) {
-        $caption = false;
-
-        if (!empty($image['caption'])) {
-            $caption = $image['caption'];
-        }
-
-        if (!empty($fields['mod_image_caption'])) {
-            $caption = $fields['mod_image_caption'];
+    private function getImageByline($imageId) {
+        $meta = wp_get_attachment_metadata($imageId);
+        if (isset($meta['image_meta']['byline'])) {
+            return $meta['image_meta']['byline'];
         }
-        
-        return $caption;
+        return false;
     }
 
     /**
@@ -212,21 +103,6 @@ private function imageHasLink(array $fields) {
         return !empty($fields['mod_image_link']) && $fields['mod_image_link'] != "false" && !empty($fields['mod_image_link_url']);
     }
 
-    /**
-     * Creates a list of predefined sizes to choose from
-     * @return array
-     */
-     public function appendImageSizes(array $field)
-     {
-        $sizes = get_intermediate_image_sizes();
-
-        foreach ($sizes as $size) {
-            $field['choices'][$size] = $size;
-        }
-
-        return $field;
-     }
-
     /**
      * Choose appropriate style
      * @return string
diff --git a/source/php/Module/Image/views/partials/image.blade.php b/source/php/Module/Image/views/partials/image.blade.php
index e3fe9ad3e..175b6d2d3 100644
--- a/source/php/Module/Image/views/partials/image.blade.php
+++ b/source/php/Module/Image/views/partials/image.blade.php
@@ -1,8 +1,7 @@
 @image([
-    'src'           => $image['src'] ?? false,
-    'alt'           => $image['alt'] ?? "",
-    'caption'       => $image['caption'] ?? "",
-    'byline'        => $image['byline'] ?? "",
+    'src'           => $image,
+    'caption'       => $caption,
+    'byline'        => $byline,
     'context'       => ['module.image', $sidebarContext . '.module.image', $sidebarContext . '.animation-item'],
 ])
 @endimage
\ No newline at end of file


Reviews:
user: login: NiclasNorin
body: 🏅
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-02T11:33:48Z
user: login: thorbrink
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-02T11:35:18Z
user: login: thorbrink
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-02T11:36:23Z

Review comments:
diff_hunk: @@ -33,173 +30,68 @@ public function init()
     public function data() : array
     {
 
-        //Get data
-        $data = [];
-        $fields = $this->getFields();
-
-        $image = $this->getImageData(
-            $fields, 
-            $this->getImageSize($fields)
-        ); 
+        //Declare default data
+        $data = [
+            'image' => false,
+            'link' => false,
+            'caption' => false,
+            'byline' => false,
+        ];
 
-        if($image) {
-            $data['image'] = $image;
-
-            //Resolve caption
-            $data['image']['caption'] = $this->getImageCaption(
-                $fields, 
-                $data['image']
-            );
+        // Get field definition
+        $fields = $this->getFields();
 
-            //Get image size & id
-            $imageId = $this->getImageId($fields);
-            $imageSize = $this->getImageSize($fields);
-    
-            //Resolve image
-            if($imageSize !== null && $imageId !== null) {
-                $resolvedImage = ImageComponentContract::factory(
-                    $imageId,
-                    $imageSize,
-                    new ImageResolver(),
-                    new ImageFocusResolver('test')
-                );
-
-                $data['image']['src'] = $resolvedImage;
-            } else {
-                $data['image'] = false;
-            }
-        } else {
-            $data['image'] = false;
+        // If the image is set, get the image data
+        $imageId = $fields['mod_image_image'] ?? null;
+        if(is_array($imageId)) {
+            $imageId = $imageId['ID'] ?? null;
         }
-        
-        $data['imageLink'] = $this->imageHasLink($fields) ? $fields['mod_image_link_url'] : false;
-
-        return $data;
-    }
 
-    /**
-     * Get the image size
-     * 
-     * @param array $fields All the acf fields
-     * 
-     * @return array|null
-     */
-    private function getImageSize($fields): ?array {
-
-        //Return custom image size if set
-        if ($this->hasCustomImageSize($fields)) {
-            $size = [
-                $fields['mod_image_crop_width'] ?? false,
-                $fields['mod_image_crop_height'] ?? false
-            ];
-        }
+        if(is_numeric($imageId) && wp_attachment_is_image($imageId)) {
+            $data['image'] = ImageComponentContract::factory(
+                $imageId,
+                [1920, false],
+                new ImageResolver(),
+                new ImageFocusResolver('test')
path: source/php/Module/Image/Image.php
user: login: thorbrink
body: Should "test" be the input param here?
created_at: 2025-04-02T11:35:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -33,173 +30,68 @@ public function init()
     public function data() : array
     {
 
-        //Get data
-        $data = [];
-        $fields = $this->getFields();
-
-        $image = $this->getImageData(
-            $fields, 
-            $this->getImageSize($fields)
-        ); 
+        //Declare default data
+        $data = [
+            'image' => false,
+            'link' => false,
+            'caption' => false,
+            'byline' => false,
+        ];
 
-        if($image) {
-            $data['image'] = $image;
-
-            //Resolve caption
-            $data['image']['caption'] = $this->getImageCaption(
-                $fields, 
-                $data['image']
-            );
+        // Get field definition
+        $fields = $this->getFields();
 
-            //Get image size & id
-            $imageId = $this->getImageId($fields);
-            $imageSize = $this->getImageSize($fields);
-    
-            //Resolve image
-            if($imageSize !== null && $imageId !== null) {
-                $resolvedImage = ImageComponentContract::factory(
-                    $imageId,
-                    $imageSize,
-                    new ImageResolver(),
-                    new ImageFocusResolver('test')
-                );
-
-                $data['image']['src'] = $resolvedImage;
-            } else {
-                $data['image'] = false;
-            }
-        } else {
-            $data['image'] = false;
+        // If the image is set, get the image data
+        $imageId = $fields['mod_image_image'] ?? null;
+        if(is_array($imageId)) {
+            $imageId = $imageId['ID'] ?? null;
         }
-        
-        $data['imageLink'] = $this->imageHasLink($fields) ? $fields['mod_image_link_url'] : false;
-
-        return $data;
-    }
 
-    /**
-     * Get the image size
-     * 
-     * @param array $fields All the acf fields
-     * 
-     * @return array|null
-     */
-    private function getImageSize($fields): ?array {
-
-        //Return custom image size if set
-        if ($this->hasCustomImageSize($fields)) {
-            $size = [
-                $fields['mod_image_crop_width'] ?? false,
-                $fields['mod_image_crop_height'] ?? false
-            ];
-        }
+        if(is_numeric($imageId) && wp_attachment_is_image($imageId)) {
+            $data['image'] = ImageComponentContract::factory(
+                $imageId,
+                [1920, false],
+                new ImageResolver(),
+                new ImageFocusResolver('test')
+            );
 
-        //Return predefined image size
-        if ($this->hasPredefinedImageSize($fields)) {
-            $size = $this->getRegisteredImageSize($fields['mod_image_size'], $fields);
+            $data['caption']    = $this->getImageCaption($fields, $imageId);
+            $data['byline']     = $this->getImageByline($imageId);
         }
 
-        //Normalize types in array
-        if(is_array($size) && !empty($size)) {
-            array_walk($size, function(&$value) {
-                $value = is_numeric($value) ? (int)$value : (bool)$value;
-            });
-            return $size;
-        }
+        //Get image link, if image is set and link is set
+        $data['link'] = $data['image'] && $this->imageHasLink($fields) ? $fields['mod_image_link_url'] : false;
 
-        return null;
-    }
-
-    /**
-     * If the image has a predefined size.
-     * 
-     * @param array $fields All the acf fields
-     * @return bool
-     */
-    private function hasPredefinedImageSize(array $fields): bool {
-        return !empty($fields['mod_image_size']) && $fields['mod_image_size'] !== "custom";
-    }
-
-    /**
-     * Check if the image has a custom size.
-     *
-     * @param array $fields All the ACF fields.
-     * @return bool
-     */
-    private function hasCustomImageSize(array $fields): bool
-    {
-        // Check if 'mod_image_size' exists and is set to "custom"
-        $hasCustomSize = !empty($fields['mod_image_size']) && $fields['mod_image_size'] === "custom";
-
-        // Check if both width and height for the custom image crop are provided
-        $hasValidCropDimensions = !empty($fields['mod_image_crop_width']) && !empty($fields['mod_image_crop_height']);
-
-        // Return true only if both conditions are met
-        return $hasCustomSize && $hasValidCropDimensions;
+        return $data;
     }
 
     /**
-     * Get the registered image size.
+     * If the image should be a link or not.
path: source/php/Module/Image/Image.php
user: login: thorbrink
body: Stämmer denna doc? Verkar inte så när man läser koden.
created_at: 2025-04-02T11:36:23Z
author_association: CONTRIBUTOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2025-04-02T11:39:41Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=helsingborg-stad_Modularity&pullRequest=836) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=helsingborg-stad_Modularity&pullRequest=836&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=helsingborg-stad_Modularity&pullRequest=836&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=helsingborg-stad_Modularity&pullRequest=836&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=helsingborg-stad_Modularity&pullRequest=836&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=helsingborg-stad_Modularity&pullRequest=836&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=helsingborg-stad_Modularity&pullRequest=836)


author_association: NONE