Helper functions

GreenLight has various helper functions that either extend possibilities of general Laravel helpers or provide functionality that several previous projects needed and it was reasonable to keep them in the package as well.

These helper functions can be found in vendor/greenroom/greenlight/src/Helper.php and are loaded in the service provider of the package (vendor/greenroom/greenlight/src/GreenLightServiceProvider.php). Below you can find the list and short documentation of these helpers.


getModuleText

Returns a GeneralText instance by alias, replaces data using replaceText() based on the passed parameters.

Parameters

Name Type Description
alias string Alias property value of the GeneralText model to be loaded
params array Associative array that holds data to be replaced in the text property of the GeneralText model fetched. Any occurrence of the array keys in square brackets will be replaced with the corresponding array value (using the replaceText helper).

Return types

Type Description
string Text value of the GeneralText model with the given alias

replaceText

Replaces data based on passed parameters.

Parameters

Name Type Description
text string Text to be altered
params array Associative array that holds data to be replaced in the given text. Any occurrence of the array keys in square brackets will be replaced with the corresponding array value.

Return types

Type Description
string Text after the replace process

addTruncateMarkup

Adds a truncated markup element after the desired character count in a string. Remaining characters are going to be wrapped into a <i class="truncated"> markup, that can be handled by CSS.

Parameters

Name Type Description
text string Text to be altered
length int Character count to truncate after

Return types

Type Description
string Text after the replace process

getDayName

Returns the name of the day of a Carbon date.

Parameters

Name Type Description
date Carbon\Carbon Carbon date

Return types

Type Description
string String result

getMonthName

Returns the name of the month of a Carbon date.

Parameters

Name Type Description
date Carbon\Carbon Carbon date

Return types

Type Description
string String result

getShortMonthName

Returns the short name of the month of a Carbon date.

Parameters

Name Type Description
date Carbon\Carbon Carbon date

Return types

Type Description
string String result

getFormattedDate

Returns the formatted string of a Carbon date based on actual locale. Currently supports 'en' and 'hu' locales, also has a fallback (same format as the 'en' locale).

Parameters

Name Type Description
date Carbon\Carbon Carbon date

Return types

Type Description
string String result

getImage

Returns an image path based on source and prefix details. If $prefix is set but no prefixed image was found, this checks the non-prefixed image url, in case that can not be found either, a placeholder image path is returned.

Parameters

Name Type Description
image_src string | null Image path (returns placeholder image if null)
prefix string | null Size variant prefix (configured in config/image.php)

Return types

Type Description
string Image path string

youTubeURLToEmbed

Converts a YouTube URL to its embed version. If the given URL is already an embed one, it returns the same value. If there is no 'v' parameter set correctly, returns false.

Parameters

Name Type Description
url string YouTube video url

Return types

Type Description
string | bool Converted URL string or false when an incorrect URL was parsed

matchUrlProtocolToHost

Converts the given url to match the protocol used by the current request.

Parameters

Name Type Description
url string URL to convert

Return types

Type Description
string Converted URL string

nbspLastWord

Replaces last space character of a given string to   if the last word found is shorter than the specified length

Parameters

Name Type Description
string string String to be altered
length int Length at what the last word is considered to be short enough to alter the string

Return types

Type Description
string Altered string

relativeAction

Similar to the original action() helper function, returns a relative path based on the action name.

Parameters

Name Type Description
name string Action name
parameters array URL parameters to be passed to the Laravel action() function

Return types

Type Description
string Relative path string

htmlToMetaData

Converts HTML data to a meta tag friendly version. Removes tags, &nbsp; characters and applies html_entity_decode.

Parameters

Name Type Description
text string HTML content

Return types

Type Description
string Meta tag friendly content