Recursively build crumbs from menu items

@param $parentId
@param array $crumbs
@return array
439058
public static function getNavigationalBreadcrumbs($parentId, $crumbs = [])
    {
        $menuItems = self::getMenuItems('id');

        if (in_array($parentId, $menuItems)) {
            array_unshift($crumbs, [
                'link' => $menuItems[$parentId]->url,
                'text' => $menuItems[$parentId]->title,
            ]);

            if (!is_null($menuItems[$parentId]->parent_id)) {
                $crumbs = Breadcrumbs::getNavigationalBreadcrumbs($menuItems[$parentId]->parent_id, $crumbs);
            }
        }

        return $crumbs;
    }
578589
public function getActiveCategoryIdList( $categoryId, $parentType ) {

		$modelClass	= static::$modelClass;

		$models = $modelClass::findActiveByCategoryIdParentType( $categoryId, $parentType );
		$ids	= [];

		foreach ( $models as $model ) {

			$category = $model->category;

			$ids[] = $category->id;
		}

		return $ids;
	}
439352
protected function parentInList($parentId, $list)
    {
        foreach ($list as $node) {
            if ($parentId === $node->getNodeId()) {
                return true;
            }
        }

        return false;
    }
587623
public function loadUrlWildcardData($parentId)
    {
        try {
            return $this->innerGateway->loadUrlWildcardData($parentId);
        } catch (DBALException $e) {
            throw new \RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new \RuntimeException('Database error', 0, $e);
        }
    }
