extbase action only called if i am logged in backend - typo3

When I am logged in Backend, the content of "Anzeigenverwaltung" is rendered. "Anzeigenverwaltung" is my extension that calls the "listAction", which works fine. Action is called, template for this action is rendered.
But if i logout from Backend then "Anzeigenverwaltung" is not being rendered.
The content "Test" is always being rendered.
It is a fresh TYPO3 8.7 installation.
Is there any security related configuration that does not allow to call the action without an BE session?
Here is some code of my extension:
// setup.txt
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
templateName = myextension
templateRootPaths.0 = EXT:myextension/Resources/Private/Templates
variables {
content < styles.content.get
content.select.where = colPos = 0
}
}
plugin.tx_myextension {
persistence {
storagePid = 7,10
classes {
TYPO3\Myextension\Domain\Model\Location.newRecordStoragePid = 10
}
}
}
// myextension.html
<section>
<div class="container-fluid">
<div class="content">
<f:format.raw>{content}</f:format.raw>
</div>
</div>
</section>
// extbase controller
class PackageController extends \MyVendor\Myextension\Controller\AbstractController {
public function listAction() {
$packages = $this->packageRepository->findAll();
$this->view->assign('packages', $packages);
}
}
// listAction template
<f:for each="{packages}" as="package">
<f:link.action pageUid="{settings.single}" action="single" arguments="{package: package}">
</f:for>
Update:
// ext_tables.php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'TS', 'MyExtension');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('RTE.default.preset = full');
$EXTDIRFULL = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY);
$EXTDIR = 'EXT:myextension/';
$LANG = 'LLL:EXT:myextension/Resources/Private/Language/locallang.xml' . ':';
$PID_DEFAULT = 10;
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'MyVendor.' . $_EXTKEY,
'Package',
$LANG . 'admanager'
);
include_once $EXTDIRFULL . 'Configuration/TCA/package.php';
// FlexForm PackageController
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$_EXTKEY . '_package'] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($_EXTKEY . '_package', 'FILE:EXT:package/Flexform/package.xml');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(array($LANG . 'admanager', $_EXTKEY . '_package'), 'list_type', $_EXTKEY);
// ext_localconf.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'MyVendor.' . $_EXTKEY,
'Package',
array(
'Package' =>
'list,single'
)
);
// flexform
<T3DataStructure>
<sheets>
<general>
<ROOT>
<TCEforms>
<sheetTitle>Display type</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<switchableControllerActions>
<TCEforms>
<label>Display</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="1" type="array">
<numIndex index="0">LLL:EXT:myextension/Resources/Private/Language/locallang.xml:listview</numIndex>
<numIndex index="1">Package->list;Package->single;</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</switchableControllerActions>
</el>
</ROOT>
</general>
</sheets>
</T3DataStructure>

Related

TYPO3 Gridelements render FAL Image using Fluidtemplate

I'm using TYPO3 8.7 and the latest extension gridelements (8.2.3). Now I want to show/render an image in my FLUIDTEMPLATE.. - but I don't know how?!?
Here's my TypoScript:
tt_content {
gridelements_pi1 = COA
gridelements_pi1 {
20 {
10 {
setup {
SectionColoured < lib.gridelements.defaultGridSetup
SectionColoured {
cObject = FLUIDTEMPLATE
cObject {
file = EXT:myext/.../SectionColoured.html
}
}
}
}
}
}
}
Now, I upload an image (e.g. for background-image) via flexforms, like this:
<backgroundimage type="array">
<TCEforms type="array">
<label>LLL:EXT:autefa/Resources/Private/Language/backend.xlf:gridelements.SectionColoured.flexforms.backgroundimage</label>
<config type="array">
<type>inline</type>
<maxitems>1</maxitems>
<foreign_table>sys_file_reference</foreign_table>
<!--<foreign_field>uid_foreign</foreign_field>-->
<foreign_table_field>tablenames</foreign_table_field>
<foreign_label>uid_local</foreign_label>
<foreign_sortby>sorting_foreign</foreign_sortby>
<foreign_selector>uid_local</foreign_selector>
<foreign_selector_fieldTcaOverride type="array">
<config>
<appearance>
<elementBrowserType>file</elementBrowserType>
<elementBrowserAllowed>jpg,png</elementBrowserAllowed>
</appearance>
</config>
</foreign_selector_fieldTcaOverride>
<foreign_match_fields type="array">
<fieldname>image</fieldname>
</foreign_match_fields>
<appearance type="array">
<newRecordLinkAddTitle>1</newRecordLinkAddTitle>
<headerThumbnail>
<field>uid_local</field>
<height>64</height>
<width>64</width>
</headerThumbnail>
</appearance>
</config>
</TCEforms>
</backgroundimage>
That works so far. How can I use the image in my FLUIDTEMPLATE? The debugger returns 12 on {data.flexform_backgroundimage} ?!
<f:debug>{data.flexform_backgroundimage}</f:debug>
<section class="main-content {data.flexform_farbe}">
<article>
<f:format.raw>{data.tx_gridelements_view_columns.101}</f:format.raw>
</article>
</section>
Debug {data}.. THanks for your help!
pi_flexform => array(1 item)
data => array(1 item)
general => array(1 item)
lDEF => array(2 items)
farbe => array(1 item)
backgroundimage => array(1 item)
vDEF => '12' (2 chars)
Edit: image
It's funny. If I try it with the TYPO3 Fluid ViewHelper:
<section style="background-image:url({f:uri.image(src: '{data.flexform_backgroundimage}', treatIdAsReference: 1)})">
<article>
<f:format.raw>{data.tx_gridelements_view_columns.100}</f:format.raw>
</article>
</section>
I'll get an error You must either specify a string src or a File object.
Now I use vhs:
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<section style="background-image:url({v:uri.image(src: '{data.flexform_backgroundimage}', treatIdAsReference: 1)})">
<article>
<f:format.raw>{data.tx_gridelements_view_columns.100}</f:format.raw>
</article>
</section>
And everything works .. here's the view helper reference of the vhs extension. Thanks for the helping guys!
Since FAL is working with records instead of plain text paths to the image, you have to use the ID of the record to get the actual image file.
Since I am not 100% sure, you should check if 12 is the ID of the sys_file_reference record or the sys_file record used for that particular image before using the usual < f:image> viewhelper either with or without "treatIdAsReference".
https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Image.html
If you just need the path to the image and not an image tag you should go for < f:uri.image> instead.
https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Uri/Image.html
This is how I did it some time ago, using the media field of tt_content instead of using flexform. This solution assumes that
a) you are using a "frontend provider" extension (EXT:yourext) that stores your TypoScript and Fluid Templates
b) EXT:yourext depends on EXT:gridelements
c) In this example, my gridelement object is called twocolumnscontainer
1) TS Constants: use EXT:yourext as alternative path for fluid templates, layouts, partials
styles.templates.templateRootPath = EXT:yourext/Resources/Private/Templates/ContentElements/
styles.templates.partialRootPath = EXT:yourext/Resources/Private/Partials/ContentElements/
styles.templates.layoutRootPath = EXT:yourext/Resources/Private/Layouts/ContentElements/
2) in TS Setup, define the template cObject for content grids
lib.gridelements.defaultGridSetup.cObject =< lib.contentElement
tt_content.gridelements_pi1.20.10.setup.twocolumnscontainer < lib.gridelements.defaultGridSetup
tt_content.gridelements_pi1.20.10.setup.twocolumnscontainer {
cObject.templateName = GridElementTwoColumns
cObject.dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = media
as = backgroundimage
}
}
}
3) In TS Config:
tx_gridelements.setup.twocolumnscontainer {
title = Two columns element with background image
description = whatever
config{
colCount = 2
rowCount = 1
rows {
1 {
columns {
1 {
name = column 1
colPos = 100
}
2 {
name = column 2
colPos = 101
}
}
}
}
}
}
4) EXT:yourext/TCA/Overrides/tt_content_element_gridelement.php
<?php
defined('TYPO3_MODE') || die();
call_user_func(function()
{
/**
* Limit the number of images in "media" for gridelements contents
*/
$GLOBALS['TCA']['tt_content']['types']['gridelements_pi1']['columnsOverrides']['media']['config']['maxitems']=1;
});
5) Define the Fluid template (I removed the classes so you can use whatever you want, Bootstrap, Foundation...):
EXT:yourext/Resources/Private/Templates/ContentElements/GridElementTwoColumns.html
<f:layout name="Default"/>
<f:section name="Main">
<f:if condition="{backgroundimage.0}">
{f:uri.image(image:backgroundimage.0)}
</f:if>
<div class="">
<div class="">
{data.tx_gridelements_view_column_100-> f:format.raw()}
</div>
<div class="">
{data.tx_gridelements_view_column_101-> f:format.raw()}
</div>
</div>
</f:section>
I hope I have not forgotten important steps :)
This should work for you:
<f:uri.image src="{data.flexform_backgroundimage}" treatIdAsReference="1"/>

