Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from berta-cms/enh-twig-background-gallery-ed…
…itor Twig: background gallery editor
- Loading branch information
Showing
10 changed files
with
275 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
_api_app/app/Sites/Sections/SectionBackgroundGalleryEditorRenderService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
namespace App\Sites\Sections; | ||
|
||
use App\Shared\ImageHelpers; | ||
|
||
class SectionBackgroundGalleryEditorRenderService | ||
{ | ||
private function getGalleryItems($currentSection, $storageService, $basePath) | ||
{ | ||
$files = !empty($currentSection['mediaCacheData']['file']) ? $currentSection['mediaCacheData']['file'] : []; | ||
|
||
$items = array_map(function ($item, $index) use ($currentSection, $storageService, $basePath) { | ||
$imagePath = "{$storageService->MEDIA_URL}/{$currentSection['mediafolder']}/{$item['@attributes']['src']}"; | ||
$thumbnail = ImageHelpers::getThumbnail($imagePath); | ||
|
||
return array_merge($item['@attributes'], [ | ||
'thumbnail' => $thumbnail, | ||
'caption' => $item['@value'], | ||
'captionDataPath' => "{$basePath}/mediaCacheData/file/{$index}/@value" | ||
]); | ||
}, $files, array_keys($files)); | ||
|
||
return $items; | ||
} | ||
|
||
private function getViewData( | ||
$siteSlug, | ||
$currentSection, | ||
$currentSectionIndex, | ||
$storageService | ||
) { | ||
$basePath = "{$siteSlug}/section/{$currentSectionIndex}"; | ||
$hideNavigation = !empty($currentSection['mediaCacheData']['@attributes']['hide_navigation']) ? $currentSection['mediaCacheData']['@attributes']['hide_navigation'] : 'no'; | ||
$animation = !empty($currentSection['mediaCacheData']['@attributes']['animation']) ? $currentSection['mediaCacheData']['@attributes']['animation'] : 'enabled'; | ||
$fadeContent = !empty($currentSection['mediaCacheData']['@attributes']['fade_content']) ? $currentSection['mediaCacheData']['@attributes']['fade_content'] : 'disabled'; | ||
$backgroundColor = !empty($currentSection['sectionBgColor']) ? $currentSection['sectionBgColor'] : 'none'; | ||
$captionColor = !empty($currentSection['mediaCacheData']['@attributes']['caption_color']) ? $currentSection['mediaCacheData']['@attributes']['caption_color'] : 'none'; | ||
$captionBackgroundColor = 'none'; | ||
if (!empty($currentSection['mediaCacheData']['@attributes']['caption_bg_color'])) { | ||
$captionBackgroundColor = '#'; | ||
foreach (explode(',', $currentSection['mediaCacheData']['@attributes']['caption_bg_color']) as $val) { | ||
$captionBackgroundColor .= dechex($val); | ||
} | ||
} | ||
$imageSize = !empty($currentSection['mediaCacheData']['@attributes']['image_size']) ? $currentSection['mediaCacheData']['@attributes']['image_size'] : 'medium'; | ||
$autoPlay = !empty($currentSection['mediaCacheData']['@attributes']['autoplay']) ? $currentSection['mediaCacheData']['@attributes']['autoplay'] : '0'; | ||
|
||
$dataPath = [ | ||
'addMedia' => $basePath, | ||
'hideNavigation' => "{$basePath}/mediaCacheData/@attributes/hide_navigation", | ||
'animation' => "{$basePath}/mediaCacheData/@attributes/animation", | ||
'fadeContent' => "{$basePath}/mediaCacheData/@attributes/fade_content", | ||
'backgroundColor' => "{$basePath}/sectionBgColor", | ||
'captionColor' => "{$basePath}/mediaCacheData/@attributes/caption_color", | ||
'captionBackgroundColor' => "{$basePath}/mediaCacheData/@attributes/caption_bg_color", | ||
'imageSize' => "{$basePath}/mediaCacheData/@attributes/image_size", | ||
'autoPlay' => "{$basePath}/mediaCacheData/@attributes/autoplay" | ||
]; | ||
|
||
$items = $this->getGalleryItems($currentSection, $storageService, $basePath); | ||
|
||
return [ | ||
'dataPath' => $dataPath, | ||
'hideNavigation' => $hideNavigation, | ||
'animation' => $animation, | ||
'fadeContent' => $fadeContent, | ||
'backgroundColor' => $backgroundColor, | ||
'captionColor' => $captionColor, | ||
'captionBackgroundColor' => $captionBackgroundColor, | ||
'imageSize' => $imageSize, | ||
'autoPlay' => $autoPlay, | ||
'items' => $items | ||
]; | ||
} | ||
|
||
public function render( | ||
$siteSlug, | ||
$sectionSlug, | ||
$sections, | ||
$storageService | ||
) { | ||
$currentSection = null; | ||
|
||
if (!empty($sections)) { | ||
$currentSectionIndex = array_search($sectionSlug, array_column($sections, 'name')); | ||
$currentSection = $sections[$currentSectionIndex]; | ||
} | ||
|
||
if (!$currentSection) { | ||
return ''; | ||
} | ||
|
||
$data = $this->getViewData( | ||
$siteSlug, | ||
$currentSection, | ||
$currentSectionIndex, | ||
$storageService | ||
); | ||
|
||
return view('Sites/Sections/sectionBackgroundGalleryEditor', $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
_api_app/app/Sites/Sections/sectionBackgroundGalleryEditor.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<div id="xBgEditorPanel" class="xPanel"> | ||
<div class="xBgEditorTabs"> | ||
<div class="xBgMediaTab tab"> | ||
<a href="#" class="xParams-media selected" title="add images and videos"> | ||
<span>media</span> | ||
</a> | ||
</div> | ||
<div class="xBgSettingsTab tab"> | ||
<a href="#" class="xParams-settings" title="background settings"> | ||
<span>background settings</span> | ||
</a> | ||
</div> | ||
<div class="xBgSlideshowSettingsTab tab"> | ||
<a href="#" class="xParams-slideshow_settings" title="slideshow settings"> | ||
<span>slideshow settings</span> | ||
</a> | ||
</div> | ||
<div class="xBgImgSizeSettingsTab tab"> | ||
<a href="#" class="xParams-image_size_settings" title="image size"> | ||
<span>image size</span> | ||
</a> | ||
</div> | ||
<a class="xBgEditorCloseLink" href="#" title="close background editor"> | ||
<span>X</span> | ||
</a> | ||
</div> | ||
<div class="xBgAddMedia"> | ||
<input type="file" name="Filedata" class="xHidden" multiple> | ||
<a class="xEntryAddImagesLink" href="/_api/v1/sites/sections/backgrounds" data-path="{{ dataPath.addMedia }}">+ add media</a> | ||
</div> | ||
<div class="xBgSettings xHidden"> | ||
<div class="xBgNavigationSettings"> | ||
<div class="caption">hide navigation arrows</div> | ||
<div class="xBgNavigation xFloatLeft xEditableSelectRC xCommand-SET_BG_NAVIGATION" x_options="no||yes" data-path="{{ dataPath.hideNavigation }}"> | ||
{{ hideNavigation }} | ||
</div> | ||
<div class="clear"></div> | ||
</div> | ||
<div class="xBgAnimationSettings"> | ||
<div class="caption">animation</div> | ||
<div class="xBgAnimation xEditableSelectRC xCommand-SET_BG_ANIMATION" x_options="enabled||disabled" data-path="{{ dataPath.animation }}"> | ||
{{ animation }} | ||
</div> | ||
<div class="clear"></div> | ||
</div> | ||
<div class="xBgFadingSettings"> | ||
<div class="caption">fade content</div> | ||
<div class="xBgFading xEditableSelectRC xCommand-SET_BG_FADE_CONTENT" x_options="enabled||disabled" data-path="{{ dataPath.fadeContent }}"> | ||
{{ fadeContent }} | ||
</div> | ||
<div class="clear"></div> | ||
</div> | ||
<div class="xBgColorSettings"> | ||
<div class="caption">background color</div> | ||
<div class="xBgColor xEditableColor xProperty-sectionBgColor xNoHTMLEntities xCSSUnits-0 xRequired-1" data-path="{{ dataPath.backgroundColor }}"> | ||
{{ backgroundColor }} | ||
</div> | ||
<div class="xBgColorReset xReset xCommand-sectionBgColorReset xParams-sectionBgColor" data-path="{{ dataPath.backgroundColor }}"> | ||
<a href="#"> | ||
<span>remove</span> | ||
</a> | ||
</div> | ||
<div class="clear"></div> | ||
<div class="caption">caption text color</div> | ||
<div class="xBgColor xEditableColor xCommand-SET_BG_CAPTION_COLOR xNoHTMLEntities xCSSUnits-0 xRequired-1" data-path="{{ dataPath.captionColor }}"> | ||
{{ captionColor }} | ||
</div> | ||
<div class="xBgColorReset xReset xCommand-RESET_BG_CAPTION_COLOR xParams-SET_BG_CAPTION_COLOR" data-path="{{ dataPath.captionColor }}"> | ||
<a href="#"> | ||
<span>remove</span> | ||
</a> | ||
</div> | ||
<div class="clear"></div> | ||
<div class="caption">caption background color</div> | ||
<div class="xBgColor xEditableColor xCommand-SET_BG_CAPTION_BACK_COLOR xNoHTMLEntities xCSSUnits-0 xRequired-1" data-path="{{ dataPath.captionBackgroundColor }}"> | ||
{{ captionBackgroundColor }} | ||
</div> | ||
<div class="xBgColorReset xReset xCommand-RESET_BG_CAPTION_BACK_COLOR xParams-SET_BG_CAPTION_BACK_COLOR" data-path="{{ dataPath.captionBackgroundColor }}"> | ||
<a href="#"> | ||
<span>remove</span> | ||
</a> | ||
</div> | ||
<div class="clear"></div> | ||
</div> | ||
</div> | ||
<div class="xBgImgSizeSettings xHidden"> | ||
<div class="caption">background image size</div> | ||
<div class="xBgImgSize xEditableSelectRC xCommand-SET_BG_IMG_SIZE" x_options="large||medium||small" data-path="{{ dataPath.imageSize }}"> | ||
{{ imageSize }} | ||
</div> | ||
<div class="clear"></div> | ||
</div> | ||
<div class="xBgSlideshowSettings xHidden"> | ||
<div class="caption">autoplay seconds</div> | ||
<div class="xBgAutoPlay xEditableRC xCommand-SET_AUTOPLAY xCaption-0" title="{{ autoPlay }}" data-path="{{ dataPath.autoPlay }}"> | ||
{{ autoPlay }} | ||
</div> | ||
<div class="clear"></div> | ||
</div> | ||
<div class="images"> | ||
<ul> | ||
{% for item in items %} | ||
<li class="image" filename="{{ item.src }}"> | ||
<img class="img" src="{{ item.thumbnail }}"> | ||
<span class="grabHandle xMAlign-container"> | ||
<span class="xMAlign-outer"> | ||
<a class="xMAlign-inner" title="click and drag to move"> | ||
<span></span> | ||
</a> | ||
</span> | ||
</span> | ||
<a href="#" class="delete"></a> | ||
<div class="xEGEImageCaption xEditableMCESimple xProperty-galleryImageCaption xCaption-caption xParam-{{ item.src }}" data-path="{{ item.captionDataPath }}"> | ||
{{ item.caption|raw }} | ||
</div> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> |
Oops, something went wrong.