Documentation

brand_guidelines_functions.php

Table of Contents

Functions

acl_can_view_brand_guidelines()  : bool
Helper function for access control purposes to check if user can view the Brand Guidelines
acl_can_edit_brand_guidelines()  : bool
Helper function for access control purposes to check if user can edit the Brand Guidelines
is_section()  : bool
Check if a page item is a section
filter_only_pages()  : bool
Check if a page item is just a page (i.e. NOT a section)
cast_reorder_direction_to_int()  : -1|1
Helper function to cast a re-order direction to an integer.
compute_item_order()  : T
Compute moving (for re-ordering purposes) an item based on the requested direction (up/down). Example:
reorder_input_validator()  : bool
Input validation for the re-order capability
richtext_input_parser()  : string
Rich text editor input parser (removes invalid HTML tags/attributes)
colour_hex_input_validator()  : bool
Input validation for HEX colour syntax, including short form notations (e.g. 03A === 0033AA)
colour_rgb_input_validator()  : bool
Input validation for RGB colour syntax (e.g. 0,0,0)
colour_cmyk_input_validator()  : bool
Input validation for CMYK colour syntax (e.g. 0,0,0,100)
create_page_content()  : bool
Create a new page content item (use case).
save_page_content()  : mixed
Save a page content item change (use case).
reorder_page_content()  : bool
Re-order page content. Use cases: - move up/down items (no group logic); - move up/down items over an entire group; - move up/down a group over another group; - move up/down an entire group of items (including over another group); - move left/right within the group boundaries; - move up/down outside group boundaries to take an item out of a group;
convert_to_db_content()  : array<string|int, mixed>
Data transfer utility to help translate custom fields' data structures to a minimum required data structure that we can store in the database.
convert_from_db_content()  : array<string|int, mixed>
Data transfer utility to help reconstruct custom fields' data structure
group_content_items()  : array<string|int, mixed>
Helper function to group similar sequential page (colour & resource) content items for rendering purposes. A group is made of at least one item (to allow users to add to it). Full width resources do not get grouped.
is_group_member()  : callable
Helper filter function to determine if a page content item is part of group
reorder_items_in_memory()  : T
Re-order table records in memory in ascending order based on their order_by
decode_page_content_item()  : array<string|int, mixed>
Page content item (JSON) decoder
is_brand_guidelines_callback()  : bool
Helper validator to check if a callback URL is for Brand Guidelines

Functions

acl_can_view_brand_guidelines()

Helper function for access control purposes to check if user can view the Brand Guidelines

acl_can_view_brand_guidelines() : bool
Return values
bool

acl_can_edit_brand_guidelines()

Helper function for access control purposes to check if user can edit the Brand Guidelines

acl_can_edit_brand_guidelines() : bool
Return values
bool

is_section()

Check if a page item is a section

is_section(array{parent: int|numeric-string} $I) : bool
Parameters
$I : array{parent: int|numeric-string}

Generic page data structure

Return values
bool

filter_only_pages()

Check if a page item is just a page (i.e. NOT a section)

filter_only_pages(array{parent: int|numeric-string} $I) : bool
Parameters
$I : array{parent: int|numeric-string}

Generic page data structure

Return values
bool

cast_reorder_direction_to_int()

Helper function to cast a re-order direction to an integer.

cast_reorder_direction_to_int(string $direction) : -1|1
Parameters
$direction : string
Return values
-1|1

compute_item_order()

Compute moving (for re-ordering purposes) an item based on the requested direction (up/down). Example:

compute_item_order(T $item, string $direction[, int $jump_over = 1 ]) : T
$changed_list = array_replace(
    $all_pages_index,
    [$ref => compute_item_order($all_pages_index[$ref], $reorder)]
);
Parameters
$item : T

Generic item record with at least the 'order_by' key

$direction : string

The direction of the re-order - up/down

$jump_over : int = 1

Specify how many elements to jump over

Tags
phpstan-template

T of array

Return values
T

reorder_input_validator()

Input validation for the re-order capability

