function _entity_embed_filter_align in Entity Embed 7
Same name and namespace in other branches
- 7.2 entity_embed.module \_entity_embed_filter_align()
Implements callback_filter_process().
Aligns embedded entities.
2 string references to '_entity_embed_filter_align'
- AlignFilterTest::testAlignFilter in ./
entity_embed.test - Tests the embed_button administration functionality.
- entity_embed_filter_info in ./
entity_embed.module - Implements hook_filter_info().
File
- ./
entity_embed.module, line 697 - Provides a CKEditor plugin and text filter for embedding and rendering entities.
Code
function _entity_embed_filter_align($text) {
$result = $text;
if (stristr($text, 'data-align') !== FALSE) {
$dom = entity_embed_dom_load_html($text);
$xpath = new \DOMXPath($dom);
foreach ($xpath
->query('//*[@data-align]') as $node) {
// Read the data-align attribute's value, then delete it.
$align = $node
->getAttribute('data-align');
$node
->removeAttribute('data-align');
// If one of the allowed alignments, add the corresponding class.
if (in_array($align, array(
'left',
'center',
'right',
))) {
$classes = $node
->getAttribute('class');
$classes = strlen($classes) > 0 ? explode(' ', $classes) : array();
$classes[] = 'align-' . $align;
$node
->setAttribute('class', implode(' ', $classes));
}
}
$result = entity_embed_serialize($dom);
}
return $result;
}