Jump to content

Add additonal settings to image field in template context


Juergen
 Share

Recommended Posts

Hello,

I am trying to add additional settings to an image field depending on template context with this piece of code inside my ready.php:

//Image field
$wire->addHookMethod('FieldtypeImage::getConfigAllowContext', function (HookEvent $e) {
    $allowables = ['minWidth', 'minHeight', 'noLang', 'clientQuality'];
    $e->return = array_merge($e->return, $allowables);
});

Unfortunately the settings will not be displayed if I am inside the template fields settings page. Can someone help me out what is missing in this case?

Thanks

Link to comment
Share on other sites

No this is correct in this case (take a look at https://abdus.co/blog/doing-more-with-fewer-fields-in-processwire/), but it seems that the settings I want to include are not supported in this case.

This example from Abdus blog works:

$this->addHookMethod('FieldtypeFile::getConfigAllowContext', function (HookEvent $e) {
    $allowables = ['maxFiles', 'defaultValuePage', 'outputFormat'];
    $e->return = array_merge($e->return, $allowables);
});

In this case it doesnt matter if you use "FieldtypeImage" or "FieldtypeFile" - both work. The settings "maxFiles, defaultValuePage and outputFormat" work, but "minWidth, minHeight" and so on not.:(

Link to comment
Share on other sites

These are the only settings that I found that may work:

$allowables = ['maxFiles', 'defaultValuePage', 'outputFormat', 'extensions', 'outputString', 'useTags', 'tagsList'];

But what I need is to add "minWidth" at least, because I have very large images for a slider too. Therefore I need to adjust this setting. Otherwise I have to create a new image field for the slider images.

Link to comment
Share on other sites

Thanks @Zeka

I know about this and the Hook a few post above works, but only for specific settings. Taking a closer look at "getConfigAllowContext" shows that the settings I want to include are not defined as configurable in getConfigAllowContext. So for the moment it is not possible to add those settings in template context. Maybe it will be added in the future. I will write a request.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...