Jump to content

$page->save($fieldname) error reporting / exception handling does not work with FieldtypeTextUnique


mtwebit
 Share

Recommended Posts

I'm trying to store values in a FieldtypeTextUnique field using the API.
Unfortunately, the following code reports no error / exception when a value is not stored because it is not unique in the DB.

try {
  if (!$page->save($fieldname)) {
    ... report the error ...
  }
} catch (\Exception $e) {
  .. report the exception ...
}

I was expecting at least an exception because of the UNIQUE SQL constraint.
Any idea how to catch this error in a module that modifies page fields?
I also tried the validate the saved value but things got complicated for certain field types (e.g. datetime, WireArrays).
Thanks!

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...