src/VersionedStateExtension.php
public function updateLink(&$link)
    {
        // Skip if link already contains reading mode
        if ($this->hasVersionedQuery($link)) {
            return;
        }

        // Skip if current mode matches default mode
        // See LeftAndMain::init() for example of this being overridden.
        $readingMode = $this->getReadingmode();
        if ($readingMode === Versioned::get_default_reading_mode()) {
            return;
        }

        // Determine if query args are supported for the current mode
        $queryargs = ReadingMode::toQueryString($readingMode);
        if (!$queryargs) {
            return;
        }

        // Don't touch Admin/CMS links
        if (class_exists(LeftAndMain::class) && $this->getOwner() instanceof LeftAndMain) {
            return;
        }

        // Decorate
        $link = Controller::join_links(
            $link,
            '?' . http_build_query($queryargs)
        );
    }
public function updateLink(&$link)
    {
        // Skip if link already contains reading mode
        if ($this->hasVersionedQuery($link)) {
            return;
        }

        // Skip if current mode matches default mode
        // See LeftAndMain::init() for example of this being overridden.
        $readingMode = $this->getReadingmode();
        if ($readingMode === Versioned::get_default_reading_mode()) {
            return;
        }

        // Determine if query args are supported for the current mode
        $queryargs = ReadingMode::toQueryString($readingMode);
        if (!$queryargs) {
            return;
        }

        // Don't touch Admin/CMS links
        if (class_exists(LeftAndMain::class) && $this->getOwner() instanceof LeftAndMain) {
            return;
        }

        // Decorate
        $link = Controller::join_links(
            $link,
            '?' . http_build_query($queryargs)
        );
    }
public function updateLink ( & $ link ) { // Skip if link already contains reading mode if ( $ this -> hasVersionedQuery ( $ link ) ) { return ; } // Skip if current mode matches default mode // See LeftAndMain::init() for example of this being overridden. $ readingMode = $ this -> getReadingmode ( ) ; if ( $ readingMode === Versioned :: get_default_reading_mode ( ) ) { return ; } // Determine if query args are supported for the current mode $ queryargs = ReadingMode :: toQueryString ( $ readingMode ) ; if ( ! $ queryargs ) { return ; } // Don't touch Admin/CMS links if ( class_exists ( LeftAndMain :: class ) && $ this -> getOwner ( ) instanceof LeftAndMain ) { return ; } // Decorate $ link = Controller :: join_links ( $ link , '?' . http_build_query ( $ queryargs ) ) ; }
Auto-append current stage if we're in draft,
to avoid relying on session state for this,
and the related potential of showing draft content
without varying the URL itself.

Assumes that if the user has access to view the current
record in draft stage, they can also view other draft records.
Does not concern itself with verifying permissions for performance reasons.

This should also pull through to form actions.

@param string $link
Auto - append current stage if we re in draft to avoid relying on session state for this and the related potential of showing draft content without varying the URL itself .