reorder_input_validator(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

richtext_input_parser()

Rich text editor input parser (removes invalid HTML tags/attributes)

richtext_input_parser(string $value) : string
Parameters
$value : string
Return values
string

colour_hex_input_validator()

Input validation for HEX colour syntax, including short form notations (e.g. 03A === 0033AA)

colour_hex_input_validator(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

colour_rgb_input_validator()

Input validation for RGB colour syntax (e.g. 0,0,0)

colour_rgb_input_validator(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

colour_cmyk_input_validator()

Input validation for CMYK colour syntax (e.g. 0,0,0,100)

colour_cmyk_input_validator(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

create_page_content()

Create a new page content item (use case).

create_page_content(int $page, BRAND_GUIDELINES_CONTENT_TYPES, fields: array, position_after: int} $item) : bool
Parameters
$page : int

Page ID

$item : BRAND_GUIDELINES_CONTENT_TYPES, fields: array, position_after: int}

An item data structure

Return values
bool

save_page_content()

Save a page content item change (use case).

save_page_content(int $ref, array<string|int, mixed> $item) : mixed
Parameters
$ref : int

Page content item ID

$item : array<string|int, mixed>

reorder_page_content()

Re-order page content. Use cases: - move up/down items (no group logic); - move up/down items over an entire group; - move up/down a group over another group; - move up/down an entire group of items (including over another group); - move left/right within the group boundaries; - move up/down outside group boundaries to take an item out of a group;

reorder_page_content(string $reorder, array<string|int, mixed> $init_page_content, array<string|int, mixed> $refs) : bool
Parameters
$reorder : string

The move direction (up/down only). Note that moving left/right <=> up/down.

$init_page_content : array<string|int, mixed>

The page content get_page_contents() with the keys being each items' ref.

$refs : array<string|int, mixed>

List of IDs to move. Multiple IDs means we move an entire group.

Return values
bool

convert_to_db_content()

Data transfer utility to help translate custom fields' data structures to a minimum required data structure that we can store in the database.

convert_to_db_content(array<string|int, mixed> $input) : array<string|int, mixed>
Parameters
$input : array<string|int, mixed>

Submitted custom fields' data structure process_custom_fields_submission()

Return values
array<string|int, mixed>

convert_from_db_content()

Data transfer utility to help reconstruct custom fields' data structure

convert_from_db_content(string $json, array<string|int, mixed> $def) : array<string|int, mixed>
Parameters
$json : string

Database record value (JSON type)

$def : array<string|int, mixed>

Custom fields' data structure as input to process_custom_fields_submission()

Return values
array<string|int, mixed>

Same custom fields' data structure with, where applicable, an extra "value" key representing the current field value

group_content_items()

Helper function to group similar sequential page (colour & resource) content items for rendering purposes. A group is made of at least one item (to allow users to add to it). Full width resources do not get grouped.

group_content_items(array<string|int, mixed> $items) : array<string|int, mixed>
Parameters
$items : array<string|int, mixed>

Page content item records

Return values
array<string|int, mixed>

Returns the item as is or makes it a group member otherwise

is_group_member()

Helper filter function to determine if a page content item is part of group

is_group_member(int $ref, array<string|int, mixed> $table) : callable
Parameters
$ref : int

Page content item ID

$table : array<string|int, mixed>

Lookup table (e.g.: array_column(get_page_contents($page), null, 'ref'))

Return values
callable

reorder_items_in_memory()

Re-order table records in memory in ascending order based on their order_by

reorder_items_in_memory(T $table) : T
Parameters
$table : T
Tags
template

T of array<postive-int, array{ref: postive-int, order_by: int}>

Return values
T

decode_page_content_item()

Page content item (JSON) decoder

decode_page_content_item(array<string|int, mixed> $item) : array<string|int, mixed>
Parameters
$item : array<string|int, mixed>

A (database record) page content item data structure BRAND_GUIDELINES_DB_COLS_CONTENT

Return values
array<string|int, mixed>

is_brand_guidelines_callback()

Helper validator to check if a callback URL is for Brand Guidelines

is_brand_guidelines_callback(mixed $url) : bool
Parameters
$url : mixed
Return values
bool
On this page

Search results