Views Data Export Failure

Created on 3 May 2024, 10 months ago
Updated 5 June 2024, 9 months ago

I'm not sure how best to report this, but here goes.

The Error

When performing View migrations via drush, the command would run and process all of the views, upon completion it would throw this error:

PHP Fatal error: Uncaught Error: Call to undefined method Drupal\views\Plugin\views\style\DefaultStyle::getFormats() in /app/web/core/modules/rest/src/Plugin/views/display/RestExport.php:351

Subsequent cache rebuilds threw the same error.

I dug into the code a little bit, and it's the core rest module's view style attempting to create routes for the view. Essentially the process of collecting the site's routes was failing and the site was broken.

The Workaround

I dug into this and ended up finding that views_migration has a ViewsDataExport plugin that is supposed to handle this, but was not applying to my views because their plugin_id was views_data_export_csv instead of data_export. It was falling back the the default style plugin which then produced a view with the "default" style, and that was failing.

I added a plugin to my custom migration module code to allow this work:


namespace Drupal\my_module\Plugin\migrate\views\style\d7;

use Drupal\views_migration\Plugin\migrate\views\style\d7\ViewsDataExport as ContribViewsDataExport;

/**
 * Custom Migrate Views Style plugin.
 *
 * Picks up necessary changes for Views Data Export that are missed by the
 * views_migration implementation.
 *
 * @MigrateViewsStyle(
 *   id = "my_module_data_export",
 *   plugin_ids = {
 *    "views_data_export_csv"
 *   },
 *   core = {7},
 * )
 */
class ViewsDataExport extends ContribViewsDataExport {

  /**
   * {@inheritdoc}
   */
  public function prepareDisplayOptions(array &$display_options) {
    $display_options['style_plugin'] = 'data_export';
    parent::prepareDisplayOptions($display_options);
  }

}

Another possible issue

Also, while exploring possible solutions I noticed that I was unable to alter the plugin info. This module sets a $type that includes a slash (/). That type is later used by the parent class to determine an alter hook, but the resulting function names are invalid due to the slash.

In my case I don't think I could have used only this hook, but it may be worth a look to see if the plugin manager can do something different to handle the alter hook function names.

🐛 Bug report
Status

Needs review

Version

1.2

Component

Code

Created by

🇺🇸United States kerasai

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024