Jump to content

Suppressing Messages


lloop
 Share

Recommended Posts

I am writing a module for personal use that generates pages with randomly generated content such as text and images.

It's an exercise in module writing as much as it is practical. I am generating the pages specified by a template successfully but,

for each page generated, I get several of the green messages in the header. Specifically for repeater fields. It's a bit inconvenient when

I generate 50 pages.

So, since I'm putting it into a module finally, I thought I would before-hook into Page::render and alter the $notices object.

$this->addHookBefore('Page::render', $this, 'suppressMessages');

public function suppressMessages(HookEvent $event) {

  if($event->object->name !== 'generate-pages') return $event;

  $new_messages = wire('notices')->not('class=FieldtypeRepeater');

  var_dump($new_messages);
  var_dump($this->wire->notices);

  // $this->wire()->set('notices', $new_messages);

  return $event;
}

The two var_dumps print the same thing which is the a $notices array without the offending messages. But the messages

are still showing up in the page header. Is the $notices variable used before Page::render? The commented out '$this->wire()->set'

didn't do anything.

TIA

Link to comment
Share on other sites

First of all i'm not sure of this, I haven't test it, but maybe you can give it a try. Not shooting will never hit the target :-)

I do think those messages are coming from InputfieldRepeater. Maybe you can hook before InputfieldRepeater::render, and suppress the errors with the getErrors(true) methode.



$this->addHookBefore('InputfieldRepeater::render', $this, 'suppressFieldError');

public function suppressFieldError(HookEvent $event) {
$repeater = $event->object;
$repeater->getErrors(true); // clear errors
}

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

×
×
  • Create New...