253584
public function breadcrumbs(array $args = [])
    {
        global $post;

        $defaults = [
            'containerEl'    => 'div',
            'containerId'    => 'breadcrumbs-container',
            'containerClass' => 'breadcrumbs-container container',
            'listEl'         => 'ol',
            'listId'         => 'breadcrumb',
            'listClass'      => 'breadcrumb',
            'crumbEl'        => 'li',
            'activeEl'       => null,
            'activeClass'    => 'active'
        ];

        $args = wp_parse_args($args, $defaults);
        extract($args, EXTR_SKIP);

        if ($activeEl) {
            $openActive = sprintf('<%s><%s class="%s">', $crumbEl, $activeEl, $activeClass);
            $closeActive = sprintf('</%s></%s>', $activeEl, $crumbEl);
        } else {
            $openActive = sprintf('<%s class="%s">', $crumbEl, $activeClass);
            $closeActive = sprintf('</%s>', $crumbEl);
        }

        $output = [];
        $output[] = sprintf('<%s id="%s" class="%s">', $containerEl, $containerId, $containerClass);
        $output[] = PHP_EOL.str_repeat('    ', 2);
        $output[] = sprintf('<%s id="%s" class="%s">', $listEl, $listId, $listClass);
        $output[] = sprintf(
            '<%s><a href="%s">%s</a></%s>',
            $crumbEl,
            esc_url(home_url('/')),
            __('Home', 'novusopress'),
            $crumbEl
        );

        if (is_home() && get_option('page_for_posts')) {
            $blogPageId = get_option('page_for_posts');
            $blogPage = get_page($blogPageId);
            $output[] = $openActive;
            $output[] = $blogPage->post_title;
            $output[] = $closeActive;
        } elseif (is_category()) {
            if (get_option('page_for_posts')) {
                $blogPageId = get_option('page_for_posts');
                $output[] = sprintf(
                    '<%s><a href="%s">%s</a></%s>',
                    $crumbEl,
                    get_permalink($blogPageId),
                    get_the_title($blogPageId),
                    $crumbEl
                );
            }

            $cat = get_category(get_query_var('cat'), false);

            if ($cat->parent != 0) {
                $parents = get_category_parents($cat->parent, true, sprintf('</%s><%s>', $crumbEl, $crumbEl));
                $parents = preg_replace('# title=".*"#', '', $parents);
                $output[] = mb_substr(sprintf('<%s>%s', $crumbEl, $parents), 0, -4);
            }

            $output[] = $openActive;
            $output[] = single_cat_title('', false);
            $output[] = $closeActive;
        } elseif (is_search()) {
            $output[] = $openActive;
            $output[] = get_search_query();
            $output[] = $closeActive;
        } elseif (is_day()) {
            if (get_option('page_for_posts')) {
                $blogPageId = get_option('page_for_posts');
                $output[] = sprintf(
                    '<%s><a href="%s">%s</a></%s>',
                    $crumbEl,
                    get_permalink($blogPageId),
                    get_the_title($blogPageId),
                    $crumbEl
                );
            }

            $output[] = sprintf(
                '<%s><a href="%s">%s</a></%s>',
                $crumbEl,
                get_year_link(get_the_time('Y')),
                get_the_time('Y'),
                $crumbEl
            );

            $output[] = sprintf(
                '<%s><a href="%s">%s</a></%s>',
                $crumbEl,
                get_month_link(get_the_time('Y'), get_the_time('m')),
                get_the_time('F'),
                $crumbEl
            );

            $output[] = $openActive;
            $output[] = get_the_time('d');
            $output[] = $closeActive;
        } elseif (is_month()) {
            if (get_option('page_for_posts')) {
                $blogPageId = get_option('page_for_posts');
                $output[] = sprintf(
                    '<%s><a href="%s">%s</a></%s>',
                    $crumbEl,
                    get_permalink($blogPageId),
                    get_the_title($blogPageId),
                    $crumbEl
                );
            }

            $output[] = sprintf(
                '<%s><a href="%s">%s</a></%s>',
                $crumbEl,
                get_year_link(get_the_time('Y')),
                get_the_time('Y'),
                $crumbEl
            );

            $output[] = $openActive;
            $output[] = get_the_time('F');
            $output[] = $closeActive;
        } elseif (is_year()) {
            if (get_option('page_for_posts')) {
                $blogPageId = get_option('page_for_posts');
                $output[] = sprintf(
                    '<%s><a href="%s">%s</a></%s>',
                    $crumbEl,
                    get_permalink($blogPageId),
                    get_the_title($blogPageId),
                    $crumbEl
                );
            }

            $output[] = $openActive;
            $output[] = get_the_time('Y');
            $output[] = $closeActive;
        } elseif (is_single() && !is_attachment()) {
            if ('post' !== get_post_type()) {
                $postType = get_post_type_object(get_post_type());
                $typeSlug = $postType->rewrite;
                $typeLink = trailingslashit(esc_url(home_url('/')).$typeSlug['slug']);
                $output[] = sprintf(
                    '<%s><a href="%s">%s</a></%s>',
                    $crumbEl,
                    $typeLink,
                    $postType->labels->singular_name,
                    $crumbEl
                );
            } else {
                if (get_option('page_for_posts')) {
                    $blogPageId = get_option('page_for_posts');
                    $output[] = sprintf(
                        '<%s><a href="%s">%s</a></%s>',
                        $crumbEl,
                        get_permalink($blogPageId),
                        get_the_title($blogPageId),
                        $crumbEl
                    );
                }

                $cat = get_the_category();

                if (isset($cat[0])) {
                    $cat = $cat[0];
                    $parents = get_category_parents($cat, true, sprintf('</%s><%s>', $crumbEl, $crumbEl));
                    $parents = preg_replace('# title=".*"#', '', $parents);
                    $output[] = mb_substr(sprintf('<%s>%s', $crumbEl, $parents), 0, -4);
                }
            }

            $output[] = $openActive;
            $output[] = get_the_title();
            $output[] = $closeActive;
        } elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404()) {
            $postType = get_post_type_object(get_post_type());
            $output[] = $openActive;
            $output[] = $postType->labels->singular_name;
            $output[] = $closeActive;
        } elseif (is_attachment()) {
            if (get_option('page_for_posts')) {
                $blogPageId = get_option('page_for_posts');
                $output[] = sprintf(
                    '<%s><a href="%s">%s</a></%s>',
                    $crumbEl,
                    get_permalink($blogPageId),
                    get_the_title($blogPageId),
                    $crumbEl
                );
            }

            $parent = get_post($post->post_parent);
            $cat = get_the_category($parent->ID);

            if (isset($cat[0])) {
                $cat = $cat[0];
                $parents = get_category_parents($cat, true, sprintf('</%s><%s>', $crumbEl, $crumbEl));
                $parents = preg_replace('# title=".*"#', '', $parents);
                $output[] = mb_substr(sprintf('<%s>%s', $crumbEl, $parents), 0, -4);
            }

            $output[] = sprintf(
                '<%s><a href="%s">%s</a></%s>',
                $crumbEl,
                get_permalink($parent),
                $parent->post_title,
                $crumbEl
            );

            $output[] = $openActive;
            $output[] = get_the_title();
            $output[] = $closeActive;
        } elseif (is_page() && !$post->post_parent) {
            $output[] = $openActive;
            $output[] = get_the_title();
            $output[] = $closeActive;
        } elseif (is_page() && $post->post_parent) {
            $parentId = $post->post_parent;
            $frontId = get_option('page_on_front');

            if ($parentId != $frontId) {
                $breadcrumbs = [];

                while ($parentId) {
                    $page = get_page($parentId);

                    if ($parentId != $frontId) {
                        $breadcrumbs[] = sprintf(
                            '<%s><a href="%s">%s</a></%s>',
                            $crumbEl,
                            get_permalink($page->ID),
                            get_the_title($page->ID),
                            $crumbEl
                        );
                    }

                    $parentId = $page->post_parent;
                }

                for ($i = count($breadcrumbs) - 1; $i >= 0; $i--) {
                    $output[] = $breadcrumbs[$i];
                }
            }

            $output[] = $openActive;
            $output[] = get_the_title();
            $output[] = $closeActive;
        } elseif (is_tag()) {
            if (get_option('page_for_posts')) {
                $blogPageId = get_option('page_for_posts');
                $output[] = sprintf(
                    '<%s><a href="%s">%s</a></%s>',
                    $crumbEl,
                    get_permalink($blogPageId),
                    get_the_title($blogPageId),
                    $crumbEl
                );
            }

            $output[] = $openActive;
            $output[] = single_tag_title('', false);
            $output[] = $closeActive;
        } elseif (is_author()) {
            global $author;

            if (get_option('page_for_posts')) {
                $blogPageId = get_option('page_for_posts');
                $output[] = sprintf(
                    '<%s><a href="%s">%s</a></%s>',
                    $crumbEl,
                    get_permalink($blogPageId),
                    get_the_title($blogPageId),
                    $crumbEl
                );
            }

            $userdata = get_userdata($author);
            $output[] = $openActive;
            $output[] = $userdata->display_name;
            $output[] = $closeActive;
        } elseif (is_404()) {
            $output[] = $openActive;
            $output[] = __('Error 404', 'novusopress');
            $output[] = $closeActive;
        } elseif (has_post_format() && !is_singular()) {
            $output[] = $openActive;
            $output[] = get_post_format_string(get_post_format());
            $output[] = $closeActive;
        }

        $output[] = sprintf('</%s>', $listEl);
        $output[] = PHP_EOL.'    ';
        $output[] = sprintf('</%s><!-- #%s -->', $containerEl, $containerId);

        $output = implode('', $output);

        return apply_filters('novusopress_view_breadcrumbs_output', $output);
    }
