library/Haste/Dca/General.php
public function doAddAliasButton($arrButtons, \DataContainer $dc)
    {
        // Generate the aliases
        if (\Input::post('FORM_SUBMIT') == 'tl_select' && isset($_POST['alias'])) {
            if (version_compare(VERSION, '4.0', '<')) {
                $objSessionData = \Session::getInstance()->getData();
                $arrIds         = $objSessionData['CURRENT']['IDS'];
            } else {
                /** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */
                $objSession = \System::getContainer()->get('session');
                $session    = $objSession->all();
                $arrIds     = $session['CURRENT']['IDS'];
            }

            $strItemClass = \Model::getClassFromTable($dc->table);

            if (!class_exists($strItemClass)) {
                return $arrButtons;
            }

            foreach ($arrIds as $intId) {
                $objItem = $strItemClass::findByPk($intId);

                if ($objItem === null) {
                    continue;
                }

                $dc->id           = $intId;
                $dc->activeRecord = $objItem;

                $strAlias = '';

                // Generate new alias through save callbacks
                foreach ($GLOBALS['TL_DCA'][$dc->table]['fields']['alias']['save_callback'] as $callback) {
                    if (is_array($callback)) {
                        $this->import($callback[0]);
                        $strAlias = $this->{$callback[0]}->{$callback[1]}($strAlias, $dc);
                    } elseif (is_callable($callback)) {
                        $strAlias = $callback($strAlias, $dc);
                    }
                }

                // The alias has not changed
                if ($strAlias == $objItem->alias) {
                    continue;
                }

                // Initialize the version manager
                $objVersions = new \Versions($dc->table, $intId);
                $objVersions->initialize();

                // Store the new alias
                \Database::getInstance()->prepare("UPDATE $dc->table SET alias=? WHERE id=?")->execute($strAlias, $intId);

                // Create a new version
                $objVersions->create();
            }

            \Controller::redirect($this->getReferer());
        }

        // Add the button
        if (version_compare(VERSION, '4.0', '<')) {
            $arrButtons['alias'] = '<input type="submit" name="alias" id="alias" class="tl_submit" accesskey="a" value="' . specialchars(
                    $GLOBALS['TL_LANG']['MSC']['aliasSelected']
                ) . '"> ';
        } else {
            $arrButtons['alias'] = '<button type="submit" name="alias" id="alias" class="tl_submit" accesskey="a">' .
                $GLOBALS['TL_LANG']['MSC']['aliasSelected'] .
                '</button> ';
        }

        return $arrButtons;
    }
public function doAddAliasButton($arrButtons, \DataContainer $dc)
    {
        // Generate the aliases
        if (\Input::post('FORM_SUBMIT') == 'tl_select' && isset($_POST['alias'])) {
            if (version_compare(VERSION, '4.0', '<')) {
                $objSessionData = \Session::getInstance()->getData();
                $arrIds         = $objSessionData['CURRENT']['IDS'];
            } else {
                /** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */
                $objSession = \System::getContainer()->get('session');
                $session    = $objSession->all();
                $arrIds     = $session['CURRENT']['IDS'];
            }

            $strItemClass = \Model::getClassFromTable($dc->table);

            if (!class_exists($strItemClass)) {
                return $arrButtons;
            }

            foreach ($arrIds as $intId) {
                $objItem = $strItemClass::findByPk($intId);

                if ($objItem === null) {
                    continue;
                }

                $dc->id           = $intId;
                $dc->activeRecord = $objItem;

                $strAlias = '';

                // Generate new alias through save callbacks
                foreach ($GLOBALS['TL_DCA'][$dc->table]['fields']['alias']['save_callback'] as $callback) {
                    if (is_array($callback)) {
                        $this->import($callback[0]);
                        $strAlias = $this->{$callback[0]}->{$callback[1]}($strAlias, $dc);
                    } elseif (is_callable($callback)) {
                        $strAlias = $callback($strAlias, $dc);
                    }
                }

                // The alias has not changed
                if ($strAlias == $objItem->alias) {
                    continue;
                }

                // Initialize the version manager
                $objVersions = new \Versions($dc->table, $intId);
                $objVersions->initialize();

                // Store the new alias
                \Database::getInstance()->prepare("UPDATE $dc->table SET alias=? WHERE id=?")->execute($strAlias, $intId);

                // Create a new version
                $objVersions->create();
            }

            \Controller::redirect($this->getReferer());
        }

        // Add the button
        if (version_compare(VERSION, '4.0', '<')) {
            $arrButtons['alias'] = '<input type="submit" name="alias" id="alias" class="tl_submit" accesskey="a" value="' . specialchars(
                    $GLOBALS['TL_LANG']['MSC']['aliasSelected']
                ) . '"> ';
        } else {
            $arrButtons['alias'] = '<button type="submit" name="alias" id="alias" class="tl_submit" accesskey="a">' .
                $GLOBALS['TL_LANG']['MSC']['aliasSelected'] .
                '</button> ';
        }

        return $arrButtons;
    }
