\midcom_helper__styleloader

This class is responsible for all style management. It is instantiated by the MidCOM framework and accessible through the midcom::get()->style object.

The method show($style) returns the style element $style for the current component:

It checks whether a style path is defined for the current component.

  • If there is a user defined style path, the element named $style in this path is returned,
  • otherwise the element "$style" is taken from the default style of the current component (/path/to/component/style/$path).

(The default fallback is always the default style, e.g. if $style is not in the user defined style path)

To enable cross-style referencing and provide the opportunity to access any style element, "show" can be called with a full qualified style path (like "/mystyle/element1", while the current page's style may be set to "/yourstyle").

Note: To make sure sub-styles and elements included in styles are handled correctly, use:

<?php midcom_show_style ("elementname"); ?>

Style Inheritance

The basic path the styleloader follows to find a style element is:

  1. Topic style -> if the current topic has a style set
  2. Inherited topic style -> if the topic inherits a style from another topic.
  3. Site-wide per-component default style -> if defined in MidCOM configuration key styleengine_default_styles
  4. Theme style -> the style of the MidCOM component.
  5. The file style. This is usually the elements found in the component's style directory.

Regarding nr. 4: It is possible to add extra file styles if so is needed for example by a portal component. This is done either using the append/prepend component_style functions or by setting it to another directory by calling (append|prepend)_styledir directly.

NB: You cannot change this in another style element or in a _show() function in a component.

Summary

Methods
Properties
Constants
get_style_path_from_id()
get_style_id_from_path()
show()
load()
parse()
render()
show_midcom()
append_styledir()
prepend_styledir()
append_component_styledir()
prepend_component_styledir()
append_substyle()
prepend_substyle()
enter_context()
leave_context()
$data
No constants found
No protected methods found
No protected properties found
N/A
_get_element_in_styletree()
_find_element_in_scope()
_get_element_from_snippet()
_get_component_style()
_get_component_snippetdir()
_merge_styledirs()
$_scope
$_topic
$_snippetdir
$_context
$_styles
$_snippets
$_styledirs_append
$_styledirs_prepend
$_styledirs
N/A

Properties

$data

$data : array

Data to pass to the style

Type

array

$_scope

$_scope : array

Current style scope

Type

array

$_snippetdir

$_snippetdir : string

Default style path

Type

string

$_context

$_context : array

Context stack

Type

array

$_styles

$_styles : array

Style element cache

Type

array

$_snippets

$_snippets : array

Default style element cache

Type

array

$_styledirs_append

$_styledirs_append : array

List of styledirs to handle after componentstyle

Type

array

$_styledirs_prepend

$_styledirs_prepend : array

List of styledirs to handle before componentstyle

Type

array

$_styledirs

$_styledirs : 

The stack of directories to check for styles.

Type

Methods

get_style_path_from_id()

get_style_path_from_id(integer  $id) : string

Returns the path of the style described by $id.

Parameters

integer $id

Style id to look up path for

Returns

string —

Style path

get_style_id_from_path()

get_style_id_from_path(string  $path, integer  $rootstyle) : integer

Returns the id of the style described by $path.

Note: $path already includes the element name, so $path looks like "/rootstyle/style/style/element".

Parameters

string $path

The path to retrieve

integer $rootstyle

???

Returns

integer —

ID of the matching style or false

show()

show(string  $path) : boolean

Looks for a style element matching $path (either in a user defined style or the default style snippetdir) and displays/evaluates it.

Parameters

string $path

The style element to show.

Returns

boolean —

True on success, false otherwise.

load()

load(string  $path) : false|string

Load style element content

Parameters

string $path

The element name

Returns

false|string

parse()

parse(string  $style, string  $path) : string

This is a bit of a hack to allow &(); tags

Parameters

string $style

The style element content

string $path

The element name

Returns

string —

The parsed element

render()

render(string  $preparsed, string  $path, array  $data = array()) 

Renders the style element with current request data

Parameters

string $preparsed

The element's content as executable code

string $path

the element's name

array $data

Request date, if you don't want to use the global data

Throws

\midcom_error

show_midcom()

show_midcom(string  $path) : boolean

Looks for a midcom core style element matching $path and displays/evaluates it.

This offers a bit reduced functionality and will only look in the DB root style, the theme directory and midcom's style directory, because it has to work even when midcom is not yet fully initialized

Parameters

string $path

The style element to show.

Returns

boolean —

True on success, false otherwise.

append_styledir()

append_styledir(string  $dirname) 

Adds an extra style directory to check for style elements at the end of the styledir queue.

Parameters

string $dirname

path of style directory within midcom.

Throws

\midcom

exception if directory does not exist.

prepend_styledir()

prepend_styledir(string  $dirname) : boolean

Function prepend styledir

Parameters

string $dirname

path of styledirectory within midcom.

Throws

\midcom_error

if directory does not exist.

Returns

boolean —

true if directory appended

append_component_styledir()

append_component_styledir(string  $component) 

Append the styledir of a component to the queue of styledirs.

Parameters

string $component

Component name

Throws

\midcom

exception if directory does not exist.

prepend_component_styledir()

prepend_component_styledir(string  $component) 

Prepend the styledir of a component

Parameters

string $component

component name

append_substyle()

append_substyle(string  $newsub) 

Appends a substyle after the currently selected component style.

Enables a depth of more than one style during substyle selection.

Parameters

string $newsub

The substyle to append.

prepend_substyle()

prepend_substyle(string  $newsub) 

Prepends a substyle before the currently selected component style.

Enables a depth of more than one style during substyle selection.

Parameters

string $newsub

The substyle to prepend.

enter_context()

enter_context(integer  $context) 

Switches the context (see dynamic load). Private variables $_context, $_topic and $_snippetdir are adjusted.

Parameters

integer $context

The context to enter

leave_context()

leave_context() 

Switches the context (see dynamic load). Private variables $_context, $_topic and $_snippetdir are adjusted.

_get_element_in_styletree()

_get_element_in_styletree(integer  $id, string  $name) : string

Returns a style element that matches $name and is in style $id.

It also returns an element if it is not in the given style, but in one of its parent styles.

Parameters

integer $id

The style id to search in.

string $name

The element to locate.

Returns

string —

Value of the found element, or false on failure.

_find_element_in_scope()

_find_element_in_scope(  $_element) 

Try to find element in current / given scope

Parameters

$_element

_get_element_from_snippet()

_get_element_from_snippet(  $_element) 

Try to get element from default style snippet

Parameters

$_element

_get_component_style()

_get_component_style(\midcom_db_topic  $topic) : integer

Gets the component style.

Parameters

\midcom_db_topic $topic

Current topic

Returns

integer —

Database ID if the style to use in current view or false

_get_component_snippetdir()

_get_component_snippetdir() : mixed

Gets the component styledir associated with the topic's component.

Returns

mixed —

the path to the component's style directory.

_merge_styledirs()

_merge_styledirs(string  $component_style) 

Merge the prepend and append styles with the componentstyle. This happens when the enter_context function is called.

You cannot change the style call stack after that (unless you call enter_context again of course).

Parameters

string $component_style