27305
public function makeDir($name, $parentID = 0)
    {
        $data = [
            'name'      => $name,
            'parent_id' => $parentID
        ];

        return $this->post('files/create-folder', $data, \false, 'file');
    }
1374564
private static function normalizeMenu(&$assigned, &$menus, $callback, $parent = null)
    {
        $result = [];
        $order = [];
        foreach ($assigned as $id) {
            $menu = $menus[$id];
            $item = [
                'id'=> $menu['id'],
                'name' => $menu['name'],
                'route' => static::parseRoute($menu['route'])[0],
                'parent_id' => $menu['parent']
            ];

            $result[] = $item;
            $order[] = $menu['order'];

        }
        if ($result != []) {
            array_multisort($order, $result);
        }

        return $result;
    }
1217134
public function parentIdInjection(array & $materialIds)
    {
        // Cut off related and table materials
        $this->query
            ->className('material')
            ->cond('MaterialID', $materialIds)
            ->cond('parent_id', 0)
            ->cond('Active', 1)
            ->order_by('Modyfied', 'DESC')
            ->fieldsNew('MaterialID', $materialIds);
    }
861649
public function getCountByParent( $parentId, $parentType ) {

		$modelClass	= static::$modelClass;

		return $modelClass::queryByParent( $parentId, $parentType )->count();
	}
