\Taxonomy\UtilityTaxonomyToolbox

Taxonomy utility class.

Utility methods used by TaxonomyField Handler.

Summary

Methods
Properties
Constants
getInstance()
formatter()
termsForBlock()
shortcodes()
stripShortcodes()
escapeShortcodes()
enableShortcodes()
disableShortcodes()
No public properties found
No constants found
No protected methods found
$_instance
N/A
No private methods found
No private properties found
N/A

Properties

Methods

getInstance()

getInstance() : \Taxonomy\Utility\TaxonomyToolbox

Returns an instance of this class.

Useful when we need to use some of the trait methods.

Returns

\Taxonomy\Utility\TaxonomyToolbox

formatter()

formatter(\Field\Model\Entity\Field $field, \Cake\View\View $view) : string

Formats the given field.

Parameters

\Field\Model\Entity\Field $field

The field being rendered

\Cake\View\View $view

Instance of View, used to access HtmlHelper

Returns

string

termsForBlock()

termsForBlock( $terms, \Cake\Datasource\EntityInterface $block)

Prepares the given threaded list of terms.

Parameters

$terms
\Cake\Datasource\EntityInterface $block

The block

shortcodes()

shortcodes(string $content, object|null $context) : string

Look for shortcodes in the given text.

If any is found an event is triggered asking for its Event Lister method. For example:

{nice_button color=green}Click Me!{/nice_button}

You must define an Event Lister nice_button:

class YourListener implements EventListenerInterface {
    public function implementedEvents() {
        return ['nice_button' => 'shortcodeNiceButton'];
    }

    public function shortcodeNiceButton(Event $event, $atts, $content, $tag) {
        // return some text
    }
}

As you can see shortcodes methods will receive three arguments:

$atts

Array which may include any arbitrary attributes that are specified by the user. Attribute names are always converted to lowercase before they are passed into the handler function. Values remains untouched.

{some_shortcode Foo="bAr" /}

Produces:

$atts = ['foo' => 'bAr'];

TIP: Don't use camelCase or UPPER-CASE for your $atts attribute names

$content

Holds the enclosed content (if the shortcode is used in its enclosing form). For self-closing shortcodes $content will be null:

{self_close some=thing /}

$tag

The shortcode name. i.e.: some_shortcode

Parameters

string $content

The the text to parse

object|null $context

Context to use when triggering events

Returns

string —

Orginal string modified with no shortcodes [..]

stripShortcodes()

stripShortcodes(string $content) : string

Removes all shortcodes from the given content.

Parameters

string $content

Text from which to remove shortcodes

Returns

string —

Content without shortcodes

escapeShortcodes()

escapeShortcodes(string $content) : string

Escapes all shortcodes from the given content.

Parameters

string $content

Text from which to escape shortcodes

Returns

string —

Content with all shortcodes escaped

enableShortcodes()

enableShortcodes() : void

Enables shortcode parser.

disableShortcodes()

disableShortcodes() : void

Globally disables shortcode parser.

The shortcodes() method will not work when disabled.