6.0 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	Title, Added
| Title | Added | 
|---|---|
| Form Extensibility for APS Stencil | v1.9.0 | 
Form Extensibility for APS Stencil
This page describes how you can customize ADF forms to your own specification.
Contents
There are two ways to customize the form
Replace default form widgets with custom components
This is an example of replacing the standard Text widget with a custom component for all APS forms rendered within the <adf-form> component.
- 
Create a simple form with some Textwidgets:Every custom widget must inherit the WidgetComponentclass in order to function properly:import { Component } from '@angular/core'; import { WidgetComponent } from '@alfresco/adf-core'; @Component({ selector: 'custom-editor', template: ` <div style="color: red">Look, I'm a custom editor!</div> ` }) export class CustomEditorComponent extends WidgetComponent {}
- 
Add it to the application module or any custom module that is imported into the application one: import { NgModule } from '@angular/core'; import { CustomEditorComponent } from './custom-editor.component'; @NgModule({ declarations: [ CustomEditorComponent ], exports: [ CustomEditorComponent ] }) export class CustomEditorsModule {}
- 
Every custom widget should be added into the collections: declarationsandexports. If you decided to store custom widgets in a separate dedicated module (and optionally as a separate re-distributable library), don't forget to import it into the main application:@NgModule({ imports: [ // ... CustomEditorsModule // ... ], providers: [], bootstrap: [ AppComponent ] }) export class AppModule {}
- 
Import the FormRenderingServicein any of your Views and override the default mapping, for example:import { Component } from '@angular/core'; import { CustomEditorComponent } from './custom-editor.component'; @Component({...}) export class MyView { constructor(formRenderingService: FormRenderingService) { formRenderingService.setComponentTypeResolver('text', () => CustomEditorComponent, true); } }
- 
At runtime it should look similar to the following: 
Replace custom stencils with custom components
This is an example of rendering custom APS stencils using custom Angular components.
Create a custom stencil
- 
Create a basic stencil and call it Custom Stencil 01:Note: the internal identifieris important as it will become thefield typewhen the form is rendered.
- 
Create a simple html layout for the Formruntime templateandFormeditor templatefields:<div style="color: blue">Custom activiti stencil</div>
- 
Create a test form based on your custom stencil: 
- 
Create a task using the test form. It will look similar to the following: 
Create a custom widget
- 
Load the form created in the previous steps into the ADF <adf-form>component:
- 
Create an Angular component to render the missing content: import { Component } from '@angular/core'; import { WidgetComponent } from '@alfresco/adf-core'; @Component({ selector: 'custom-stencil-01', template: `<div style="color: green">ADF version of custom Activiti stencil</div>` }) export class CustomStencil01 extends WidgetComponent {}
- 
Place it inside a custom module: import { NgModule } from '@angular/core'; import { CustomStencil01 } from './custom-stencil-01.component'; @NgModule({ declarations: [ CustomStencil01 ], exports: [ CustomStencil01 ] }) export class CustomEditorsModule {}
- 
Import it into your Application Module: @NgModule({ imports: [ // ... CustomEditorsModule // ... ], providers: [], bootstrap: [ AppComponent ] }) export class AppModule {}
- 
Import the FormRenderingServicein any of your Views and provide the new mapping:import { Component } from '@angular/core'; import { CustomStencil01 } from './custom-stencil-01.component'; @Component({...}) export class MyView { constructor(formRenderingService: FormRenderingService) { formRenderingService.setComponentTypeResolver('custom_stencil_01', () => CustomStencil01, true); } }
- 
At runtime you should now see your custom Angular component rendered in place of the stencils: 






