Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EWPP-1863: Add list with illustrations pattern. #1006

Merged
merged 7 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
313 changes: 102 additions & 211 deletions modules/oe_theme_helper/src/TwigExtension/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,210 +275,19 @@ public function toEclAttributes($attributes): array {
* Icon array for ECL components containing icon name, path and rotation.
*/
public function toEclIcon(array $context, $icon, string $size = ''): array {
$path = $context['ecl_icon_path'];
$social_path = $context['ecl_icon_social_media_path'];

// ECL supported icons naming and rotation.
$icons = [
'facebook' => [
'name' => 'facebook',
'social' => TRUE,
],
'instagram' => [
'name' => 'instagram',
'social' => TRUE,
],
'linkedin' => [
'name' => 'linkedin',
'social' => TRUE,
],
'pinterest' => [
'name' => 'pinterest',
'social' => TRUE,
],
'rss' => [
'name' => 'rss',
],
'skype' => [
'name' => 'skype',
'social' => TRUE,
],
'twitter' => [
'name' => 'twitter',
'social' => TRUE,
],
'youtube' => [
'name' => 'youtube',
'social' => TRUE,
],
'audio' => [
'name' => 'audio',
],
'book' => [
'name' => 'book',
],
'brochure' => [
'name' => 'brochure',
],
'budget' => [
'name' => 'budget',
],
'calendar' => [
'name' => 'calendar',
],
'copy' => [
'name' => 'copy',
],
'data' => [
'name' => 'data',
],
'digital' => [
'name' => 'digital',
],
'edit' => [
'name' => 'edit',
],
'energy' => [
'name' => 'energy',
],
'euro' => [
'name' => 'euro',
],
'faq' => [
'name' => 'faq',
],
'feedback' => [
'name' => 'feedback',
],
'file' => [
'name' => 'file',
],
'gear' => [
'name' => 'gear',
],
'generic-lang' => [
'name' => 'generic-lang',
],
'global' => [
'name' => 'global',
],
$path = $this->getIconPath($context, $icon);

// Icons that require transforming.
$transformed_icons = [
'googleplus' => [
'name' => 'digital',
],
'growth' => [
'name' => 'growth',
],
'hamburger' => [
'name' => 'hamburger',
],
'image' => [
'name' => 'image',
],
'infographic' => [
'name' => 'infographic',
],
'language' => [
'name' => 'language',
],
'livestreaming' => [
'name' => 'livestreaming',
],
'location' => [
'name' => 'location',
],
'log-in' => [
'name' => 'log-in',
],
'logged-in' => [
'name' => 'logged-in',
],
'multiple-files' => [
'name' => 'multiple-files',
],
'organigram' => [
'name' => 'organigram',
],
'package' => [
'name' => 'package',
],
'presentation' => [
'name' => 'presentation',
],
'print' => [
'name' => 'print',
],
'regulation' => [
'name' => 'regulation',
],
'search' => [
'name' => 'search',
],
'share' => [
'name' => 'share',
],
'slides' => [
'name' => 'presentation',
],
'spinner' => [
'name' => 'spinner',
],
'spreadsheet' => [
'name' => 'spreadsheet',
],
'video' => [
'name' => 'video',
],
'camera' => [
'name' => 'video',
],
'error' => [
'name' => 'error',
],
'information' => [
'name' => 'information',
],
'info' => [
'name' => 'information',
],
'success' => [
'name' => 'success',
],
'warning' => [
'name' => 'warning',
],
'check' => [
'name' => 'check',
],
'check-filled' => [
'name' => 'check-filled',
],
'close' => [
'name' => 'close',
],
'close-filled' => [
'name' => 'close-filled',
],
'corner-arrow' => [
'name' => 'corner-arrow',
],
'download' => [
'name' => 'download',
],
'external' => [
'name' => 'external',
],
'fullscreen' => [
'name' => 'fullscreen',
],
'minus' => [
'name' => 'minus',
],
'plus' => [
'name' => 'plus',
],
'solid-arrow' => [
'name' => 'solid-arrow',
],
'close-dark' => [
'name' => 'close-filled',
],
Expand Down Expand Up @@ -516,30 +325,112 @@ public function toEclIcon(array $context, $icon, string $size = ''): array {
],
];

if (array_key_exists($icon, $icons)) {
$icons[$icon]['path'] = $path;
if (isset($icons[$icon]['social']) && $icons[$icon]['social']) {
$icons[$icon]['path'] = $social_path;
}
// Check whether the icon needs any transformation.
if (array_key_exists($icon, $transformed_icons)) {
$transformed_icons[$icon]['path'] = $path;
if ($size) {
$icons[$icon]['size'] = $size;
$transformed_icons[$icon]['size'] = $size;
}

return $icons[$icon];
return $transformed_icons[$icon];
}

// We define a default icon if one is not provided.
if (!$icon) {
$icon = 'digital';
}
$icon = [
'name' => $icon,
'path' => $path,
];
if ($size) {
return [
'name' => 'digital',
'path' => $path,
'size' => $size,
];
$icon['size'] = $size;

}
return $icon;
}

return [
'name' => 'digital',
'path' => $path,
/**
* Returns the file path for an ECL icon.
*
* @param array $context
* The twig context.
* @param string $icon
* The icon to be converted.
*
* @return string
* ECL icon file path.
*/
protected function getIconPath(array $context, string $icon): string {
// Flag icon names.
$flag_icons = [
'austria',
'belgium',
'bulgaria',
'croatia',
'cyprus',
'czech-republic',
'denmark',
'estonia',
'EU',
'finland',
'france',
'germany',
'greece',
'hungary',
'ireland',
'italy',
'latvia',
'lithuania',
'luxembourg',
'malta',
'netherlands',
'poland',
'portugal',
'romania',
'slovakia',
'slovenia',
'spain',
'sweden',
];
// Flag icons can have a -square string appended, so check if the icon name
// starts with a country name.
$found_icon = array_filter($flag_icons, function ($var) use ($icon) {
if (strpos($icon, $var) === 0) {
return TRUE;
};
return FALSE;
});
if ($found_icon) {
return $context['ecl_icon_flag_path'];
yenyasinn marked this conversation as resolved.
Show resolved Hide resolved
}

// Social media icon names.
$social_icons = [
'blog',
'facebook',
'flickr',
'foursquare',
'instagram',
'linkedin',
'pinterest',
'reddit',
'skype',
'spotify',
'twitter',
'youtube',
];
// Social icons can have a -color or a -negative string appended,
// so check if the icon name starts with a social name.
$found_icon = array_filter($social_icons, function ($var) use ($icon) {
if (strpos($icon, $var) === 0) {
return TRUE;
};
return FALSE;
});
if ($found_icon) {
return $context['ecl_icon_social_media_path'];
}
return $context['ecl_icon_path'];
}

/**
Expand Down
Loading