Top rated products magento 2

I want to display top rated products in magento 2
My block Toprated.php
public function getTesting()
{
$collection = $this->_productCollectionFactory->create();
foreach($collection as $eachColl)
{
$storeId = $eachColl->getStore()->getId();
$reviewSum = $this->reviewSummaryFactory->create()->setStoreId($storeId)->load($eachColl->getId());
$rated[] = array(
'rating' => $reviewSum['rating_summary'],
'name' => $eachColl->getName(),
'url' => $eachColl->getUrlPath(),
'product_sku' => $eachColl->getSku()
);
$rateds[$eachColl->getSku()] = $reviewSum['rating_summary'];
}
arsort($rateds);
$rateds = array_slice($rateds, 0, 3);
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToFilter('status', '1');
$collection->addAttributeToFilter('rating', array('in' => implode(",", $rateds)));
return $collection;
}
my template toprated.phtml file
<?php
$_productCollection = $this->getTesting();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
?>
but phtml file not calling any data.what i did mistake here
Where do you want to show the new block ?
It is possible by edit/add a layout file in view/frontend/layout/
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceContainer name="content">
<block
template="[your template]"
class="[your class]"
name="[your name]"/>
</referenceContainer>
create layout file in view -> frontend -> templates -> layout ,
file name should be your routname_controllernamespace_controllername (controller->Index->index.php)
ex. blog_index_index file should be look like this
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Demo\Blog\Block\PostList" name="demo.list" template="Demo_Blog::list.phtml" />
</referenceContainer>
</body>
</page>

How do I pass an object to, or set a variable in a TVML template file I am using?

