Repository navigation
Document post types and model slugging, and correct three outdated claims - #594
Open
karl-bullock wants to merge 1 commit into
Open
karl-bullock wants to merge 1 commit into
karl-bullock wants to merge 1 commit into
Conversation
…aims extend/post-types.md and extend/slugging.md contained nothing but a heading, while both are listed under Advanced Guides in extendSidebar, so they shipped as reachable blank pages. extend/views.md already linked into the slugging one when describing $slugManager. Post Types now covers the type discriminator on posts, writing an event post on AbstractEventPost with a static $type, MergeableInterface and what saveAfter() must return, registering with Extend\Post, creating the post from a listener through Discussion::mergePost(), the EventPost component and its overridable methods, and registering that component with Extend.PostTypes. Model Slugging now covers what a slug driver is and that it is an admin-selectable option, core's drivers per model, the slug_driver_<class> setting and its fallback, writing a SlugDriverInterface, why fromSlug() takes an actor, registering with Extend\ModelUrl, why a newly sluggable model must register a default driver, BatchSlugDriverInterface, and labelling drivers in the admin UI via the static AdminPage::modelLocale and BasicsPage::driverLocale. extend/theme.md said "There currently isn't an extender to modify Less variable values in the PHP layer, but this is planned for future releases". Extend\Theme::addCustomLessVariable() does that, and Extend\Settings::registerLessConfigVar() exposes a setting as a Less variable, which is how core defines @config-primary-color. None of the Theme extender's four methods were documented, so that paragraph is replaced with sections for the custom variable, the setting-backed variable, custom Less functions and the file overrides. extend/i18n.md contradicted itself on gender: one paragraph credits ICU MessageFormat with handling genderization, while the Dealing with Gender section said support was still to come. The frontend translator is format-message, a full ICU implementation, and ICU plural is already used across core.yml, so select works today and is now documented. extend/frontend-pages.md quoted a DiscussionPageResolver that no longer exists, including a docblock referring to beta 15. The snippet now matches core 2.x, where the slug handling is a canonicalizeDiscussionSlug() method that extensions can override.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two pages in the 2.x extend sidebar ship with nothing but a heading, and three pages state things about 2.0 that are no longer true. This fills in the first and corrects the second. Every API detail below was read out of
flarum/framework@2.xrather than inferred.The two blank pages
extend/post-types.mdcontained only# Post Types, andextend/slugging.mdonly# Model Slugging. Both are listed under Advanced Guides inextendSidebar, so they were reachable, visibly blank pages, andextend/views.mdalready linked into the slugging one where it mentions$slugManager.Post Types now covers the
typediscriminator onpostsand what makes an event post different from a comment; building one onAbstractEventPostwith a static$typeand whycontentcan be treated as an array;MergeableInterface, whatsaveAfter()receives and what it has to return, and how a pair of opposite events cancels out; registering withExtend\Post; creating the post from a listener throughDiscussion::mergePost(), including that the post it returns may not be the instance you passed and may no longer exist; theEventPostcomponent with a table of its four overridable methods and theuser/username/timevariables it injects into the translation; and registering the component withExtend.PostTypes. It points atflarum/lockas a complete worked example, because that extension happens to use every piece.Model Slugging now covers what a slug driver is, and that adding one gives the admin an option rather than changing every forum; a table of core's five drivers across
DiscussionandUser; theslug_driver_<class>setting and its fallback todefaultwhen the stored value names a driver that is no longer registered; writing aSlugDriverInterfaceand whyfromSlug()takes an actor; the round-tripping constraint, and why core's default keeps the ID in the slug; registering withExtend\ModelUrl; making a model of your own sluggable, and why such a model must register a driver under the identifierdefault(asflarum/tagsdoes forTag);BatchSlugDriverInterfacefor resolving many slugs in one query, and checking for it before using it; and labelling your drivers in the admin UI, which needs the staticAdminPage.modelLocaleandBasicsPage.driverLocaleextended, since otherwise the dropdown renders your raw identifier and the heading renders the raw class name.Three claims 2.0 has outrun
extend/theme.mdsaid a capability does not exist when it does. The page read: "There currently isn't an extender to modify Less variable values in the PHP layer, but this is planned for future releases."Extend\Theme::addCustomLessVariable()does exactly that, andExtend\Settings::registerLessConfigVar()exposes a database setting as a Less variable, which is how core's own@config-primary-colorand@config-secondary-colorare defined.Theme::addCustomLessVariable's docblock even cross-references theSettingsmethod. None of theThemeextender's four methods were documented anywhere in the docs, so that paragraph is replaced with sections for the custom variable, the setting-backed variable,addCustomLessFunction, and theoverrideLessImport/overrideFileSourcefile overrides. The custom-variable section carries a warning that the returned value is written into the stylesheet verbatim and is not escaped or quoted for you, which is what the extender's own docblock cautions about.extend/i18n.mdcontradicted itself about gender. One paragraph credits ICU MessageFormat with handling "pluralization and genderization"; the "Dealing with Gender" section a few lines later said support "will be added in a future version of Flarum". The frontend translator isformat-message, a full ICU implementation, and ICUpluralis already used throughoutcore.yml, soselectworks today. That section now documents it, with a note that Flarum does not store a gender for users so the variable has to come from the extension's own data.extend/frontend-pages.mdquoted code that no longer exists. TheDiscussionPageResolverexample showed a freegetDiscussionIdFromSlug()function whose docblock read "A more robust system will be implemented alongside UTF-8 support in beta 15". In core 2.x that is acanonicalizeDiscussionSlug()method, with a different docblock, andonmatchhas changed as well. The snippet now matches core, with a note that being a method is what lets an extension override it, linking to the new slugging page.Verification
npm run buildcompiles the English docs with no errors, both new pages render, and Docusaurus's own broken-anchor check reports nothing for the 2.x English docs. EveryFlarum\*class reference and everyflarum/{common,forum,admin}/...import path in the new pages resolves against the 2.x source.Not included
I left
config.mdalone, since #573 is already rewriting it, and its new note that extensions document their own config keys covers the one gap I had found there.Separately,
flarum/realtimeis bundled but has no admin-facing documentation on this site, while its README carries a full production setup guide. That needs a decision about shape rather than a guess from me, so I opened #593 for it instead of writing something here.