before_save_record

18 views
Skip to first unread message

Battistella, Marco

unread,
Feb 10, 2016, 11:55:43 AM2/10/16
to omek...@googlegroups.com
HI,
i am trying to manipulate the values of an item before it is saved or updated.
while i see that there are some record object properties that allow me to retrieve the values of the various fields, i don’t immediately see any way to change the values of any of the fields.
I’m sure i’m missing something…

BTW there is a mistake in the relevant page in the docs: http://omeka.readthedocs.org/en/latest/Reference/hooks/before_save_record.html
it say "Since this hook fires after the record is saved, “ i’m pretty sure it should be "Since this hook fires before the record is saved, "

Any help wold be appreciated.
Thanks.
Marco

John Flatness

unread,
Feb 10, 2016, 12:52:36 PM2/10/16
to Omeka Dev
If by "values" you're talking about Element Text data (values for Dublin Core elements and so on) then pretty much all the methods for directly editing that stuff are in Mixin_ElementText (http://omeka.readthedocs.org/en/latest/Reference/models/Mixin/ElementText.html).

I'll see about fixing that docs page.

-John

Battistella, Marco

unread,
Feb 22, 2016, 12:07:49 PM2/22/16
to omek...@googlegroups.com
Hi again,
i am still unsure how to proceed to modify an element text.
let me give a snip of code:

  public function hookBeforeSaveItem($args) {
    $record = $args['record'];
    $elem = $record->getElementTexts('Dublin Core','Title');
  }

in this case $elem is now an array of ElementText objects. I can retrieve the value (eg: $elem[0]->text) but i don’t se any way to modify it.
Could you provide an example?
Sorry, this is probably something obvious that i’m just not seeing….
Thanks,
Marco


On Feb 10, 2016, at 12:52 PM, John Flatness <jo...@zerocrates.org> wrote:

If by "values" you're talking about Element Text data (values for Dublin Core elements and so on) then pretty much all the methods for directly editing that stuff are in Mixin_ElementText (http://omeka.readthedocs.org/en/latest/Reference/models/Mixin/ElementText.html).

I'll see about fixing that docs page.

-John

On Wednesday, February 10, 2016 at 11:55:43 AM UTC-5, mbatti...@gc.cuny.edu wrote:
HI,
i am trying to manipulate the values of an item before it is saved or updated.
while i see that there are some record object properties that allow me to retrieve the values of the various fields, i don’t immediately see any way to change the values of any of the fields.
I’m sure i’m missing something…

it say "Since this hook fires after the record is saved, “ i’m pretty sure it should be "Since this hook fires before the record is saved, "

Any help wold be appreciated.
Thanks.
Marco


--
You received this message because you are subscribed to the Google Groups "Omeka Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omeka-dev+...@googlegroups.com.
To post to this group, send email to omek...@googlegroups.com.
Visit this group at https://groups.google.com/group/omeka-dev[groups.google.com].
For more options, visit https://groups.google.com/d/optout[groups.google.com].

Patrick Murray-John

unread,
Feb 22, 2016, 3:44:17 PM2/22/16
to omek...@googlegroups.com
Marco,

Going that route, you might be able to alter values with $elem->setText('your text'). It's sometimes tricky to get things to work with the sequence of before and after save hooks and when they are fired, though.

Depending on the details of what you need, the Element Save filter might offer another approach, especially to help customize the changes for particular elements.

Patrick
Reply all
Reply to author
Forward
0 new messages