I'm working with the TVMLCatalog sample files from Apple, and am stuck trying to pass an object to a template file I am loading in the presenter (javascript file). This seems like it should be a totally rudimentary thing to accomplish, but it has me beat.
I have the following, which loads a template with the resource loader, and pushes it to the view.
resourceLoader.loadResource('http://localhost/mytemplate.xml.js',
function(resource) {
if (resource) {
var doc = self.makeDocument(resource);
doc.addEventListener("select", self.load.bind(self));
navigationDocument.pushDocument(doc);
}
}
);
Where do I define an object or set a variable that will be in the document when the template file is loaded in the view?
Yes! You can inject variables into your TVML templates.
First, you have to create a string that contain the same TVML template, and use ${variable} to inject values.
Then, use DOMParser object to convert this string into XML DOM element.
Finally, present the document with help of presentModal method (main object navigationDocument)
Your function will look like this:
function catalogTemplate(title, firstMovie, secMovie) {
var xmlStr = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<catalogTemplate>
<banner>
<title>${title}</title>
</banner>
<list>
<section>
<listItemLockup>
<title>All Movies</title>
<decorationLabel>2</decorationLabel>
<relatedContent>
<grid>
<section>
<lockup>
<img src="http://a.dilcdn.com/bl/wp-content/uploads/sites/2/2014/03/Maleficent-Poster.jpg" width="250" height="376" />
<title>${firstMovie}</title>
</lockup>
<lockup>
<img src="http://www.freedesign4.me/wp-content/gallery/posters/free-movie-film-poster-the_dark_knight_movie_poster.jpg" width="250" height="376" />
<title>${secMovie}</title>
</lockup>
</section>
</grid>
</relatedContent>
</listItemLockup>
</section>
</list>
</catalogTemplate>
</document>`
var parser = new DOMParser();
var catalogDOMElem = parser.parseFromString(xmlStr, "application/xml");
navigationDocument.presentModal(catalogDOMElem );
}
PS: I used Catalog template as an example. You can use any template
In the onLaunch function, you can call the catalogTemplate function by passing any variable.
App.onLaunch = function(options) {
catalogTemplate("title", "Maleficent.", "The Dark knight");
}
You can add a listener and pass an function to move to another page or trigger an action using addEventListener
function catalogTemplate(title, firstMovie, secMovie, cb) {
var xmlStr = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<catalogTemplate>
<banner>
<title>${title}</title>
</banner>
<list>
<section>
<listItemLockup>
<title>All Movies</title>
<decorationLabel>2</decorationLabel>
<relatedContent>
<grid>
<section>
<lockup>
<img src="http://a.dilcdn.com/bl/wp-content/uploads/sites/2/2014/03/Maleficent-Poster.jpg" width="250" height="376" />
<title>${firstMovie}</title>
</lockup>
<lockup>
<img src="http://www.freedesign4.me/wp-content/gallery/posters/free-movie-film-poster-the_dark_knight_movie_poster.jpg" width="250" height="376" />
<title>${secMovie}</title>
</lockup>
</section>
</grid>
</relatedContent>
</listItemLockup>
</section>
</list>
</catalogTemplate>
</document>
`
var parser = new DOMParser();
var catalogDOMElem = parser.parseFromString(xmlStr, "application/xml”);
catalogDOMElem.addEventListener("select", cb, false);
navigationDocument.presentModal(catalogDOMElem );
}
Let's create another template just to showcase how we jump to another page by selecting a specific item.
function ratingTemplate(title) {
var xmlStr = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<ratingTemplate>
<title>${title}</title>
<ratingBadge value="0.8"></ratingBadge>
</ratingTemplate>
</document>`
var parser = new DOMParser();
var ratingDOMElem = parser.parseFromString(xmlStr,"application/xml");
navigationDocument.presentModal(ratingDOMElement);
}
In our onLaunch function.
App.onLaunch = function(options) {
catalogTemplate("title", "Maleficent.", "The Dark knight", function() {
navigationDocument.dismissModal();
ratingTemplate(“rating template title")
});
}
Check this list for more tutorials.

Call ViewHelper from outside Fluid template

In my general page setup, I define the template as follows: page.10.template.file = fileadmin/template.html
Is there a way to call a MVC ViewHelper in this template? The snippet
{namespace xyz=PATH\TO\MY\ViewHelpers}
<xyz:myhelper argument="abc" />
does not work in the above template, it is surfaced as is.
It is not 100% clear for me, which cObject you use for your page template. If you would like to use Fluid ViewHelpers in your page template, then I would recommend to use FLUIDTEMPLATE for your page template.
1. FLUIDTEMPLATE
If you use FLUIDTEMPLATE for your page template, then you can use any available ViewHelper (from FLUID or any other ExtBase/Fluid extension) directly in your template (see example below).
TypoScript
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
template = FILE
template.file = fileadmin/templates/template.html
partialRootPath = fileadmin/templates/Partials/
layoutRootPath = fileadmin/templates/Layouts/
variables {
content < styles.content.get
content.select.where = colPos=1
}
}
Content of file: fileadmin/templates/template.html
{namespace xyz=NAMESPACE\EXTENSION\ViewHelpers}
<f:layout name="Main" />
<f:section name="Content">
<xyz:myhelper argument="abc" />
<f:format.html parseFuncTSPath="">{content}</f:format.html>
</f:section>
Content of file: fileadmin/templates/Layouts/Main.html
<f:render section="Content" />
2. TEMPLATE
If you use TEMPLATE (with markers and subparts), then you can't directly use Fluid ViewHelpers in that template. But you could define a marker which renders the FLUID ViewHelper like shown below.
TypoScript
page = PAGE
page.10 = TEMPLATE
page.10 {
template = FILE
template.file = fileadmin/templates/template.html
marks {
CONTENT < styles.content.get
VIEWHELPER = FLUIDTEMPLATE
VIEWHELPER {
template = FILE
template.file = fileadmin/templates/viewhelper.html
partialRootPath = fileadmin/templates/Partials/
layoutRootPath = fileadmin/templates/Layouts/
}
}
workOnSubpart = DOCUMENT
}
Content of file: fileadmin/templates/template.html
<!--###DOCUMENT### Start-->
###VIEWHELPER###
###CONTENT###
<!--###DOCUMENT### end-->
Content of file: fileadmin/templates/viewhelper.html
{namespace xyz=NAMESPACE\EXTENSION\ViewHelpers}
<f:layout name="Main" />
<f:section name="Content">
<xyz:myhelper argument="abc" />
</f:section>
Content of file: fileadmin/templates/Layouts/Main.html
<f:render section="Content" />

giving errors in bootstrap when try to use breadcrumbs in zend framework

hi i want to use a breadcrumb for my zend framework application
i craeted navigation.xml in configs folder where application.ini is .
and in the bootstarp i added following code
protected function _initNavigation()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml');
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
}
and in the layout i added folllowing code
<div id="menu">
<?php echo $this->navigation()->menu(); ?>
</div>
<div id="breadcrumbs">
You are in: <?php echo $this->navigation()->breadcrumbs()->setLinkLast(false)->setMinDepth(0)->render(); ?>
</div>
it is not working , errors are given
Fatal error: Uncaught exception 'Zend_Navigation_Exception' with message 'Invalid argument: Unable to determine class to instantiate' in /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Page.php:223
Stack trace:
#0 /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Container.php(117): Zend_Navigation_Page::factory(Array)
#1 /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Container.php(164): Zend_Navigation_Container->addPage(Array)
#2 /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation.php(46): Zend_Navigation_Container->addPages(Object(Zend_Config_Xml))
#3 /home/kanishka/workspace/jetwing_ibe/application/Bootstrap.php(94): Zend_Navigation->__construct(Object(Zend_Config_Xml))
#4 /home/kanishka/workspace/jetwing_ibe/library/Zend/Application/Bootstrap/BootstrapAbstract.php(666): Bootstrap->_initNavigation()
#5 /home/kanishka/workspace/jetwing_ibe/library/Zend/Application/Bootstrap/BootstrapAbstract.php(619): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('navigati in /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Page.php on line 223
this is my xml file
<?xml version="1.0" encoding="UTF-8"?>
<config>
<nav>
<dashboard>
<label>dashboard</label>
<controller>dashboard</controller>
<action>index</action>
<resource>dashboard</resource>
<pages>
<rates>
<label>Rates</label>
<controller>rates</controller>
<action>index</action>
<pages>
<index>
<label>index</label>
<controller>rates</controller>
<action>index</action>
<class>dontdisplay</class>
</index>
</pages>
</rates>
<occupancydenomination>
<label>Occupancydenominations</label>
<controller>occupancydenomination</controller>
<action>index</action>
<pages>
<index>
<label>Occupancydenomination</label>
<controller>occupancydenomination</controller>
<action>index</action>
<class>dontdisplay</class>
</index>
<add>
<label>Add Occupancydenomination</label>
<controller>occupancydenomination</controller>
<action>add</action>
<class>dontdisplay</class>
</add>
</pages>
</occupancydenomination>
</pages>
</dashboard>
</nav>
</config>
i am not sure what the error is . please help me ................
The error is due to your config file.
You're not providing enough parameters for the navigation container to determine the correct page type, Zend_Navigation_Page_Mvc or Zend_Navigation_Page_Uri.
Also, you know there's a navigation resource plugin, right?
UPDATE
Get rid of the <nav> wrapper element. It's trying to interpret that as a page.
That or do follow the example and specify the config section correctly
$config = new Zend_Config_Xml('/path/to/navigation.xml', 'nav');
$container = new Zend_Navigation($config);