Jump to content

Set default description for input field file on load


TomPich
 Share

Recommended Posts

Hello friends,

I stumbled upon a problem that is harder to solve that I thought.
On a template, the user can upload a file. The description of the file is used in the front as text for the download button.
The client asked me to have a default description for this field (Communiqué).
So I started to play with some hooks (in admin page), mainly addHookAfter InputfieldFile::processInputFile
This is where I am for now...

$wire->addHookAfter('InputfieldFile::processInputFile', function (HookEvent $event) {
	$field = $event->object;
	if ($field->attributes["name"] === "postFile") {
		// fill the file description with "Communiqué de presse
		// but I can’t figure out how to do that
	};
});

Any help?
Thanks!

Edited by TomPich
Correct typo
Link to comment
Share on other sites

wire()->addHookBefore("InputfieldFile::renderItem", function(HookEvent $event) {
    $pagefile = $event->argumentsByName('pagefile');

    if ($pagefile->field->name === 'yourFileField') {
        $pagefile->description = 'Communiqué de presse';
        $pagefile->page->save($pagefile->field->name);
    }
});

Try this @TomPich

  • Like 1
  • Thanks 1
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...