Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

[3.4-dev] Include blank option for image size selects #7436

Closed
ausi opened this issue Nov 12, 2014 · 31 comments
Closed

[3.4-dev] Include blank option for image size selects #7436

ausi opened this issue Nov 12, 2014 · 31 comments
Labels
Milestone

Comments

@ausi
Copy link
Member

ausi commented Nov 12, 2014

If you create a new image content element in Contao 3.3 the size is set to ['', '', 'proportional'] which doesn't resize the image because no dimensions are set.

If you do the same in Contao 3.4 size is set to something like ['', '', '1'] which does resize the image because '1' is the ID of an image size.

We should set 'includeBlankOption' => true for all image size fields.

@aschempp
Copy link
Member

That would be a BC break with all existing extensions.

@ausi
Copy link
Member Author

ausi commented Nov 12, 2014

Why?

"Old" extensions wouldn't use System::getImageSizes() so they don't need to set 'includeBlankOption' => true

@leofeyer leofeyer added this to the 3.4.0 milestone Nov 12, 2014
@leofeyer
Copy link
Member

Hm, this is a problem indeed. But includeBlankOption does not seem a good solution, does it? How does Contao behave, if an empty value is passed?

@aschempp
Copy link
Member

Well if width & height are empty, the third flag should be completely ignored. That should also be the case in the future, no matter if it's 1 or proportional.

(I have not checked any code yet).

@leofeyer
Copy link
Member

Well if width & height are empty, the third flag should be completely ignored.

That's not possible, because when you select a predefined image set, width and height are always empty.

@ausi
Copy link
Member Author

ausi commented Nov 13, 2014

If the resize mode is an image size ID, width and height are ignored.

If it's not, and width and height are empty, the resize mode gets ignored, see system/modules/core/library/Contao/Image.php:408-413

So ['', '', 'proportional'] and ['', '', ''] produce the same result.

@leofeyer
Copy link
Member

Why is it that in Contao 3.4 the size is set to ['', '', '1'] instead of ['', '', 'proportional'] by default?

@ausi
Copy link
Member Author

ausi commented Nov 13, 2014

Because the image sizes are listed at the top of the select list (which is IMO correct) and because there is no blank option the first item gets selected by the browser.

@leofeyer
Copy link
Member

So if there are no custom images, the default selection is still ['', '', 'proportional']?

@ausi
Copy link
Member Author

ausi commented Nov 13, 2014

Yes.

@ausi
Copy link
Member Author

ausi commented Nov 13, 2014

We could also move the image sizes to the bottom of the list to fix this issue, but i don't like that.

@leofeyer
Copy link
Member

I think we can leave it as is. Actually, I think it is good that Contao uses a predefined dimension as default if there is one. And if there are none, it behaves exactly like before, so everything is fine to me.

@ausi
Copy link
Member Author

ausi commented Nov 13, 2014

But if I don't want to resize an image I have to select "proportional" which is confusing IMO.

@leofeyer
Copy link
Member

Oh, now I see what you mean. Then why don't we add the includeBlankOption flag? :D

Sorry, sometimes its hard to understand things from reading tickets only.

@aschempp
Copy link
Member

The blank option is confusing too, because then I can enter width & height and nothing will happen because no resize mode is selected…

@ausi
Copy link
Member Author

ausi commented Nov 13, 2014

We could update the script to disable the width and height fields if the blank option is selected.

@leofeyer
Copy link
Member

Good idea.

@leofeyer
Copy link
Member

We could also – for the sake of backwards compatibility – preselect the "proportional" option if no selection has been made.

@leofeyer
Copy link
Member

This would solve the problem:

            'load_callback' => array
            (
                function($val)
                {
                    if (empty($val))
                    {
                        $val = serialize(array('', '', 'proportional'));
                    }

                    return $val;
                }
            ),

@ausi @aschempp What do you think?

@leofeyer
Copy link
Member

And this would solve the issue in the ImageSize class:

    public function generate()
    {
        if (!is_array($this->varValue))
        {
            $this->varValue = array($this->varValue);
        }

        // Set the default value (see #7436)
        if (!isset($this->varValue[2]))
        {
            $this->varValue[2] = 'proportional';
        }

        // Backwards compatibility (see #3911)
        elseif ($this->varValue[2] == 'crop')
        {
            $this->varValue[2] = 'center_center';
        }

        ...

Probably even better, because it does not require to adjust the DCA files.

@ausi
Copy link
Member Author

ausi commented Nov 13, 2014

I still don't like having to select "proportional" to disable resizing, even if it is the default. What about adding a none option to System::getImageSizes()?

static::$arrImageSizes = array_merge(array('none', 'image_sizes' => $sizes), $GLOBALS['TL_CROP']);

@aschempp
Copy link
Member

Would not solve my previous comment:

The blank option is confusing too, because then I can enter width & height and nothing will happen because no resize mode is selected…

@ausi
Copy link
Member Author

ausi commented Nov 13, 2014

Updating the script to disable the width and height fields if none is selected would solve it, right?

assets/contao/js/core-uncompressed.js:2026:

if (select.get('value') === 'none' || select.get('value').toInt().toString() === select.get('value')) {

@leofeyer
Copy link
Member

I still don't like having to select "proportional" to disable resizing, even if it is the default.

Me neither. But I'd prefer to keep the behavior of the previous Contao versions for the sake of consistency. Still I wouldn't mind having a blank/none option with the input fields disabled. You two just have to manage to agree to something now :)

@aschempp
Copy link
Member

Can you point me to some code about the new image size options? I must admit I don't know anything about them yet. Maybe @Toflar can help here too?

@ausi
Copy link
Member Author

ausi commented Nov 14, 2014

DCA image size: system/modules/core/dca/tl_content.php:246-255

System::getImageSizes(): system/modules/core/library/Contao/System.php:480-510

JS which disables/enables width and height fields: assets/contao/js/core-uncompressed.js:2017-2048

@leofeyer
Copy link
Member

If we really cannot agree on a solution, it will be up to @ausi to make the decision, because it kind of is "his" feature ;)

@ausi
Copy link
Member Author

ausi commented Nov 14, 2014

I would go with 'includeBlankOption' => true and update assets/contao/js/core-uncompressed.js:2026 to:

if (select.get('value') === '' || ...

@Toflar
Copy link
Member

Toflar commented Nov 14, 2014

I agree with @ausi. I'd do the same.

@aschempp
Copy link
Member

Fine with me :)

@leofeyer
Copy link
Member

Changed in 7ec91ee.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants