Simplify code transforming images from posts
[MAILPOET-1684]
This commit is contained in:
@ -41,19 +41,12 @@ class StructureTransformer {
|
|||||||
private function transformTagsToBlocks($root, $image_full_width) {
|
private function transformTagsToBlocks($root, $image_full_width) {
|
||||||
return array_map(function($item) use ($image_full_width) {
|
return array_map(function($item) use ($image_full_width) {
|
||||||
if($item->tag === 'img' || $item->tag === 'a' && $item->query('img')) {
|
if($item->tag === 'img' || $item->tag === 'a' && $item->query('img')) {
|
||||||
if($item->tag === 'a') {
|
$image = $item->tag === 'img' ? $item : $item->children[0];
|
||||||
$link = $item->getAttribute('href');
|
|
||||||
$image = $item->children[0];
|
|
||||||
} else {
|
|
||||||
$link = '';
|
|
||||||
$image = $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
$width = $image->getAttribute('width');
|
$width = $image->getAttribute('width');
|
||||||
$height = $image->getAttribute('height');
|
$height = $image->getAttribute('height');
|
||||||
return array(
|
return array(
|
||||||
'type' => 'image',
|
'type' => 'image',
|
||||||
'link' => $link,
|
'link' => $item->getAttribute('href') ?: '',
|
||||||
'src' => $image->getAttribute('src'),
|
'src' => $image->getAttribute('src'),
|
||||||
'alt' => $image->getAttribute('alt'),
|
'alt' => $image->getAttribute('alt'),
|
||||||
'fullWidth' => $image_full_width,
|
'fullWidth' => $image_full_width,
|
||||||
|
Reference in New Issue
Block a user