Unable to select display to attach to - no options showing

Created on 27 November 2023, 12 months ago
Updated 28 November 2023, 12 months ago

Problem/Motivation

When creating/editing the PDF view display and you click on "Attach to", the modal provides no display options to choose from. This is due to incorrect syntax/views API usage in Drupal\views_pdf\Plugin\views\display\PDF->buildOptionsForm(). The follow 2 warnings are recorded in the watchdog log when it attempts to render the display selection form in the modal dialog:

Warning: Undefined property: Drupal\views\ViewExecutable::$display in Drupal\views_pdf\Plugin\views\display\PDF->buildOptionsForm() (line 1030 of /[docroot]/modules/contrib/views_pdf/src/Plugin/views/display/PDF.php)

Warning: foreach() argument must be of type array|object, null given in Drupal\views_pdf\Plugin\views\display\PDF->buildOptionsForm() (line 1030 of /[docroot]/modules/contrib/views_pdf/src/Plugin/views/display/PDF.php)

Steps to reproduce

Using Drupal 10.1 (I have not tested with D9 or earlier D10 versions), create/edit the PDF display of your view and click the "Attach to" link.

Proposed resolution

Modify the syntax on lines 1030, 1031 and 1032 to be the same as is found in the Views Data Export module, which has the same functionality but without any errors when selecting the display to attach to:

        foreach ($this->view->storage->get('display') as $display_id => $display) {
          if ($this->view->displayHandlers->has($display_id) && $this->view->displayHandlers->get($display_id)->acceptAttachments()) {
            $displays[$display_id] = $display['display_title'];

In the Views Data Export module, this is found around line 490 of src\Plugin\views\display\DataExport.php. Copying this as-is into the Views PDF module resolves the issue.

Remaining tasks

Create issue fork and submit merge request.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada teknocat

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024