{"record":{"id":"08791dd22f5287d0","repo":"getgrav/grav","slug":"flex-directory-not-defined-object-is-not-fully-de","errorCode":null,"errorMessage":"Flex Directory not defined, object is not fully defined","messagePattern":"Flex Directory not defined, object is not fully defined","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"system/src/Grav/Framework/Flex/FlexIndex.php","lineNumber":202,"sourceCode":"    }\n\n    /**\n     * {@inheritdoc}\n     * @see FlexCollectionInterface::getFlexType()\n     */\n    public function getFlexType(): string\n    {\n        return $this->getFlexDirectory()->getFlexType();\n    }\n\n    /**\n     * {@inheritdoc}\n     * @see FlexCollectionInterface::getFlexDirectory()\n     */\n    public function getFlexDirectory(): FlexDirectory\n    {\n        if (null === $this->_flexDirectory) {\n            throw new RuntimeException('Flex Directory not defined, object is not fully defined');\n        }\n\n        return $this->_flexDirectory;\n    }\n\n    /**\n     * {@inheritdoc}\n     * @see FlexCollectionInterface::getTimestamp()\n     */\n    public function getTimestamp(): int\n    {\n        $timestamps = $this->getTimestamps();\n\n        return $timestamps ? max($timestamps) : time();\n    }\n\n    /**\n     * {@inheritdoc}","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/getgrav/grav/blob/6040efed04efa69b8209448ed81308e7c24147c2/system/src/Grav/Framework/Flex/FlexIndex.php#L184-L220","documentation":"FlexIndex is a lazy collection that needs a FlexDirectory to resolve its entries; if the private _flexDirectory was never set, getFlexDirectory() throws 'Flex Directory not defined, object is not fully defined'. Indexes are meant to be built through a directory (getIndex()) or via createFromStorage/createFromEntries with a directory option, so hitting this means the index was constructed incompletely.","triggerScenarios":"Calling getFlexType()/getFlexDirectory()/render() or any directory-dependent method on an index built with FlexIndex::createFromArray(['entries' => [...]]) without passing 'directory' in options; unserializing a cached index whose directory link was lost; subclass code that forgot to call setFlexDirectory().","commonSituations":"Custom collections assembled by hand in plugins instead of via $directory->getIndex(); caching FlexIndex objects directly in a cache backend; upgrading Grav versions where index internals changed shape.","solutions":["Build indexes from the directory: $index = $flex->getDirectory('pages')->getIndex();.","When using static creators, always pass the directory: FlexIndex::createFromEntries($entries, ['directory' => $directory]).","Cache only plain entry arrays and rebuild the index after retrieval.","If you subclass FlexIndex, ensure the constructor/create path sets the directory."],"exampleFix":"// before\n$index = FlexIndex::createFromArray(['entries' => $entries]);\n$type = $index->getFlexType(); // throws\n\n// after\n$index = FlexIndex::createFromEntries($entries, ['directory' => $directory]);\n$type = $index->getFlexType();","handlingStrategy":"validation","validationCode":"// Only use directory-derived indexes; when building manually, always pass the directory\n$directory = $grav['flex']->getDirectory($type);\n$index = $directory->getIndex(); // safe: directory guaranteed\n// manual path:\n$index = FlexIndex::createFromEntries($entries, ['directory' => $directory]);","typeGuard":null,"tryCatchPattern":"try {\n    $directory = $index->getFlexDirectory();\n} catch (\\Grav\\Framework\\Flex\\Exception\\RuntimeException $e) {\n    // index was built incompletely: rebuild from the flex registry\n    $directory = $grav['flex']->getDirectory($fallbackType);\n    $index->setFlexDirectory($directory);\n}","preventionTips":["Never construct FlexIndex directly or cache index objects; cache entry arrays instead.","Always obtain indexes via $directory->getIndex().","In FlexIndex subclasses, ensure the directory option reaches the parent constructor."],"tags":["grav","flex","collection","initialization"],"backgroundTag":"uninitialized-object-state","analyzedSha":"6040efed04efa69b8209448ed81308e7c24147c2","analyzedAt":"2026-08-17T05:07:31.593Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}