Commit ae66ab33 authored by Mickael Bidinger's avatar Mickael Bidinger Committed by Marc-Antoine MARTY
Browse files

Issue #3279072 by MBidinger: Shorten very long urls

parent 99b4c662
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ class EntityListFilterFormBase extends FormBase {
      }
    }

    $this->unsetEmptyValues($params);

    if (!empty($params['page'])) {
      unset($params['page']);
    }
@@ -53,4 +55,21 @@ class EntityListFilterFormBase extends FormBase {
    $url = Url::fromRoute('<current>', $params);
    $form_state->setRedirectUrl($url);
  }

  /**
   * Avoid long urls by removing any empty parameter.
   *
   * @param array $values
   *   The values to filter.
   */
  private function unsetEmptyValues(array &$values): void {
    foreach ($values as $key => &$value) {
      if (is_array($value)) {
        $this->unsetEmptyValues($value);
      }
      if (empty($value) || $value === '0') {
        unset($values[$key]);
      }
    }
  }
}