public function AceFilter::tagAttributes in Ace Code Editor 8
Get all attributes of an <ace> tag in key/value pairs.
1 call to AceFilter::tagAttributes()
- AceFilter::process in src/
Plugin/ Filter/ AceFilter.php - Processing the filters and return the processed result.
File
- src/
Plugin/ Filter/ AceFilter.php, line 174
Class
- AceFilter
- Filters implementation for Ace Editor.
Namespace
Drupal\ace_editor\Plugin\FilterCode
public function tagAttributes($element_name, $xml) {
// Grab the string of attributes inside the editor tag.
$found = preg_match('#<' . $element_name . '\\s+([^>]+(?:"|\'))\\s?/?>#', $xml, $matches);
if ($found == 1) {
$attribute_array = [];
$attribute_string = $matches[1];
// Match attribute-name attribute-value pairs.
$found = preg_match_all('#([^\\s=]+)\\s*=\\s*(\'[^<\']*\'|"[^<"]*")#', $attribute_string, $matches, PREG_SET_ORDER);
if ($found != 0) {
// Create an associative array that matches attribute names
// with their values.
foreach ($matches as $attribute) {
$value = substr($attribute[2], 1, -1);
if ($value == "1" || $value == "0" || $value == "TRUE" || $value == "FALSE") {
$value = intval($value);
}
$attribute_array[str_replace('-', '_', $attribute[1])] = $value;
}
return $attribute_array;
}
}
// Attributes either weren't found, or couldn't be extracted
// by the regular expression.
return FALSE;
}