V8-archive: API Hooks Not Working

Created on 15 Aug 2019  Â·  6Comments  Â·  Source: directus/v8-archive

Bug Report

Using hooks within the API php file is no longer working.

Steps to Reproduce

'item.create.devices:before' => function (\Directus\Hook\Payload $payload) { $payload->set('name','test'); return $payload

  1. Go to Devices collection.
  2. Click on + to add a new device item.
  3. Create the item with no value for the name field.
  4. Item is created successfully without error but the name is not set to 'test' it remains empty.

Expected Behavior

https://docs.directus.io/extensions/hooks.html#creating-hooks

item.create hook should allow me to set the name to test by altering the payload.

Actual Behavior

No value is set for the name text field.

Other Context & Screenshots

Technical Details

  • Device: Desktop
  • OS: Windows 10
  • Install Method: cloned master branch of directus
  • Version: Spouting Whale — (190807A)
bug documentation

Most helpful comment

@benhaynes can we get this labeled back as a bug? It is not a documentation issue unless that's to say the procedure has been changed and needs to be updated.

All 6 comments

@srjrol

If you check the doc, then you'll able to find out that the hook will accept the array of your input and filters will accept the object of payload.

  • Action Hooks execute a piece of code without altering the data being passed through it.
  • Filter Hooks are similar to Actions but alter the data that passes through it.

Based on your example, It seems like you are trying to user object of payload as a hook to update your payload and that's the cause of the error at your end.

Kindly use filters to edit your payload instead of hooks.

@bjgajjar

Thanks for the suggestion. I should have been more clear in my original report as I am already using a filter hook for this. I do not have any action hooks. The hooks I have written were working for about 6-8 months but I noticed problems sometime around the World Map — (190717A) release.

@benhaynes can we get this labeled back as a bug? It is not a documentation issue unless that's to say the procedure has been changed and needs to be updated.

@srjrol,

World Map — (190717A) release

Can you please check it in the latest build? As I am not able to reproduce it in the latest one.

Not sure why you quoted the World Map release. I am already using the latest release Spouting Whale — (190807A).

I found the problem. My config.php was overwritten in one of the updates and it was no longer pointed to my custom api file :(

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdwmhcc picture cdwmhcc  Â·  3Comments

24js picture 24js  Â·  3Comments

gitlabisbetterthangithub picture gitlabisbetterthangithub  Â·  3Comments

Nitwel picture Nitwel  Â·  3Comments

andgar2010 picture andgar2010  Â·  3Comments