protected function compileIndexForLayoutLayer(array $layout, $parentKeys = [])
    {
        $permissions = [];

        $unconditional = false;
        $mixed         = false;

        foreach ($layout as $key => $value) {

            if ($value->type() === MenuPresenceType::GROUP) {

                $childKeys = $parentKeys;
                array_push($childKeys, $key);

                $childPermissions = $this->compileIndexForLayoutLayer($value->children(), $childKeys);

                // If the children of the group have unconditional presences,
                // this layer becomes unconditionally displayable as well.
                if (false === $childPermissions) {
                    $mixed = true;
                } elseif (count($childPermissions)) {
                    $permissions = array_merge($permissions, $childPermissions);
                }

                continue;
            }

            // For non-group presences, check the permissions directly
            if ( ! count($value->permissions())) {
                $unconditional = true;
                continue;
            }

            $permissions = array_merge($permissions, $value->permissions());
        }

        $this->permissions = array_merge($this->permissions, $permissions);

        // This layer and its descendants have mixed con/unconditional presences when:
        if ($mixed || count($permissions) && $unconditional) {
            return false;
        }

        array_unique($permissions);

        if (count($parentKeys)) {
            $this->permissionsIndex->setForNode($parentKeys, $permissions);
        }

        return $permissions;
    }