Jump to content
elabx

[SOLVED] Field access on runtime

Recommended Posts

Posted (edited)

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.

Edited by elabx
Soled, check posts below

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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);
		}
	});
});

 

  • Like 2

Share this post


Link to post
Share on other sites
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).

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...