public function jQueryUiFilter::parseOptions in jQuery UI filter 8.2
Parse options from an attributes string.
Parameters
string $text: A string of options.
Return value
array An associative array of parsed name/value pairs.
1 call to jQueryUiFilter::parseOptions()
- jQueryUiFilter::process in src/
Plugin/ Filter/ jQueryUiFilter.php - Performs the filter processing.
File
- src/
Plugin/ Filter/ jQueryUiFilter.php, line 147 - Contains \Drupal\jquery_ui_filter\Plugin\Filter\jQueryUiFilter.
Class
- jQueryUiFilter
- Provides a filter to generate jQuery UI accordion and tabs widgets.
Namespace
Drupal\jquery_ui_filter\Plugin\FilterCode
public function parseOptions($text) {
// Decode special characters.
$text = html_entity_decode($text);
// Convert decode to expected ASCII code 32 character.
// See: http://stackoverflow.com/questions/6275380/does-html-entity-decode-replaces-nbsp-also-if-not-how-to-replace-it
$text = str_replace("", ' ', $text);
// Convert camel case to hyphen delimited because HTML5 lower cases all
// data-* attributes.
// See: Drupal.jQueryUiFilter.getOptions.
$text = strtolower(preg_replace('/([a-z])([A-Z])/', '\\1-\\2', $text));
// Create a DomElement so that we can parse its attributes as options.
$html = Html::load('<div ' . $text . ' />');
$dom_node = $html
->getElementsByTagName('div')
->item(0);
$options = [];
foreach ($dom_node->attributes as $attribute_name => $attribute_node) {
// Convert empty attributes (ie nothing inside the quotes) to 'true' string.
$options[$attribute_name] = $attribute_node->nodeValue ?: 'true';
}
return $options;
}