I have a boolean field associated with my custom entity. The field itself is hidden in the entity form however when an instance of my entity is created a field record is generated with the default value. This is not the case for a text field i have, where if the field is hidden the field record is not created.

Basically this creation of a default boolean field is messing up my views further down the line.

How can i prevent a default value boolean field being autogenerated when hidden?

Thanks Mathew

  • 2
    Well, boolean can only have true or false. So NULL is not an acceptable value. You could switch it to textfield or number if it is hidden/internal field.
    – user21641
    Jan 25 '17 at 10:59

I am sure there are other (better )ways but the way i got around this issue, which fundamentally was about not having the default turn up in my views further down the line, was to implement a hook on hook_views_pre_view and show/hide the fields as i wanted:

function mymod_views_pre_view(ViewExecutable $view, $display_id, array &$args)
  $fields[$field_name]['exclude'] = TRUE;

worked for me hope it helps someone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.