Error shows in the Swimlane controller when there is no short code in the URL

Created on 18 December 2024, 20 days ago

Problem/Motivation

An error shows in the Drupal UI via the Swimlane controller when there is no short code in the URL.

Steps to reproduce

Go to Swimlane url via the project list and then press the link shown above.


Proposed resolution

One possible solution would be test if the short code is null or not. If it's null then return nothing to the URL. However, this doesn't stop the controller from creating an orphan Swimlanes.

This was the result with the change of code below mentioned below.

web/modules/contrib/burndown/src/Controller/SwimlaneController.php
  /**
   * Callback for `burndown/reorder_swimlanes/{shortcode}` route.
   */
  public function getSwimlanes($shortcode = null) { <----- added null
    $data = [];
    
    if($shortcode == null) { <---- added this if statement which returns no error.
      return [
        '#theme' => 'burndown_project_swimlanes',
        '#data' => [
          'shortcode' => '',
          'swimlanes' => '',
        ],
        '#attached' => [
          'library' => [
            'burndown/drupal.burndown.swimlanes',
          ],
        ],
        '#cache' => [
          'max-age' => 0,
        ],
      ];
    }

    // Sanitize input.
    $code = Html::escape($shortcode);

    // Get swimlanes.
    $swimlanes = Swimlane::getBoardSwimlanes($code);

    // Get tasks for each swimlane.
    foreach ($swimlanes as $swimlane) {
      $swimlane_name = $swimlane->getName();
      $swimlane_id = $swimlane->id();

      $data[] = [
        'swimlane_name' => $swimlane_name,
        'swimlane_id' => $swimlane_id,
      ];
    }

    // Return data.
    return [
      '#theme' => 'burndown_project_swimlanes',
      '#data' => [
        'shortcode' => $code,
        'swimlanes' => $data,
      ],
      '#attached' => [
        'library' => [
          'burndown/drupal.burndown.swimlanes',
        ],
      ],
      '#cache' => [
        'max-age' => 0,
      ],
    ];
  }

Remaining tasks

What the best way create a link back to the project page and remove the Swimlane button when there is not short code to render the Swimlanes associate to that project.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇦🇺Australia purencool

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

Comments & Activities

Production build 0.71.5 2024