Create Group
Create user groups through a reusable, extensible form and AJAX workflow.
Purpose and architecture
Create Group provides a ready-to-use form and AJAX workflow for creating a user group. It extends
Core\Base,
uses CoreUi\Form\FieldBuilder to render its fields, and requires an
application-specific
group collection. There is no generic document creator: group creation has its own validation and
persistence rules.
The default form contains a required group name and an active checkbox. Name length constraints are read from the configured collection. The create action validates the name, including uniqueness, before persisting a new group document.
Integrating Create Group
Extend CoreApp\Create\CreateGroup in the application context and map the appropriate
group
collection. The shared class returns null by default, so the mapping is required.
use Core\Registry;
use Core\Collection\BaseGroupCollection;
use CoreApp\Create\CreateGroup as CoreAppCreateGroup;
class CreateGroup extends CoreAppCreateGroup
{
protected function getGroupCollection(): BaseGroupCollection|null
{
return Registry::get(AdminGroupCollection::class);
}
}
The example follows the appnetos-api-dev admin integration. Use the concrete collection
class provided by your own application.
Extension points
| Method | Purpose |
|---|---|
getGroupCollection(): BaseGroupCollection|null |
Map the group collection used for validation and persistence. |
getFormData(array|null $formData = null): array |
Provide or extend FieldBuilder field definitions and redisplay validation errors. |
createGetFormData(): array |
Read and normalize submitted values. |
createValidateFormData(array &$formData): void |
Run application-specific validation in addition to the shared name validation. |
createValidateName(array &$formData): void |
Validate the required, length-constrained, unique group name. |
createGroupDocument(array $formData): BaseDocument |
Build the document before persistence; override to attach additional properties. |
getBaseTemplate(), getFormTemplate(), getSuccessTemplate() |
Override the relevant Twig templates. |
getUserIsSignedIn(): bool |
Customize the authentication requirement. |
Real-world example: appnetos-api-dev
The admin implementation overrides getFormData() to add an administrator checkbox and
dynamically generated REST API permission fields. It also extends createGetFormData()
to
collect the submitted permission values and createGroupDocument() to attach the
resulting
permissions to the new group. The existing form rendering and AJAX submission remain reusable.
This is an example of extending a specialized Core App rather than rebuilding a complete creation form.
Rendering, AJAX and customization
The Core App uses FieldBuilder to produce the form view. Its #[Ajax] create()
action validates submissions, re-renders the form with errors when necessary, and persists the
created
document on success. Core App JavaScript is registered automatically.
Templates are organized by Bootstrap version (the supplied package includes Bootstrap 5.3 templates) and may be replaced by applications. Translation files are supplied with the Core App. The FieldBuilder component is documented separately under Core UI.