elabx Posted June 10, 2019 Share Posted June 10, 2019 Hi everyone! Does anyone know if I can tweak field access on runtime to hide fields in ProcessPageEdit depending on some other field conditions. Eg. I want users to be able to edit the data if they are asigned to said page, or they created it and if not, hide the fields. Right now I'm wiping the fields with a hook on ProcessPageEdit::buildFormContent, but for example, I'd like to leave the title field intact and some other "common" fields amongst the users. Link to comment Share on other sites More sharing options...
Robin S Posted June 10, 2019 Share Posted June 10, 2019 You can use my Custom Inputfield Dependencies module to do this. Link to comment Share on other sites More sharing options...
elabx Posted June 11, 2019 Author Share Posted June 11, 2019 2 hours ago, Robin S said: You can use my Custom Inputfield Dependencies module to do this. Wow thanks! With the module, is it possible to render the fields with their renderValue() ? Like the access permission does! It let's you view the inputfield, but doesn't display as an actual input but just the value. Thanks for your help! Will definitely take a look at your module. Link to comment Share on other sites More sharing options...
Robin S Posted June 11, 2019 Share Posted June 11, 2019 5 hours ago, elabx said: With the module, is it possible to render the fields with their renderValue() ? No, it only allows for the showing or hiding of fields, not setting the render value mode. But if you want to selectively render the value of fields rather than the full inputfield you could use hooks like below: $wire->addHookBefore('ProcessPageEdit::buildForm', function(HookEvent $event) { /* @var ProcessPageEdit $ppe */ $ppe = $event->object; $page = $ppe->getPage(); // Some test on $page here, for example... if($page->template != 'news_item') return; $event->wire()->addHookBefore('InputfieldWrapper::renderInputfield', function(HookEvent $event) { /* @var Inputfield $inputfield */ $inputfield = $event->arguments(0); // Some test on $inputfield here, or on the field object via ->hasField if($inputfield->name === 'text_1') { // Inputfield should have only its value rendered, so set render value mode argument to true $event->arguments(1, true); } }); }); 3 Link to comment Share on other sites More sharing options...
elabx Posted June 11, 2019 Author Share Posted June 11, 2019 7 hours ago, Robin S said: No, it only allows for the showing or hiding of fields, not setting the render value mode. But if you want to selectively render the value of fields rather than the full inputfield you could use hooks like below: $wire->addHookBefore('ProcessPageEdit::buildForm', function(HookEvent $event) { /* @var ProcessPageEdit $ppe */ $ppe = $event->object; $page = $ppe->getPage(); // Some test on $page here, for example... if($page->template != 'news_item') return; $event->wire()->addHookBefore('InputfieldWrapper::renderInputfield', function(HookEvent $event) { /* @var Inputfield $inputfield */ $inputfield = $event->arguments(0); // Some test on $inputfield here, or on the field object via ->hasField if($inputfield->name === 'text_1') { // Inputfield should have only its value rendered, so set render value mode argument to true $event->arguments(1, true); } }); }); Awesome! Thanks a lot for your help! Actually found this myself yesterday working through the PW source code (I really LOVE being able to do this). 1 Link to comment Share on other sites More sharing options...
elabx Posted October 18, 2019 Author Share Posted October 18, 2019 Hi everyone! Just came back with another issue trying to solve this "dynamic field access" thing. I've implemented the previous hook @Robin S kindly gave me, but I now have the issue that if I visit the page a second time and save the page again while the conditions within are met (I visit the page a second time, and the fields show as their rendervalue) , the fields data gets deleted! Anyone got any clues on this? I wonder if I have to put a flag somwhere when the form is submitted? Link to comment Share on other sites More sharing options...
elabx Posted October 19, 2019 Author Share Posted October 19, 2019 I solved this like this: $wire->addHookBefore('ProcessPageEdit::buildForm', function(HookEvent $event) { $ppe = $event->object; $page = $ppe->getPage(); if($page->template != 'transaccion') return; $pageInputfields = $page->getInputfields()->children(); if($event->user->hasRole('asesor') && $page->transaccion_enviar_admin){ foreach($page->getFields() as $field){ $event->addHookAfter("Field::editable", function($event){ $event->return = false; }); } } }); BUT, I have to turn on access control on the fields and set the fields to be viewable even if not editable. (the checkboxes at the bottom) 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