I'm adding new fields to views through a custom module.

When I open the view page UI, the field is not shown. However, If I edit the view from the user interface, and click on Add field, the custom field is available.

How can I automatically add those fields to the list of fields to display on a view?

function mymodule_views_default_views() {
  // …
  $handler->display->display_options['fields']['myfield']['id'] = 'fieldname';
  $handler->display->display_options['fields']['myfield']['table'] = 'databaseTableName';
  $handler->display->display_options['fields']['myfield']['field'] = 'fieldname';
  // …


Your Answer

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

Browse other questions tagged or ask your own question.