Juergen Posted January 28, 2018 Share Posted January 28, 2018 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 More sharing options...
BitPoet Posted January 28, 2018 Share Posted January 28, 2018 Shouldn't that be addHookAfter? Link to comment Share on other sites More sharing options...
Juergen Posted January 28, 2018 Author Share Posted January 28, 2018 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 More sharing options...
Juergen Posted January 28, 2018 Author Share Posted January 28, 2018 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 More sharing options...
Zeka Posted January 28, 2018 Share Posted January 28, 2018 @Juergen In PW 3.0.87 there were some updates to field/template context settings and now you can change field settings in the context of other templates through admin UI. https://processwire.com/blog/posts/pw-3.0.87/ Maybe this update has changed something in core that prevents your hook to work. 1 Link to comment Share on other sites More sharing options...
Juergen Posted January 28, 2018 Author Share Posted January 28, 2018 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 More sharing options...
BitPoet Posted January 28, 2018 Share Posted January 28, 2018 Try hooking InputfieldImage instead of FieldtypeImage. 1 Link to comment Share on other sites More sharing options...
Juergen Posted January 28, 2018 Author Share Posted January 28, 2018 I have set the $config->advanced = true; and remove the hook. This works great but thanks for your tipp. Link to comment Share on other sites More sharing options...
Robin S Posted January 28, 2018 Share Posted January 28, 2018 7 hours ago, Juergen said: The settings "maxFiles, defaultValuePage and outputFormat" work, but "minWidth, minHeight" and so on not. See here for how you can add those settings via hooks: 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now