1262277
public function getParentNodes($dsId)
    {
        $parents = [];

        $node = $this->getNode($dsId);
        while ($node) {
            // get parent
            $node = $this->getParentNode($node->getDsId());

            // add id
            if ($node) {
                $parents[] = $node;
            }
        }

        return $parents;
    }
1180789
public function setParentId($parentId)
    {
        return (is_string($this->parentAttribute) && !empty($this->parentAttribute)) ?
        $this->{$this->parentAttribute} = $parentId : null;
    }
1312420
final protected function parseData(array $data, $parentId = 0)
    {
        $result = array();

        foreach ($data as $subArray) {
            $nested = array();

            if (isset($subArray[$this->childrenKey])) {
                // Recursive call
                $nested = $this->parseData($subArray[$this->childrenKey], $subArray[RelationBuilder::TREE_PARAM_ID]);
            }

            $result[] = array(
                RelationBuilder::TREE_PARAM_ID => $subArray[RelationBuilder::TREE_PARAM_ID], 
                RelationBuilder::TREE_PARAM_PARENT_ID => $parentId
            );

            $result = array_merge($result, $nested);
        }

        return $result;
    }
314199
private function validateParentId($parentId) : array
    {
        if (!empty($parentId)) {
            if (is_array($parentId)) {
                if (count($parentId) != count($parentId, COUNT_RECURSIVE)) {
                    throw new JsonParserException(
                        'Error assigning parentId to a CSV file! $parentId array cannot be multidimensional.',
                        [
                            'parentId' => $parentId
                        ]
                    );
                }
            } else {
                $parentId = ['JSON_parentId' => $parentId];
            }
        } else {
            $parentId = [];
        }
        $result = [];
        foreach ($parentId as $key => $value) {
            $result[$this->structure->getParentTargetName($key)] = $value;
        }
        return $result;
    }
130907
public static function getUrlsByParentId($isSuper, $menuIdList, $parentId, $condition = '', $params = [], $order = 'display_order asc')
    {
        $data = static::find()
            ->normal()
            ->findByParentId($parentId)
            ->andWhere($condition, $params)
            ->active()
            ->orderBy($order)
            ->asArray()
            ->all();
        $urls = [];
        if ($data) {
            foreach ($data as $item) {
                if ($isSuper || in_array($item['menu_id'], $menuIdList)) {
                    $menuUrls = DpAdminMenuUrlRelation::getAllUrlByMenuId($item['menu_id']);
                    if ($menuUrls) {
                        foreach ($menuUrls as $menuUrl) {
                            $urls[$menuUrl['alias']] = Url::toRoute($menuUrl['route']);
                        }
                    }
                    $childrenUrls = static::getUrlsByParentId($isSuper, $menuIdList, $item['menu_id'], $condition, $params, $order);
                    if ($childrenUrls) {
                        $urls = array_merge($urls, $childrenUrls);
                    }
                }
            }
        }

        return $urls;
    }
339075
public function load($parentID = null)
    {
        if ($parentID !== null) {
            $this->parentID = $parentID;
        }
        if ( ! is_array($rows = $this->selFromDbAll())) {
            return false;
        }

        if ( ! $this->fillItems($rows)) {
            return false;
        }

        return true;
    }
1231656
public static function findByParentCartId( $parentId, $parentType, $cartId ) {

		return self::find()->where( 'parentId=:pid AND parentType=:ptype AND cartId=:cid', [ ':pid' => $parentId, ':ptype' => $parentType, ':cid' => $cartId ] )->one();
	}
859403
public static function queryByParentModelId( $parentId, $parentType, $modelId ) {

		$tableName = static::tableName();

		return self::queryWithModel()->where( "$tableName.parentId=:pid AND $tableName.parentType=:ptype AND $tableName.modelId=:mid", [ ':pid' => $parentId, ':ptype' => $parentType, ':mid' => $modelId ] );
	}