public function doAddAliasButton ( $ arrButtons , \ DataContainer $ dc ) { // Generate the aliases if ( \ Input :: post ( 'FORM_SUBMIT' ) == 'tl_select' && isset ( $ _POST [ 'alias' ] ) ) { if ( version_compare ( VERSION , '4.0' , '<' ) ) { $ objSessionData = \ Session :: getInstance ( ) -> getData ( ) ; $ arrIds = $ objSessionData [ 'CURRENT' ] [ 'IDS' ] ; } else { /** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */ $ objSession = \ System :: getContainer ( ) -> get ( 'session' ) ; $ session = $ objSession -> all ( ) ; $ arrIds = $ session [ 'CURRENT' ] [ 'IDS' ] ; } $ strItemClass = \ Model :: getClassFromTable ( $ dc -> table ) ; if ( ! class_exists ( $ strItemClass ) ) { return $ arrButtons ; } foreach ( $ arrIds as $ intId ) { $ objItem = $ strItemClass :: findByPk ( $ intId ) ; if ( $ objItem === null ) { continue ; } $ dc -> id = $ intId ; $ dc -> activeRecord = $ objItem ; $ strAlias = '' ; // Generate new alias through save callbacks foreach ( $ GLOBALS [ 'TL_DCA' ] [ $ dc -> table ] [ 'fields' ] [ 'alias' ] [ 'save_callback' ] as $ callback ) { if ( is_array ( $ callback ) ) { $ this -> import ( $ callback [ 0 ] ) ; $ strAlias = $ this -> { $ callback [ 0 ] } -> { $ callback [ 1 ] } ( $ strAlias , $ dc ) ; } elseif ( is_callable ( $ callback ) ) { $ strAlias = $ callback ( $ strAlias , $ dc ) ; } } // The alias has not changed if ( $ strAlias == $ objItem -> alias ) { continue ; } // Initialize the version manager $ objVersions = new \ Versions ( $ dc -> table , $ intId ) ; $ objVersions -> initialize ( ) ; // Store the new alias \ Database :: getInstance ( ) -> prepare ( "UPDATE $dc->table SET alias=? WHERE id=?" ) -> execute ( $ strAlias , $ intId ) ; // Create a new version $ objVersions -> create ( ) ; } \ Controller :: redirect ( $ this -> getReferer ( ) ) ; } // Add the button if ( version_compare ( VERSION , '4.0' , '<' ) ) { $ arrButtons [ 'alias' ] = '<input type="submit" name="alias" id="alias" class="tl_submit" accesskey="a" value="' . specialchars ( $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'aliasSelected' ] ) . '"> ' ; } else { $ arrButtons [ 'alias' ] = '<button type="submit" name="alias" id="alias" class="tl_submit" accesskey="a">' . $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'aliasSelected' ] . '</button> ' ; } return $ arrButtons ; }
Generic method for automatically generating aliases

@param array $arrButtons
@param \DataContainer $dc

@return array
Generic method for automatically generating aliases