UserDocsManifest
class UserDocsManifest implements Flushable (View source)
A utility class which builds a manifest of where to find all user documentation and caches it.
It finds the following information:
- The canonical location of the file for each documentation slug. If more than one module has a doc with the same slug, the module with the highest priority is used.
- Metadata for each doc, such as its title, sort order and frontmatter.
- Which pages have which localisations.
- The tree structure used to display links to the documentation.
Traits
Provides extensions to this object to integrate it with standard config API methods.
A class that can be instantiated or replaced via DI
Constants
| protected CACHE_KEY |
|
| private MODULE_NAME_PATTERN |
Matches a composer package name, e.g. "silverstripe/admin"
Refer to https://getcomposer.org/doc/04-schema.md#name |
| private UNINHERITED_FRONT_MATTER_KEYS |
Frontmatter keys that only apply to the file they're in, so they're never filled in from another file. The title has its own fallback, and "extends" decides if a file is a doc or an extension. |
Config options
| documentation_roots | array | Paths to directories that contain user documentation. |
Properties
| protected | array | $cachedProperties | Array of properties to cache |
Methods
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
Gets the uninherited value for the given config option
An implementation of the factory method, allows you to create an instance of a class
Creates a class instance by the "singleton" design pattern.
Get the request locale and fallbacks in order of precedence.
Completely regenerates the manifest file.
Visit a file to inspect for user help documentation.
Get the path to the documentation root in the given module.
Get the metadata about documentation, optionally for a single locale.
Get the title and link of each ancestor of the doc with the given slug, starting at the root.
Get the hierarchical-structured tree data for the current locale.
Get the slugs of the docs that name each class in their frontmatter, for the current locale.
Get the classes that a doc names in the "classes" key of its frontmatter, including classes that its extensions add.
Get the URL slug for the given documentation file/folder path.
Encode each segment of the slug so that it can be used in a URL.
Get the slug from the path of a doc URL, relative to the URL of the docs action.
Set the manifest properties from cached or newly built data, and clear the data worked out from them.
Details
static Config_ForClass
config()
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
mixed
uninherited(string $name)
Gets the uninherited value for the given config option
static Injectable
create(mixed ...$args)
An implementation of the factory method, allows you to create an instance of a class
This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.
This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();
static Injectable
singleton(string $class = null)
Creates a class instance by the "singleton" design pattern.
It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).
static
flush()
This function is triggered early in the request if the kernel gets flushed.
Each class that implements Flushable implements this function which looks after it's own specific flushing functionality.
static array
getLocalePriority()
Get the request locale and fallbacks in order of precedence.
void
init(bool $includeTests = false)
Initialise the documentation manifest
void
regenerate(array $validPaths, bool $includeTests)
Completely regenerates the manifest file.
void
handleFile(array $data, string $fileName, string $filePath, string $basePath)
Visit a file to inspect for user help documentation.
Updates the $data array in place, so that further transformations (e.g. sorting) can be done before storing the data as manifest state.
string|null
getRootPathInModule(string $module)
Get the path to the documentation root in the given module.
array
getDocData(string|null $locale = null)
Get the metadata about documentation, optionally for a single locale.
For each locale, the doc from the module with the highest priority that has the doc in that locale is used. Note that this does not include the locale fallbacks - use getLocalisedDocData() if you need the data to be flowing through the locale cascade. Extensions are added to each doc in the same way as getLocalisedDocData().
array
getLocalisedDocData()
Get all data about documentation for the current locale.
For each doc, the module with the highest priority that has the doc in any of the current locales is used. Within that module, the current locale falls back to the shortened locale and then to the default locale. For example pt_BR will fallback to pt which will then fallback to en_US which falls back to en.
Extensions are kept separately for each doc, keyed by their extension key. Each extension key uses the same rules as docs, and falls back separately from the doc it extends.
Frontmatter keys that a doc doesn't have are filled in from the docs it overrides or translates, except for keys in UNINHERITED_FRONT_MATTER_KEYS. See inheritFrontMatter().
array
getBreadcrumbs(string $slug, string $baseUrl)
Get the title and link of each ancestor of the doc with the given slug, starting at the root.
The link is null for ancestors without content.
array
getLocalisedTreeData()
Get the hierarchical-structured tree data for the current locale.
Uses the same docs as getLocalisedDocData().
array
getLocalisedClassMap()
Get the slugs of the docs that name each class in their frontmatter, for the current locale.
Only docs with content are included.
Docs that have the class in "primary_for" come first, and then docs are in the order of the navigation tree. The first doc for a class is its main doc.
array
getDocClasses(array $docDatum)
Get the classes that a doc names in the "classes" key of its frontmatter, including classes that its extensions add.
Names that aren't the name of a class are left out, because docs can be for classes from modules that aren't installed.
string
getSlugForPath(string $path, bool $isRootDir = false)
Get the URL slug for the given documentation file/folder path.
The slug for an index file with no directory, such as "index.md", is ".".
static string
encodeSlug(string $slug)
Encode each segment of the slug so that it can be used in a URL.
Dots are encoded so that the URL isn't read as having a file extension, except in "." and ".." segments.
static string
getSlugFromUrlPath(string $path)
Get the slug from the path of a doc URL, relative to the URL of the docs action.
This removes any query string or anchor, and decodes the path.
protected bool
setManifestData(array $data)
Set the manifest properties from cached or newly built data, and clear the data worked out from them.
Properties that are missing or invalid in the data are reset, so empty data resets the manifest.