public function RandomShortcode::process in Shortcode 2.0.x
Same name and namespace in other branches
- 8 shortcode_basic_tags/src/Plugin/Shortcode/RandomShortcode.php \Drupal\shortcode_basic_tags\Plugin\Shortcode\RandomShortcode::process()
Performs the shortcode processing.
Parameters
array $attributes: Array of attributes.
string $text: The text string to be processed.
string $langcode: The language code of the text to be filtered. Defaults to LANGCODE_NOT_SPECIFIED.
Return value
string The processed text.
Overrides ShortcodeInterface::process
File
- shortcode_basic_tags/
src/ Plugin/ Shortcode/ RandomShortcode.php, line 22
Class
- RandomShortcode
- Insert div or span around the text with some css classes.
Namespace
Drupal\shortcode_basic_tags\Plugin\ShortcodeCode
public function process(array $attributes, $text, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
// Merge with default attributes.
$attributes = $this
->getAttributes([
'length' => 8,
], $attributes);
$length = intval($attributes['length']);
$length = max($length, 8);
$length = min($length, 99);
$text = '';
for ($i = 0; $i < $length; ++$i) {
$text .= chr(rand(32, 126));
}
return $text;
}