spacecatninja / craft-imager-x

Image transforms, optimizations and manipulations for your Craft CMS site.
Other
26 stars 16 forks source link

Target an image handle for auto generation only inside a matrix #39

Open alexroper opened 4 years ago

alexroper commented 4 years ago

I'm submitting a...

Description

Is it possible to target an image handle inside a specific matrix field for auto transform generation? Can I do this without targeting all fields with the same handles?

Say I have a matrix field named content with a block type named carousel and a field inside that with the handle of image.

This seems to work:

'fields' => [
    'image' => ['myTransform'],
],

But this doesn't:

'fields' => [
    'content:carousel.image' => ['myTransform'],
],

The format that uses <matrixFieldHandle>:<matrixTypeHandle>.<fieldHandle> only seems to work with elements.

'elements' => [
    [
        'elementType' =>  \craft\elements\Entry::class,
        'criteria' => [
            'section' => ['news'],
        ],
        'fields' => ['content:carousel.image'],
        'transforms' => ['myTransform']
    ],
],

Is this working correctly or am I doing something wrong?

Additional info

aelvan commented 4 years ago

No, you're right, the matrix field handle syntax only works inside the elements functionality. Supporting it in the general fields functionality was a bit tricky, so I dropped it initially. But I'll leave this open and revisit it down the line.

FWIW, if you drop the criteria in an elements definition, it'll do the same thing. But you'll have to define it for each element type of course.

alexroper commented 4 years ago

Thanks. I thought that's how it worked but just wanted to make sure I wasn't missing something.

I realized this wouldn't be too painful if I just combine several sections in the element criteria. Didn't occur to me I could do that at first.

return [
    'elements' => [
        [
            'elementType' => \craft\elements\Entry::class,
            'criteria' => [
                'section' => ['news', 'about', 'blog', 'contact'],
            ],
            'fields' => ['pageContent:image.image'],
            'transforms' => ['imageBlock']
        ],
    ]
];
daniellelecomte commented 3 years ago

Is it possible to target an image inside of a super-table field in the same way that you can for a matrix field? <matrixFieldHandle>:<matrixTypeHandle>.<fieldHandle>

alexroper commented 3 years ago

@daniellelecomte I don't think so. My experiments with targeting image transforms inside a Super Table field haven't worked at all. But maybe I'm doing something wrong. ¯\_(ツ)_/¯

aelvan commented 3 years ago

@daniellelecomte It's not at the moment, but shouldn't be too difficult to add. File a separate FR if you want me to look into it.