src/Common/Traits/Model/Nestable.php
protected function saveBreadcrumbs($iItemId)
    {
        //  @todo (Pablo - 2018-07-01) - protect against infinite loops

        $oItem = $this->getById($iItemId);

        if (!empty($oItem)) {

            $aBreadcrumbs = [];
            $iParentId    = (int) $oItem->parent_id;
            while ($iParentId) {
                $oParentItem = $this->getById($iParentId);
                if ($oParentItem) {
                    $iParentId = $oParentItem->parent_id;
                    array_unshift(
                        $aBreadcrumbs,
                        (object) array_filter([
                            'id'    => $oParentItem->id,
                            'label' => !empty($oParentItem->label) ? $oParentItem->label : null,
                            'slug'  => !empty($oParentItem->slug) ? $oParentItem->slug : null,
                            'url'   => !empty($oParentItem->url) ? $oParentItem->url : null,
                        ])
                    );
                } else {
                    $iParentId = null;
                }
            }

            //  Save breadcrumbs to the current item
            parent::update(
                $iItemId,
                [
                    $this->getBreadcrumbsColumn() => json_encode($aBreadcrumbs),
                ]
            );

            //  Save breadcrumbs of all children
            $oDb = Factory::service('Database');
            $oDb->where('parent_id', $iItemId);
            $aChildren = $oDb->get($this->getTableName())->result();
            foreach ($aChildren as $oItem) {
                $this->saveBreadcrumbs($oItem->id);
            }
        }
    }
protected function saveBreadcrumbs($iItemId)
    {
        //  @todo (Pablo - 2018-07-01) - protect against infinite loops

        $oItem = $this->getById($iItemId);

        if (!empty($oItem)) {

            $aBreadcrumbs = [];
            $iParentId    = (int) $oItem->parent_id;
            while ($iParentId) {
                $oParentItem = $this->getById($iParentId);
                if ($oParentItem) {
                    $iParentId = $oParentItem->parent_id;
                    array_unshift(
                        $aBreadcrumbs,
                        (object) array_filter([
                            'id'    => $oParentItem->id,
                            'label' => !empty($oParentItem->label) ? $oParentItem->label : null,
                            'slug'  => !empty($oParentItem->slug) ? $oParentItem->slug : null,
                            'url'   => !empty($oParentItem->url) ? $oParentItem->url : null,
                        ])
                    );
                } else {
                    $iParentId = null;
                }
            }

            //  Save breadcrumbs to the current item
            parent::update(
                $iItemId,
                [
                    $this->getBreadcrumbsColumn() => json_encode($aBreadcrumbs),
                ]
            );

            //  Save breadcrumbs of all children
            $oDb = Factory::service('Database');
            $oDb->where('parent_id', $iItemId);
            $aChildren = $oDb->get($this->getTableName())->result();
            foreach ($aChildren as $oItem) {
                $this->saveBreadcrumbs($oItem->id);
            }
        }
    }
protected function saveBreadcrumbs ( $ iItemId ) { //  @todo (Pablo - 2018-07-01) - protect against infinite loops $ oItem = $ this -> getById ( $ iItemId ) ; if ( ! empty ( $ oItem ) ) { $ aBreadcrumbs = [ ] ; $ iParentId = ( int ) $ oItem -> parent_id ; while ( $ iParentId ) { $ oParentItem = $ this -> getById ( $ iParentId ) ; if ( $ oParentItem ) { $ iParentId = $ oParentItem -> parent_id ; array_unshift ( $ aBreadcrumbs , ( object ) array_filter ( [ 'id' => $ oParentItem -> id , 'label' => ! empty ( $ oParentItem -> label ) ? $ oParentItem -> label : null , 'slug' => ! empty ( $ oParentItem -> slug ) ? $ oParentItem -> slug : null , 'url' => ! empty ( $ oParentItem -> url ) ? $ oParentItem -> url : null , ] ) ) ; } else { $ iParentId = null ; } } //  Save breadcrumbs to the current item parent :: update ( $ iItemId , [ $ this -> getBreadcrumbsColumn ( ) => json_encode ( $ aBreadcrumbs ) , ] ) ; //  Save breadcrumbs of all children $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> where ( 'parent_id' , $ iItemId ) ; $ aChildren = $ oDb -> get ( $ this -> getTableName ( ) ) -> result ( ) ; foreach ( $ aChildren as $ oItem ) { $ this -> saveBreadcrumbs ( $ oItem -> id ) ; } } }
Generates breadcrumbs for the item

@param integer $iItemId The item's ID
Generates breadcrumbs for the item