Indatus\Ranger\ContentType\HtmlView\ViewManager::handleRedirect PHP Method

handleRedirect() public method

Function to handle redirection of regular and also nested resource routes.
public handleRedirect ( $route, $parentAssociation, integer $id = null, $responseCode ) : Redirect
$id integer The id for the route
return Redirect
    public function handleRedirect($route, $parentAssociation, $id = null, $responseCode)
    {
        $params = array();
        if ($id && null_or_empty($parentAssociation)) {
            $route = explode('.', $route)[0] . '.' . self::ACTION_EDIT;
            $params = array($id);
        } elseif ($id && !null_or_empty($parentAssociation)) {
            $parent = explode('.', $route)[0];
            $child = explode('.', $route)[1];
            $route = $parent . '.' . $child . '.' . self::ACTION_EDIT;
            $params = array_values(array_merge($parentAssociation, array($id)));
        } elseif (is_null($id) && !null_or_empty($parentAssociation)) {
            $parent = explode('.', $route)[0];
            $child = explode('.', $route)[1];
            $route = $parent . '.' . $child . '.' . self::ACTION_SHOW;
            $params = array_values($parentAssociation);
        } elseif (is_null($id) && null_or_empty($parentAssociation)) {
            $route = explode('.', $route)[0] . '.' . self::ACTION_SHOW;
            $params = array();
        } else {
            throw new InvalidArgumentException("incorrect format");
        }
        //handle error responses
        return $this->redirect->route($route, $params);
    }