Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Toutouwai
Copy link
Contributor

Related forum post: https://processwire.com/talk/topic/30194-weekly-update-%E2%80%93%C2%A011-july-2024/?do=findComment&comment=242758

Another admin customisation issue I've struck recently is when you want to customise markup for InputfieldWrapper. There's InputfieldWrapper::setMarkup() but this is marked as internal and isn't that practical to use because InputfieldWrapper::markup is static. That means any custom markup you set there persists for all InputfieldWrappers that are subsequently rendered, when what I want to do is customise markup for a specific instance of InputfieldWrapper.

@ryancramerdesign
Copy link
Member

@Toutouwai Wouldn't this only affect the markup from that one instance of InputfieldWrapper? Forms usually have multiple InputfieldWrappers in them, which is why this is stored statically and set with InputfieldWrapper::setMarkup().

Are there cases where you'd be rendering multiple forms using different wrapper markup in the same request? I've not come across that yet. But I suppose you could do it this way:

// save current markup
$originalMarkup = InputfieldWrapper::getMarkup();

// set new custom markup
InputfieldWrapper::setMarkup([ ... ]); 

// render form
echo $form->render();

// restore original markup
InputfieldWrapper::setMarkup($originalMarkup);

That whole thing could potentially be abstracted behind the $form->render(), maybe with a $form->renderCustom($markup) or something like that?

@Toutouwai
Copy link
Contributor Author

Wouldn't this only affect the markup from that one instance of InputfieldWrapper?

Yes, that's exactly the aim of the pull request.

For me this request is about the ability to customise specific parts of the admin markup via hooks without affecting other InputfieldWrappers.

As an example, I wanted to add some markup adjacent to (not within) the <label> element of items within a repeater field.

With the changes in this pull request I can do this:

$wire->addHookBefore('InputfieldWrapper(name^=repeater_form_)::render', function(HookEvent $event) {
	$wrapper = $event->object;
	$markup = [
		'item_label' => "<label class='InputfieldHeader ui-widget-header{class}' for='{for}'>{out}</label><div class='my-extra-mark'>My extra markup here</div>",
	];
	$wrapper->setInstanceMarkup($markup);
});

2024-07-30_121003

To achieve these targeted changes it's not sufficient to set the static $markup property before the form render and reset it after the form render because all the InputfieldWrappers within each repeater item will be affected before $markup can be reset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants