Browse Source

refactor the news template

Olivier Massot 5 years ago
parent
commit
3e540a9091

+ 18 - 0
ot_templating/Classes/News/NewsFilter.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace Opentalent\OtTemplating\News;
+
+use GeorgRinger\News\Utility\Page;
+use Opentalent\OtTemplating\Page\OtPageRepository;
+
+class NewsFilter
+{
+    public function createDemandObjectFromSettings($params) {
+        $pageRepo = new OtPageRepository();
+        $rootUid = $pageRepo->getRootPageFor($GLOBALS['TSFE']->id);
+        $params['demand']->setStoragePage(Page::extendPidListByChildren(
+            '' . $rootUid['uid'],
+            5
+        ));
+    }
+}

+ 44 - 0
ot_templating/Classes/ViewHelpers/Request/GetViewHelper.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace Opentalent\OtTemplating\ViewHelpers\Request;
+
+use Closure;
+use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
+
+/**
+ *   Returns the current GET request as an array.
+ *
+ *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
+ *
+ *     {ot:request.get()}
+ *
+ * @package Opentalent\OtTemplating\ViewHelpers
+ */
+class GetViewHelper extends AbstractViewHelper {
+
+    /**
+     * -- This method is expected by Fluid --
+     * Declares the viewhelper's parameters
+     */
+    public function initializeArguments()
+    {
+    }
+
+    /**
+     * -- This method is expected by Fluid --
+     * Renders the content as html
+     *
+     * @param array $arguments
+     * @param Closure $renderChildrenClosure
+     * @param RenderingContextInterface $renderingContext
+     * @return array|null
+     */
+    public static function renderStatic(
+        array $arguments,
+        Closure $renderChildrenClosure,
+        RenderingContextInterface $renderingContext
+    ) {
+        return $_REQUEST;
+    }
+}

+ 0 - 38
ot_templating/Configuration/TypoScript/setup.txt

@@ -169,41 +169,3 @@ lib.tx_ottemplating.widgets.contact {
     }
     }
     settings.persistenceIdentifier = EXT:ot_templating/Resources/Private/Forms/Contact.form.yaml
     settings.persistenceIdentifier = EXT:ot_templating/Resources/Private/Forms/Contact.form.yaml
 }
 }
-
-
-# * News extension integration
-
-# Disable error handling to allow displaying both list ans detail on the same page
-plugin.tx_news.settings {
-    detail.errorHandling =
-}
-
-# Create the news list and news details objects to render with:
-#     <f:cObject typoscriptObjectPath="lib.tx_ottemplating.widgets.listnews"/>
-#     <f:cObject typoscriptObjectPath="lib.tx_ottemplating.widgets.detailnews"/>
-lib.tx_ottemplating.widgets {
-    listnews = USER
-    listnews {
-        userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
-        extensionName = News
-        pluginName = Pi1
-        vendorName = GeorgRinger
-        action = list
-        switchableControllerActions {
-            News {
-                1 = list
-            }
-        }
-
-        settings < plugin.tx_news.settings
-        settings {
-            limit = {$settings.news.limit}
-        }
-    }
-
-    detailnews < lib.tx_ottemplating.widgets.listnews
-    detailnews {
-        action = detail
-        switchableControllerActions.News.1 = detail
-    }
-}

+ 33 - 2
ot_templating/Resources/Private/Layouts/Classic/News.html

@@ -1,17 +1,48 @@
+{namespace v=FluidTYPO3\Vhs\ViewHelpers}
+{namespace ot=Opentalent\OtTemplating\ViewHelpers}
+
 <f:comment><!-- Special layout for the Members page --></f:comment>
 <f:comment><!-- Special layout for the Members page --></f:comment>
 <f:layout name="News" />
 <f:layout name="News" />
 
 
 <f:comment><!-- Render the header defined in partial/header.html--></f:comment>
 <f:comment><!-- Render the header defined in partial/header.html--></f:comment>
 <f:render partial="Classic/Header" arguments="{_all}" />
 <f:render partial="Classic/Header" arguments="{_all}" />
 
 
+<v:variable.set name="request"
+                value="{ot:request.get()}" />
+
 <div class="main">
 <div class="main">
     <f:comment><!-- Central column --></f:comment>
     <f:comment><!-- Central column --></f:comment>
     <div class="content">
     <div class="content">
         <div class="news-section">
         <div class="news-section">
 
 
-            <f:cObject typoscriptObjectPath="lib.tx_ottemplating.widgets.detailnews" />
-            <f:cObject typoscriptObjectPath="lib.tx_ottemplating.widgets.listnews" />
+            <f:if condition="{request.tx_news_pi1.news}">
+                <f:then>
+                    <f:comment><!-- a news was required, show details --></f:comment>
+
+                    <v:render.request extensionName="News"
+                                      vendorName="GeorgRinger"
+                                      controller="News"
+                                      action="detail"
+                                      arguments="{news: request.tx_news_pi1.news}" />
+
+                    <f:link.page>
+                        Revenir à la liste des actualités
+                    </f:link.page>
+
+                </f:then>
+                <f:else>
+                    <f:comment><!-- no news was required, show list --></f:comment>
+                    <v:render.request extensionName="News"
+                                      vendorName="GeorgRinger"
+                                      controller="News"
+                                      action="list"
+                                      arguments="{overwriteDemand: {limit: 9}}" />
+                </f:else>
+            </f:if>
 
 
         </div>
         </div>
     </div>
     </div>
 </div>
 </div>
+
+<f:comment><!-- Render the footer defined in partial/footer.html--></f:comment>
+<f:render partial="Classic/Footer" />

+ 26 - 2
ot_templating/Resources/Private/Layouts/Modern/News.html

@@ -1,3 +1,6 @@
+{namespace v=FluidTYPO3\Vhs\ViewHelpers}
+{namespace ot=Opentalent\OtTemplating\ViewHelpers}
+
 <f:comment><!-- Special layout for the Members page --></f:comment>
 <f:comment><!-- Special layout for the Members page --></f:comment>
 <f:layout name="News" />
 <f:layout name="News" />
 
 
@@ -13,9 +16,30 @@
                 <div class="row">
                 <div class="row">
                     <div class="col-sm-12 mt-30">
                     <div class="col-sm-12 mt-30">
 
 
-                        <f:cObject typoscriptObjectPath="lib.tx_ottemplating.widgets.detailnews" />
+                        <f:if condition="{request.tx_news_pi1.news}">
+                            <f:then>
+                                <f:comment><!-- a news was required, show details --></f:comment>
+
+                                <v:render.request extensionName="News"
+                                                  vendorName="GeorgRinger"
+                                                  controller="News"
+                                                  action="detail"
+                                                  arguments="{news: request.tx_news_pi1.news}" />
+
+                                <f:link.page>
+                                    Revenir à la liste des actualités
+                                </f:link.page>
 
 
-                        <f:cObject typoscriptObjectPath="lib.tx_ottemplating.widgets.listnews" />
+                            </f:then>
+                            <f:else>
+                                <f:comment><!-- no news was required, show list --></f:comment>
+                                <v:render.request extensionName="News"
+                                                  vendorName="GeorgRinger"
+                                                  controller="News"
+                                                  action="list"
+                                                  arguments="{overwriteDemand: {limit: 9}}" />
+                            </f:else>
+                        </f:if>
 
 
                     </div>
                     </div>
                 </div>
                 </div>

+ 1 - 1
ot_templating/Resources/Private/Templates/Page/Members.html

@@ -9,7 +9,7 @@
     <flux:form id="members" label="Gabarit Adherents" extensionName="Opentalent.OtTemplating">
     <flux:form id="members" label="Gabarit Adherents" extensionName="Opentalent.OtTemplating">
     </flux:form>
     </flux:form>
 
 
-    <!-- Backend layout grid -->
+    <f:comment><!-- Backend layout grid --></f:comment>
     <flux:grid>
     <flux:grid>
         <flux:grid.row>
         <flux:grid.row>
         </flux:grid.row>
         </flux:grid.row>

+ 0 - 7
ot_templating/Resources/Private/Templates/Page/News.html

@@ -1,5 +1,4 @@
 {namespace flux=FluidTYPO3\Flux\ViewHelpers}
 {namespace flux=FluidTYPO3\Flux\ViewHelpers}
-{namespace v=FluidTYPO3\Vhs\ViewHelpers}
 {namespace ot=Opentalent\OtTemplating\ViewHelpers}
 {namespace ot=Opentalent\OtTemplating\ViewHelpers}
 
 
 <f:comment><!-- uses the layout 1Col, defined in layouts/[templateName]/1Col.html --></f:comment>
 <f:comment><!-- uses the layout 1Col, defined in layouts/[templateName]/1Col.html --></f:comment>
@@ -12,13 +11,7 @@
     <f:comment><!-- Backend layout grid --></f:comment>
     <f:comment><!-- Backend layout grid --></f:comment>
     <flux:grid>
     <flux:grid>
         <flux:grid.row>
         <flux:grid.row>
-            <flux:grid.column colPos="0" name="Content" label="Contenu" />
         </flux:grid.row>
         </flux:grid.row>
     </flux:grid>
     </flux:grid>
 
 
 </f:section>
 </f:section>
-
-<f:section name="Content">
-    <f:comment><!-- Render colPos=0 in this section --></f:comment>
-    <v:content.render column="0" />
-</f:section>

+ 11 - 10
ot_templating/Resources/Public/assets/Classic/script/main.js

@@ -179,16 +179,16 @@ $(document).ready(function(){
             };
             };
             items.push(item);
             items.push(item);
         });
         });
-        if (items.length === 0) {
-            console.error(mapId + ': no data to show');
-            return;
-        }
 
 
         // Instanciate the map object  @see https://leafletjs.com/reference-1.6.0.html#map-factory
         // Instanciate the map object  @see https://leafletjs.com/reference-1.6.0.html#map-factory
         var mapOptions = {scrollWheelZoom: false};
         var mapOptions = {scrollWheelZoom: false};
         var initialZoom = 13;
         var initialZoom = 13;
         var map = L.map(mapId, mapOptions);
         var map = L.map(mapId, mapOptions);
-        map.setView([items[0].lat, items[0].long], initialZoom);
+        if (items.length > 0) {
+            map.setView([items[0].lat, items[0].long], initialZoom);
+        } else {
+            map.setView([46.3399276, 2.6067229], 5);
+        }
 
 
         // Add the tile layer
         // Add the tile layer
         // L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
         // L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
@@ -210,13 +210,14 @@ $(document).ready(function(){
             marker.bindPopup(item.label);
             marker.bindPopup(item.label);
             markers.push(marker);
             markers.push(marker);
         });
         });
-        console.log(markers);
 
 
         // Set the view
         // Set the view
-        var markersGroup = new L.featureGroup(markers);
-        map.fitBounds(markersGroup.getBounds());
-        map.zoomSnap = 1;
-        map.zoomOut();
+        if (items.length > 0) {
+            var markersGroup = new L.featureGroup(markers);
+            map.fitBounds(markersGroup.getBounds());
+            map.zoomSnap = 1;
+            map.zoomOut();
+        }
     }
     }
 
 
 
 

+ 11 - 10
ot_templating/Resources/Public/assets/Modern/script/custom-ot.js

@@ -50,16 +50,16 @@ $(document).ready(function(){
 			};
 			};
 			items.push(item);
 			items.push(item);
 		});
 		});
-		if (items.length === 0) {
-			console.error(mapId + ': no data to show');
-			return;
-		}
 
 
 		// Instanciate the map object  @see https://leafletjs.com/reference-1.6.0.html#map-factory
 		// Instanciate the map object  @see https://leafletjs.com/reference-1.6.0.html#map-factory
 		var mapOptions = {scrollWheelZoom: false};
 		var mapOptions = {scrollWheelZoom: false};
 		var initialZoom = 13;
 		var initialZoom = 13;
 		var map = L.map(mapId, mapOptions);
 		var map = L.map(mapId, mapOptions);
-		map.setView([items[0].lat, items[0].long], initialZoom);
+		if (items.length > 0) {
+			map.setView([items[0].lat, items[0].long], initialZoom);
+		} else {
+			map.setView([46.3399276, 2.6067229], 5);
+		}
 
 
 		// Add the tile layer
 		// Add the tile layer
 		// L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
 		// L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
@@ -81,13 +81,14 @@ $(document).ready(function(){
 			marker.bindPopup(item.label);
 			marker.bindPopup(item.label);
 			markers.push(marker);
 			markers.push(marker);
 		});
 		});
-		console.log(markers);
 
 
 		// Set the view
 		// Set the view
-		var markersGroup = new L.featureGroup(markers);
-		map.fitBounds(markersGroup.getBounds());
-		map.zoomSnap = 1;
-		map.zoomOut();
+		if (items.length > 0) {
+			var markersGroup = new L.featureGroup(markers);
+			map.fitBounds(markersGroup.getBounds());
+			map.zoomSnap = 1;
+			map.zoomOut();
+		}
 	}
 	}
 
 
 
 

+ 3 - 0
ot_templating/ext_localconf.php

@@ -36,3 +36,6 @@ $GLOBALS['TYPO3_CONF_VARS']['LOG']['Opentalent']['OtTemplating']['writerConfigur
         ]
         ]
     ]
     ]
 ];
 ];
+
+
+$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Controller/NewsController.php']['createDemandObjectFromSettings'] = ['Opentalent\OtTemplating\News\NewsFilter->createDemandObjectFromSettings'];