Override Exclude from Navigation Default Value from False to True

Exclude from navigation uses a default value adapter: https://github.com/plone/plone.app.dexterity/commit/1e20bed0552d43317ee38f8a3efa5343c64937da

How do you override the default adapter for custom content types? I tried:

<adapter
  for=".personal_profile.IPersonalProfile"
  provides="plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigationDefault"
  factory="plone.app.dexterity.behaviors.exclfromnav.default_exclude_true"
/>

But this does not work.

Have you checked, that the respective objects provide IPersonalProfile?

The "exclude from navigation" is potentially catalogued. In this case, you need to reindex the corresponding index to make the change fully effective.

No, it's not indexed (at least not before Plone 5.2b1).

As Dieter wrote: check for the related interface. In doubt add a debugger breakpoint inside the configured factory method and check if there is something potentially going wrong.

@dieter @zopyx Thank you for your replies. Before posting, I have not tested saving the content type. I was expecting the default True value to already apply in the add form.

I have just tested saving the form and the content type still has the default False value.

p.a.dexterity registers the behavior with the following:

<plone:behavior
      name="plone.excludefromnavigation"
      title="Exclude From navigation"
      description="Allow items to be excluded from navigation"
      provides=".exclfromnav.IExcludeFromNavigation"
      />
  <adapter
      for="*"
      factory=".exclfromnav.default_exclude_false"
      />

Is my adapter registration to override the above for the personal profile type, correct?

As said: check yourself if your own code is being executed first.

It should - as your adapter registration is more specific than the default one.

I see various possibilities why is does not work:

  • are you sure that your registration gets "executed"?
  • are you sure that the respective objects provide the interface your adapter was registered for?

Thanks for the confirmation. I have difficulty finding documentation about this.

The registration zcml, at least, is being executed since I get errors when I try to use other options like a layer. The interface is a schema interface. I will check on this when I find more time. I actually have a custom behavior that already implements Exclude from Navigation with a default True value. I was just interested in finding out how to adapt the default implementation since the code is already there.

I will post back if I have more to add on this topic.

Thanks.

I just run in the same problem, and try to make the adapter thing work (without success), maybe the adapter never worked, and need to be fixed.

In the end override the behavior and didn't try to be clever like @datakurre suggested as better solution here How to change existing dexterity types and behaviors