Find the "root" widgetmap (the one that has no parent).

@param $widgetMaps

@return WidgetMap|null
507977
private function findRootWidgetMap($widgetMaps)
    {
        $rootWidgetMap = null;
        foreach ($widgetMaps as $_widgetMap) {
            if (!$_widgetMap->getParent()) {
                $rootWidgetMap = $_widgetMap;
                break;
            }
        }

        return $rootWidgetMap;
    }
521609
public function addWidgetMap(WidgetMap $widgetMap)
    {
        if (!$widgetMap->getView()) {
            $widgetMap->setView($this);
        }
        $this->widgetMaps[] = $widgetMap;
    }
912109
public function getWidgets($widgetType = null)
    {
        $widgets = array();

        foreach ($this->getPortfolioWidgets() as $portfolioWidget) {
            $widget = $portfolioWidget->getWidget();
            if ($widgetType !== null || $widgetType === $widget->getWidgetType()) {
                $widgets[] = $widget;
            }
        }

        return $widgets;
    }
452323
public function getInputGroup(Widget $widget)
    {
        if ($this->widgetConfig[$widget->type]['input_group'] && $widget->bs_addInputGroup) {
            return InputGroupHelper::forWidget($widget);
        }

        return null;
    }
408216
public function ancestor($lookup = null)
    {
        /** @var Pages $pages */
        $pages = Grav::instance()['pages'];

        return $pages->ancestor($this->route, $lookup);
    }
969151
public function getWidgets()
    {
        if ($this->widgets === null || !array_key_exists('value', $this->widgets)) {
            return;
        }

        //return an array, no matter one or many widget defined
        if (count($this->widgets['value']) > 1) {
            return $this->widgets['value'];
        } else {
            return [$this->widgets['value']];
        }
    }
722809
public static function getRowMap($key=NULL)
    {
        if ($key) {
            return isset(self::$_keyRowMap[$key]) ? self::$_keyRowMap[$key] : NULL;
        } else {
            return self::$_keyRowMap;
        }
    }
639612
private function getWidgetLocalClass(string $widgetType) : AbstractWidget
    {
        //====================================================================//
        // Safety Check => Widget Type is Mapped
        if (!in_array($widgetType, array_keys(self::$widgetsMap), true)) {
            throw new Exception(sprintf("Unknown Widget Type : %s", $widgetType));
        }
        //====================================================================//
        // Get Widget Class
        $className = static::$widgetsMap[$widgetType];
        //====================================================================//
        // Safety Check => Validate Widget Class
        if (true !== $this->isValidWidgetClass($className)) {
            throw new Exception($this->isValidWidgetClass($className));
        }
        //====================================================================//
        // Create Widget Class
        $genericWidget = new $className($this);
        //====================================================================//
        // If StandaloneWidget => Configure it!
        if (is_subclass_of($className, AbstractStandaloneWidget::class)) {
            $genericWidget->configure($widgetType, $this->getWebserviceId(), $this->getConfiguration());
        }

        return $genericWidget;
    }
912264
public function map($map = null) {
		if ($map !== null) {
			$this->_map = $map;
			return $this;
		}
		return $this->_map;
	}
348302
static public function getMapIdParent()
    {
        if (self::$_mapIdParent)
        {
            return self::$_mapIdParent;
        }

        $model = Cache::remember('map_tree', self::$lifeCache, function()
        {
            return DB::table('menus')->get();
        });

        $map = array();

        foreach ($model as $val)
        {
            $map[$val->id] = $val->parent_id;
        }
        unset($val);
        
        self::$_mapIdParent = $map;
       
        return $map;
    }
602435
public function getWidget($alias)
    {
        if (!isset($this->widgets[$alias])) {
            throw new WidgetException(sprintf('View widget with alias "%s" does not exist.', $alias));
        }

        return $this->widgets[$alias];
    }
306873
public function key()
    {
        return isset($this->mappedEnums[$this->iteratorIndex])
            ? $this->mappedEnums[$this->iteratorIndex]
            : null;
    }
247540
protected function widgetFactory()
    {
        if ($this->widgetFactory === null) {
            throw new RuntimeException(sprintf(
                'Widget Factory is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->widgetFactory;
    }
1085502
public function getMap($locale, $key = null)
    {
        // Get sanitized locale
        $locale = Locale::sanitizeLocale($locale);

        if ($key) {
            return isset($this->maps[$locale][$key]) ? $this->maps[$locale][$key] : null;
        }

        return isset($this->maps[$locale]) ? $this->maps[$locale] : null;
    }
501019
private Map<String, Scope> getSubMap(Map<String, Map<String, Scope>> parent, String key) {

	Map<String, Scope> context = parent.get(key);
	if (context != null) return context;

	context = MapFactory.<String, Scope>getConcurrentMap();
	parent.put(key, context);
	return context;

    }
934536
public function getContextualChildren($position)
    {
        $widgetMapChildren = [];
        $viewWidgetMaps = $this->getContextualView()->getWidgetMapsForViewAndTemplates();

        foreach ($viewWidgetMaps as $viewWidgetMap) {
            if ($viewWidgetMap->getParent() == $this && $viewWidgetMap->getPosition() == $position) {
                $widgetMapChildren[] = $viewWidgetMap;
            }
        }

        return $widgetMapChildren;
    }
64462
protected function getFinalEntityMapper(array $nestedRelations) : IEntityMapper
    {
        $entityMapper = null;

        foreach (array_reverse($nestedRelations) as $relation) {
            if ($relation instanceof EntityRelation) {
                $entityMapper = $relation->getEntityMapper();
                break;
            }
        }

        return $entityMapper ?: $this->rootEntityMapper;
    }