CSSmartTemplatePlugin
extends CSPlugin
in package
Plugin that can be inherited to define a @link CSSmartTemplate
To implement a CSSmartTemplatePlugin you have to provide a class ending on SmartTemplate and store it to any plugins/smart subdirectory. To define the templates behaviour and layout overwrite the @link addPages() method.
Tags
Table of Contents
- __call() : mixed|string
- All method calls which are not defined within the plugin are forwarded to the module Therefore it is possible to get, e.g. the label by calling the getSuiteName() method.
- _construct() : void
- The construct method may be used to initialize custom plugin properties it is called immediately after instantiating the plugin all arguments passed to the getPlugins method are also available in this method.
- addAlternativePluginFolder() : void
- A path to a specific folder in which should be search for plugins.
- addContent() : void
- This is the entry point for the framework to tell the template to become active.
- addDefaultPage() : CSSmartPage
- Standard Method that can be overwritten by templates that adds a default page
- addPages() : void
- This is the most important method to implement when defining your CSSmartTemplate Use the $doc parameter to modify the document as required.
- addPresetField() : void
- Call this function to add another preset field for this template
- addPresetFieldsToEditor() : mixed
- This method can will be used by CSGuiEditors to add your template specific preset fields to the editor
- createDefaultFolders() : void
- Creates the Default Folders for a Template
- createMacro() : CSSmartMacro
- Creates a new Macro within the template
- createView() : CSSmartCSView
- Creates a new CSSmartCSView that can be used in templating to create HTML separated from PHP
- encode() : string
- Encodes the HTML entities in a text
- finalize() : void
- This method will be called by the renderer once the internal tcpdf object has been created and the html output provided through the addPages method was placed. It is the final hook to deal with the extended api of the tcpdf object, which has a very rich and powerful api.
- getAlternativePluginFolder() : array<string|int, mixed>
- getAvailableFonts() : array<string|int, mixed>
- This method returns all font files which are used in the default css files of the template.
- getAvailableFormats() : mixed
- Allows the Template Developer to narrow the available renders
- getBaseName() : string
- Returns the short name of the plugin without the SmartTemplate at the end
- getDefaultCSSFile() : string
- Searches a CSS File which has the same name as the Template File Note: You can use the method @see getDefaultCSSFiles to collect the files of the parent templates as well
- getDefaultCSSFiles() : array<string|int, mixed>
- Collects all CSS Files which have the same name as the Template File for the current class and all parents
- getDefaultFonts() : array<string|int, string>
- Collects all Font Files which are in the fonts folder of the Template File for the current class and all parents
- getDefaultFooter() : string
- Overwrite this method to modify the way of building the footer If the parameter contains one element, this will be placed in the middle, if two they will be placed left and right and if three they will be placed left, center and right
- getDefaultFormat() : string
- The Default Page Format is used by the addDefaultPage Object and can be overwritten by templates
- getDefaultHeader() : string
- Overwrite this method to modify the way of building the header If the parameter contains one element, this will be placed in the middle, if two they will be placed left and right and if three they will be placed left, center and right
- getDefaultMargins() : array<string|int, float>
- The Default Page Margins are used by the addDefaultPage Object and can be overwritten by templates
- getDefaultOrientation() : string
- The Default Page Orientation is used by the addDefaultPage Object and can be overwritten by templates
- getDefaultPaddings() : array<string|int, float>
- The Default Page Paddings are used by the addDefaultPage Object and can be overwritten by templates
- getDescription() : string
- Get the description of the plugin
- getDocument() : CSSmartDocument
- Gets the internal CSSmartDocument reference
- getHttpMethod() : string
- Reads out the http method defined for this plugin
- getImageUrl() : string
- This method will return an url to the passed image depending on the format.
- getItems() : array<string|int, CSItemApiItem>
- Utility method that can be used by templates to get items If the $IDs contains one ID and this is folder, also the children are used
- getLevel() : int
- The getLevel method may be overwritten in the plugins and defines the order, the plugins are called, where the highest level is called first.
- getMetaData() : CSMetaData
- Returns the CSMetaData of the current plugin.
- getModule() : CSModule
- Returns the module, if the plugin is defined within a module.
- getPlaceholder() : string
- Ignore this method
- getPlugin() : CSPlugin|null
- Returns a CSPlugin for the given plugin type and plugin class name.
- getPluginChooser() : array<string|int, mixed>
- Returns an array all defined CSPlugins for the current plugin type
- getPluginData() : mixed
- getPluginDefinitionFile() : string
- Returns the path to the file, the plugin is defined.
- getPluginName() : mixed
- getPluginPath() : string
- Get the plugin subdirectory
- getPlugins() : array<string|int, CSPlugin>
- Returns all defined CSPlugins for the current plugin type It should be used to get all matching plugins for a given plugin api.
- getPluginsInModule() : array<string|int, mixed>
- Returns all CSPlugins for the current plugin type which are defined within the given module It should be used to get all matching plugins for a given plugin api.
- getPreset() : CSSmartPreset
- Returns the current preset to be used
- getPresetValue() : mixed
- Provides a preset value for a given parameter
- getPreviewUrl() : string
- Tries to find a URL for this template by choosing the next best html or xml preset export url
- getView() : CSSmartView
- Gets the current CSSmartView If no CSSmartView has been created, it is created on the fly
- getViewScriptFolders() : array<string|int, string>
- Collects all script folders under the Template File for the current class and all parents
- getViewScripts() : array<string|int, string>
- Returns all View Scripts for the Template
- isAvailable() : bool
- This method is called to check, whether the plugin is available.
- isAvailableForContext() : bool
- Let the plugin decide, if it should be available for a given context the context may be any kind of object that a consumer of templates might pass with the expectation, that only matching templates should be returned. If no context is given, all templates can be returned
- isVirtualTemplate() : bool
- Templates can have be declared virtual to serve only for inheritance purposes The default way to declare a template as virtual is to use the prefix "master" or use an initial underscore in the name
- resetLoadedPlugins() : mixed
- reset the internal plugins cache for loaded plugins
- setDocument() : void
- Sets the internal document reference This method is called by the CSSmartTemplate before calling the addPages method so that submethods can at any time access the current document object without passing the document
- setHttpMethod() : mixed
- Allows to overwrite the standard http method handling which is through GET
- setPreset() : void
- Sets the preset
- shouldBeSelectableInUI() : bool
- Defines if the template should be selectable in the UI interface.
- supportsFormat() : bool
- Method that tells if a given format or at least one out an array of formats is available
Methods
__call()
All method calls which are not defined within the plugin are forwarded to the module Therefore it is possible to get, e.g. the label by calling the getSuiteName() method.
public
__call(mixed $methodName, mixed $methodArguments) : mixed|string
Parameters
- $methodName : mixed
- $methodArguments : mixed
Tags
Return values
mixed|string —_construct()
The construct method may be used to initialize custom plugin properties it is called immediately after instantiating the plugin all arguments passed to the getPlugins method are also available in this method.
public
_construct() : void
Tags
Return values
void —addAlternativePluginFolder()
A path to a specific folder in which should be search for plugins.
public
static addAlternativePluginFolder(mixed $sPluginFolder) : void
Parameters
- $sPluginFolder : mixed
Tags
Return values
void —addContent()
This is the entry point for the framework to tell the template to become active.
public
addContent(CSSmartDocument $doc, CSSmartPreset $preset) : void
By default it forwards the call to the @see addPages method.
Use the $doc parameter to modify the document as required.
Parameters
- $doc : CSSmartDocument
-
the CSSmartDocument object that the template represents
- $preset : CSSmartPreset
-
any parameters as CSSmartPreset object
Tags
Return values
void —addDefaultPage()
Standard Method that can be overwritten by templates that adds a default page
public
addDefaultPage([string $html = '' ][, array<string|int, string> $headers = array() ][, array<string|int, string> $footers = array() ][, string $key = '' ]) : CSSmartPage
Parameters
- $html : string = ''
-
the html content on the page, can also be added later to the page
- $headers : array<string|int, string> = array()
-
array with one, two or three header html textblocks that can be added from the default template to the center, left and right or left, center, and right area of the header
- $footers : array<string|int, string> = array()
-
array with one, two or three footer html textblocks that can be added from the default template to the center, left and right or left, center, and right area of the footer
- $key : string = ''
-
an optional key for the page, so that it can be later replaced by other pages
Tags
Return values
CSSmartPage —the resulting page object
addPages()
This is the most important method to implement when defining your CSSmartTemplate Use the $doc parameter to modify the document as required.
public
addPages(CSSmartDocument $doc, CSSmartPreset $preset) : void
Parameters
- $doc : CSSmartDocument
-
the CSSmartDocument object that the template represents
- $preset : CSSmartPreset
-
any parameters as CSSmartPreset object
Tags
Return values
void —addPresetField()
Call this function to add another preset field for this template
public
final addPresetField(string $sFieldName, string|array<string|int, string> $sLabel[, mixed $mType = 'caption' ][, mixed $mDefault = '' ][, string $sPaneTitle = '' ][, array<string|int, mixed> $aAdditionalOptions = array() ][, string $sSectionTitle = '' ]) : void
Parameters
- $sFieldName : string
-
The name of the preset under which it can be retrieved later with getPresetValue.
- $sLabel : string|array<string|int, string>
-
The visual label of the preset in the preset editor. In case of an array the second element is the tooltip.
- $mType : mixed = 'caption'
-
The type like in a CSGuiEditor.
- $mDefault : mixed = ''
-
The default value to use if the preset is applied to a new record.
- $sPaneTitle : string = ''
-
The tab name under which the preset should show up, default is Template Options.
- $aAdditionalOptions : array<string|int, mixed> = array()
-
Further options like in a CSGuiEditor.
- $sSectionTitle : string = ''
-
The section name under which the preset should show up.
Tags
Return values
void —addPresetFieldsToEditor()
This method can will be used by CSGuiEditors to add your template specific preset fields to the editor
public
final addPresetFieldsToEditor([CSGuiEditor $editor = NULL ]) : mixed
Parameters
- $editor : CSGuiEditor = NULL
-
the CSGuiEditor or descendant
Tags
Return values
mixed —createDefaultFolders()
Creates the Default Folders for a Template
public
createDefaultFolders() : void
Tags
Return values
void —createMacro()
Creates a new Macro within the template
public
createMacro(mixed $sMacroType) : CSSmartMacro
Parameters
- $sMacroType : mixed
-
the macro plugin base name
Tags
Return values
CSSmartMacro —createView()
Creates a new CSSmartCSView that can be used in templating to create HTML separated from PHP
public
createView() : CSSmartCSView
Tags
Return values
CSSmartCSView —encode()
Encodes the HTML entities in a text
public
static encode(string $text) : string
If you want to add content to a Smart Page this is expected in a HTML markup. Always make sure, that the content passed by you is properly encoding HTML entities like <,>,&, etc. To convert your text into html markup you can use this method.
Parameters
- $text : string
-
unencoded text maybe containing html entities
Tags
Return values
string —html encoded text
finalize()
This method will be called by the renderer once the internal tcpdf object has been created and the html output provided through the addPages method was placed. It is the final hook to deal with the extended api of the tcpdf object, which has a very rich and powerful api.
public
finalize(TCPDF $tcpdf, Html2Pdf $html2pdf) : void
Parameters
- $tcpdf : TCPDF
- $html2pdf : Html2Pdf
Tags
Return values
void —getAlternativePluginFolder()
public
static getAlternativePluginFolder() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getAvailableFonts()
This method returns all font files which are used in the default css files of the template.
public
getAvailableFonts() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —array('css name' => 'path to font file')
getAvailableFormats()
Allows the Template Developer to narrow the available renders
public
getAvailableFormats(array<string|int, string> $allFormats) : mixed
Parameters
- $allFormats : array<string|int, string>
-
array with name and label of supported rendering formats
Tags
Return values
mixed —array with name and labels
getBaseName()
Returns the short name of the plugin without the SmartTemplate at the end
public
getBaseName() : string
Tags
Return values
string —the base name
getDefaultCSSFile()
Searches a CSS File which has the same name as the Template File Note: You can use the method @see getDefaultCSSFiles to collect the files of the parent templates as well
public
getDefaultCSSFile([mixed $createIfMissing = FALSE ]) : string
Parameters
- $createIfMissing : mixed = FALSE
Tags
Return values
string —the css file link
getDefaultCSSFiles()
Collects all CSS Files which have the same name as the Template File for the current class and all parents
public
getDefaultCSSFiles() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —the css file links
getDefaultFonts()
Collects all Font Files which are in the fonts folder of the Template File for the current class and all parents
public
getDefaultFonts() : array<string|int, string>
Tags
Return values
array<string|int, string> —the font file links
getDefaultFooter()
Overwrite this method to modify the way of building the footer If the parameter contains one element, this will be placed in the middle, if two they will be placed left and right and if three they will be placed left, center and right
public
getDefaultFooter(array<string|int, string> $footers) : string
Parameters
- $footers : array<string|int, string>
-
html content for the footer areas
Tags
Return values
string —getDefaultFormat()
The Default Page Format is used by the addDefaultPage Object and can be overwritten by templates
public
getDefaultFormat() : string
Tags
Return values
string —the default page format
getDefaultHeader()
Overwrite this method to modify the way of building the header If the parameter contains one element, this will be placed in the middle, if two they will be placed left and right and if three they will be placed left, center and right
public
getDefaultHeader(array<string|int, string> $headers) : string
Parameters
- $headers : array<string|int, string>
-
html content for the header areas
Tags
Return values
string —getDefaultMargins()
The Default Page Margins are used by the addDefaultPage Object and can be overwritten by templates
public
getDefaultMargins() : array<string|int, float>
Tags
Return values
array<string|int, float> —the default page margins as array with four float values for margin top, right, bottom and left
getDefaultOrientation()
The Default Page Orientation is used by the addDefaultPage Object and can be overwritten by templates
public
getDefaultOrientation() : string
Tags
Return values
string —the default page orientation as one of the two CSSmart::ORIENTATION constants
getDefaultPaddings()
The Default Page Paddings are used by the addDefaultPage Object and can be overwritten by templates
public
getDefaultPaddings() : array<string|int, float>
Tags
Return values
array<string|int, float> —the default page paddings as array with four float values for padding top, right, bottom and left
getDescription()
Get the description of the plugin
public
getDescription() : string
Tags
Return values
string —the description
getDocument()
Gets the internal CSSmartDocument reference
public
getDocument() : CSSmartDocument
Tags
Return values
CSSmartDocument —the internal CSSmartDocument
getHttpMethod()
Reads out the http method defined for this plugin
public
getHttpMethod() : string
Tags
Return values
string —the http method like GET, POST, DELETE or PUT
getImageUrl()
This method will return an url to the passed image depending on the format.
public
final getImageUrl(int|string $mFile[, int $iWidth = 1200 ][, int $iHeight = 1200 ]) : string
Parameters
- $mFile : int|string
-
Can be an mam file id, an relative or absolute path or an url
- $iWidth : int = 1200
-
The width of image in px
- $iHeight : int = 1200
-
The height of image in px
Tags
Return values
string —with an url to the passed image.
getItems()
Utility method that can be used by templates to get items If the $IDs contains one ID and this is folder, also the children are used
public
getItems(string $IDs[, string $class = 'Pdmarticle' ][, bool $includeFolders = TRUE ]) : array<string|int, CSItemApiItem>
Parameters
- $IDs : string
-
one ID or multiple comma separated IDs
- $class : string = 'Pdmarticle'
-
the class name of the record, e.g. Pdmarticle or Itemstructure or MamFile
- $includeFolders : bool = TRUE
-
if false then folder items are ignored
Tags
Return values
array<string|int, CSItemApiItem> —array with CSItemApiItems that matches the IDs
getLevel()
The getLevel method may be overwritten in the plugins and defines the order, the plugins are called, where the highest level is called first.
public
getLevel() : int
The method can also be set for all plugins within a module by overwriting the modules getLevel method.
Tags
Return values
int —the level of the plugin where it is called
getMetaData()
Returns the CSMetaData of the current plugin.
public
getMetaData() : CSMetaData
Tags
Return values
CSMetaData —getModule()
Returns the module, if the plugin is defined within a module.
public
getModule() : CSModule
This method can be used in the plugin api and the plugin wherever access to the defining module is required. If it is used in the Api, it should be noticed that this method may return null, if the plugin is directly defined in the projects or admin.local plugins directory.
Tags
Return values
CSModule —the module object, if the plugin defined in a module or null otherwise
getPlaceholder()
Ignore this method
public
getPlaceholder(mixed $item, mixed $attributeID[, null $languageID = NULL ]) : string
Parameters
- $item : mixed
- $attributeID : mixed
- $languageID : null = NULL
Tags
Return values
string —getPlugin()
Returns a CSPlugin for the given plugin type and plugin class name.
public
static getPlugin(string $pluginApiPath, string $className[, mixed $arguments = NULL ]) : CSPlugin|null
As standard behaviour the module subfolder is guessed from the forward URL parameter. If a plugin should point to something in a special module subfolder, this scope can be added by adding the module name in squared bracket at the end of the $pluginApiPath, e.g. 'core/api/plugins/CSRecordPlugin.php[pms]' to get all CSRecordPlugins defined for pms records.
Parameters
- $pluginApiPath : string
-
The relative path in filesystem for the requested plugin api (optional: ending with the module subfolder).
- $className : string
-
The target plugin class name, which should be loaded.
- $arguments : mixed = NULL
-
one or multiple arguments which should be passed to the isAvailable method.
Tags
Return values
CSPlugin|null —Returns the requested plugin for the given parameter.
getPluginChooser()
Returns an array all defined CSPlugins for the current plugin type
public
static getPluginChooser(string $pluginApiPath[, mixed $arguments = NULL ]) : array<string|int, mixed>
Parameters
- $pluginApiPath : string
-
the relative path in filesystem for the requested plugin api (optional: ending with the module subfolder).
- $arguments : mixed = NULL
-
one ore multiple arguments which should be passed to the isAvailable method.
Tags
Return values
array<string|int, mixed> —of CSPlugins in the form [CLASSNAME => LABEL] where the CLASSNAME may be used in the CSPlugin::getPlugin method
getPluginData()
public
getPluginData() : mixed
Tags
Return values
mixed —getPluginDefinitionFile()
Returns the path to the file, the plugin is defined.
public
getPluginDefinitionFile() : string
Tags
Return values
string —the path to the plugin
getPluginName()
public
getPluginName() : mixed
Tags
Return values
mixed —getPluginPath()
Get the plugin subdirectory
public
getPluginPath() : string
Tags
Return values
string —the sub path
getPlugins()
Returns all defined CSPlugins for the current plugin type It should be used to get all matching plugins for a given plugin api.
public
static getPlugins(string $pluginApiPath[, mixed $arguments = NULL ]) : array<string|int, CSPlugin>
As standard behaviour the module subfolder is guessed from the forward URL parameter. If a plugin should point to something in a special module subfolder, this scope can be added by adding the module name in squared bracket at the end of the $pluginApiPath, e.g. 'core/api/plugins/CSRecordPlugin.php[pms]' to get all CSRecordPlugins defined for pms records.
Parameters
- $pluginApiPath : string
-
the relative path in filesystem for the requested plugin api (optional: ending with the module subfolder).
- $arguments : mixed = NULL
-
one ore multiple arguments which should be passed to the isAvailable method.
Tags
Return values
array<string|int, CSPlugin> —array of CSPlugin objects matching the defined plugin criteria
getPluginsInModule()
Returns all CSPlugins for the current plugin type which are defined within the given module It should be used to get all matching plugins for a given plugin api.
public
static getPluginsInModule(string $moduleName, string $pluginApiPath[, mixed $sFileNamePattern = '' ][, mixed $arguments = NULL ]) : array<string|int, mixed>
Parameters
- $moduleName : string
-
the module which should be searched for plugins
- $pluginApiPath : string
-
the relative path in filesystem for the requested plugin api.
- $sFileNamePattern : mixed = ''
- $arguments : mixed = NULL
-
one ore multiple arguments which should be passed to the isAvailable method.
Tags
Return values
array<string|int, mixed> —of CSPlugin objects matching the defined plugin criterias
getPreset()
Returns the current preset to be used
public
final getPreset() : CSSmartPreset
Tags
Return values
CSSmartPreset —the preset
getPresetValue()
Provides a preset value for a given parameter
public
final getPresetValue(string $name[, string $default = NULL ]) : mixed
Parameters
- $name : string
-
the name of the preset value
- $default : string = NULL
-
the value to use if the parameter evaluates to FALSE
Tags
Return values
mixed —the value
getPreviewUrl()
Tries to find a URL for this template by choosing the next best html or xml preset export url
public
getPreviewUrl([string $sBase = 'external' ]) : string
Parameters
- $sBase : string = 'external'
-
the base for the URL like 'external' or 'relative'
Tags
Return values
string —the URL if found
getView()
Gets the current CSSmartView If no CSSmartView has been created, it is created on the fly
public
getView() : CSSmartView
Tags
Return values
CSSmartView —getViewScriptFolders()
Collects all script folders under the Template File for the current class and all parents
public
getViewScriptFolders([bool $includeInheritedScripts = TRUE ]) : array<string|int, string>
Parameters
- $includeInheritedScripts : bool = TRUE
-
if to include also the inherited scripts
Tags
Return values
array<string|int, string> —the script folder links
getViewScripts()
Returns all View Scripts for the Template
public
getViewScripts([bool $includeInheritedScripts = TRUE ]) : array<string|int, string>
Parameters
- $includeInheritedScripts : bool = TRUE
-
if to include also the inherited scripts
Tags
Return values
array<string|int, string> —array with the scripts files relative to the admin
isAvailable()
This method is called to check, whether the plugin is available.
public
isAvailable() : bool
If further arguments are added to the CSPlugin::getPlugins call, they are added as arguments to this method.
For simpler usage of the plugin concept: This method should be overwritten with the correct signature for a plugin call, if arguments are passed.
Tags
Return values
bool —whether the plugin is available for the given arguments
isAvailableForContext()
Let the plugin decide, if it should be available for a given context the context may be any kind of object that a consumer of templates might pass with the expectation, that only matching templates should be returned. If no context is given, all templates can be returned
public
isAvailableForContext(mixed $context) : bool
Parameters
- $context : mixed
-
the context object
Tags
Return values
bool —TRUE if the plugin should be available for the context
isVirtualTemplate()
Templates can have be declared virtual to serve only for inheritance purposes The default way to declare a template as virtual is to use the prefix "master" or use an initial underscore in the name
public
isVirtualTemplate() : bool
Tags
Return values
bool —resetLoadedPlugins()
reset the internal plugins cache for loaded plugins
public
static resetLoadedPlugins() : mixed
Tags
Return values
mixed —setDocument()
Sets the internal document reference This method is called by the CSSmartTemplate before calling the addPages method so that submethods can at any time access the current document object without passing the document
public
setDocument(mixed $doc) : void
Parameters
- $doc : mixed
-
CSSmartDocument the document object
Tags
Return values
void —setHttpMethod()
Allows to overwrite the standard http method handling which is through GET
public
setHttpMethod([string $method = 'GET' ]) : mixed
Parameters
- $method : string = 'GET'
-
the method like GET, POST, DELETE, PUT
Tags
Return values
mixed —setPreset()
Sets the preset
public
setPreset(CSSmartPreset $preset) : void
Parameters
- $preset : CSSmartPreset
Tags
Return values
void —shouldBeSelectableInUI()
Defines if the template should be selectable in the UI interface.
public
shouldBeSelectableInUI() : bool
Tags
Return values
bool —if the template should be selectable in the UI interface.
supportsFormat()
Method that tells if a given format or at least one out an array of formats is available
public
final supportsFormat(mixed $format) : bool
Parameters
- $format : mixed
-
if a string then exactly this format must be supported, if an array then one or more out of the array
Tags
Return values
bool —TRUE if the format is available
