How can I render preview of FE plugin diplayed in Page module - typo3

I have developed TYPO3 (6.2) extensions with some FE plugins.
I need to change informations about plugin, which is displayed in the backend on page view.
Now only Title and name of plugin is displayed ...
I have used flexforms for configure the plugin and I would like to show some of configuration on the plugin "placeholder" in the backend.
I remember, I read some documentation how to do it a few years ago, but I can't find it anymore...
Does anyone know the right way to do it?

If I understood well you are asking for ContentElement preview. You need to use cms/layout/class.tx_cms_layout.php hook for this, here's quite nice gist
just two additions:
don't use t3lib_extMgm class it's removed since 7.x you can register this hook just with:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'][$_EXTKEY]
= 'EXT:your_ext/Classes/Hooks/PageLayoutView.php:\Vendor\YourExt\Hooks\PageLayoutView';
Depending on how did you register the plugin (didn't mention) you can also need to check the $row['list_type'] as your $row['CType'] may be just generic list.
Sample class with value from FlexForm field
<?php
namespace Vendor\YourExt\Hooks;
class PageLayoutView implements \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface {
public function preProcess(\TYPO3\CMS\Backend\View\PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row) {
if ($row['CType'] == 'list' && $row['list_type'] == 'yourext_yourplugin') {
$drawItem = false;
$linkStart = '<a href="#" onclick="window.location.href=\'../../../alt_doc.php?returnUrl=%2Ftypo3%2Fsysext%2Fcms%2Flayout%2Fdb_layout.php%3Fid%3D' . $row['pid'] . '&edit[tt_content][' . $row['uid'] . ']=edit\'; return false;" title="Edit">';
$linkEnd = '</a>';
$headerContent =
$linkStart .
"<strong>Selected slides</strong>" .
$linkEnd;
$ffXml = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($row['pi_flexform']);
$itemContent =
$linkStart .
$ffXml['data']['sDEF']['lDEF']['settings.myFlexField']['vDEF'] .
$linkEnd;
}
}
}

Related

TYPO3 Extbase Parameters in Url get ignored. No action is called

I'm writing an extension which checks for the browser version, and if the version isn't supported a hint is showed.
I'm doing this with a typoscript condition, which works well so far. But in the hint is a link for the ignoring. The link should call my action "setSessionParameters" in the controller "BrowserCheck". If the link is clicked the correct url gets called, but the same output as before is shown (the hint). The action is completly ignored. I tried to put in a non existing action, but not even an exception is called, which means for me: It's not checked if the question is allowed in the ext_localconf and neither it gets checked in the controller.
I think the typoscript configuration could be a problem, but I can't find a solution. Can anyone help?
Please see my code below
ext_localconf.php:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'VENDOR.' . $extensionKey,
'browsercheck',
[
'BrowserCheck' => 'setSessionParameter',
],
[
'BrowserCheck' => 'setSessionParameter',
]
);
page.typoscript:
page = PAGE
[session('wcobrowsercheck') == "ignore" || checkInternetExplorer()]
page{
//normal setup
}
[ELSE]
// called setup for hint-case
page >
page = PAGE
page{
typeNum = 0
shortcutIcon = {$files.favicon.path}
10 = FLUIDTEMPLATE
10 {
templateRootPaths {
0 = EXT:my_extension/Resources/Private/Templates/BrowserCheck
}
layoutRootPaths {
0 = EXT:my_extension/Resources/Private/Layouts/BrowserCheck
}
templateName = MainPage
}
includeCSS {
...
}
}
[END]
link call in the template:
<f:link.action controller="BrowserCheck" action="setSessionParameters" extensionName="my_extension" pluginName="browsercheck" arguments="{ignore: 'true'}"> ignore </f:link.action>
I see 2 issues with your setup.
You define the PAGE object twice. And the second time you wipe all previous configuration
I can't see that you have placed the plugin on the page.
As your question targets the second issue, I recommend adding the plugin to the page via typoscript if you want that plugin to be available everywhere.
page = PAGE
// ...
page.999 < tt_content.list.20.extkey_pluginname
Or you use a plugin that is placed on the page as a content element. Both will work. But with the current setup you cannot call the plugin as it's not present on the page.

Magento2 custom price render on product page

How to format the product view page price differently from the one from category page ( and possible others ) ?
If I change in my child theme the:
app/design/frontend/VENDOR/my_theme/Magento_Catalog/templates/product/price/final_price.phtml
The price is being changed on both pages (category and product);
I have tried several approaches but it seems that this price rendering mechanism is complicated as hell in Magento2.
Thanks!
<?php
try {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get(‘Magento\Framework\App\Action\Context’)->getRequest();
$currentPageXML = $request->getFullActionName();
echo $currentPageXML; //catalog_product_view is product detail page controller action
} catch (Exception $e) {}
?>
The above code will help you get the current area of the environment being accessed, and then you can apply a logic
if ($currentPageXML=="catalog_product_view") {
// render my custom need
} else {
// keep the actual code intact.
}
You are facing a problem because same phtml file is being used by both the catalog and product page, so a change in this file will be reflected everywhere.
I hope this will help you.

archive functionality for magento aw_blog extension

I have been working with a client who wanted a blog in the magento website. After installing the AW blog extension i realized that it doesn't have archive functionality, and i didn't find any solution in the web.
After few days of work, I have finally found a solution for this task. I didn't know where to post it, and I thought that this is the best place to share it.
I know that people usually don't post answers here, but I have to share, because out there, somebody is having difficult time, or might have.
I will presume that you already installed the AW Blog extension to your magento project. blog extension page
1) first of all we need a placeholder for future datepicker. I choose the sidebar of AW_blog extension: app\design\frontend\YOUR_THEME\default\template\aw_blog\menu.phtml
I added following html markup almost to the end:
<div class="block-content">
<div class="menu-recent">
<h5 class="uppercase"><?php echo Mage::helper('blog')->__('Archives'); ?></h5>
<div id="datepicker"></div>
</div>
</div>
2) After this i added jquery ui datepicker into project. we will need it for date selection. jquery ui page. Here I need make some note. I only copied the jquery-ui.js, jquery-ui.css, images folder with theme icons. I did this because i didn't need anything else. you can download everything if you want, but the key files are jquery-ui.js, jquery-ui.css, images folder.
a) copy jquery-ui.js into skin\js directory
b) copy jquery-ui.css and images folder into skin\frontend\YOUR_THEME\default\css directory
3) Add following code to app\design\frontend\default\default\layout\page.xml
<default translate="label" module="page">
<label>All Pages</label>
<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
<block type="page/html_head" name="head" as="head">
....
<action method="addJs"><script>jquery-ui.js</script></action>
...
<action method="addCss"><stylesheet>css/jquery-ui.css</stylesheet></action>
4) add following code to app\design\frontend\YOUR_THEME\default\template\page\head.phtml
this is just simple work with datepicker plugin
jQuery(function(){
jQuery( "#datepicker" ).datepicker({
dateFormat:"yy-mm-dd",
onSelect: function(dateText) {
window.location = '<?php echo Mage::getBaseUrl();?>news/?date='+dateText;//refreshes screen
}
});
});
all these four 4 steps are for frontend stuff. now we will go to the backend programming
1) open app\code\community\AW\Blog\Block\blog.php and replace getPosts() function with following code
public function getPosts()
{
$collection = parent::_prepareCollection();
$tag = $this->getRequest()->getParam('tag');
$date = $this->getRequest()->getParam('date');//gets $_GET[date] parameter
if ($tag) {
$collection->addTagFilter(urldecode($tag));
}
else if ($date) { // checks if $date parameter exists
$collection->addDateFilter(urldecode($date));
}
parent::_processCollection($collection);
return $collection;
}
2) open app\code\community\AW\Blog\Model\Mysql4\Blog\Collection.php and add following function
public function addDateFilter($date) {
if ($date = trim($date)) {
$whereString = sprintf("main_table.created_time >= %s", $this->getConnection()->quote($date));
$this->getSelect()->where($whereString);
}
return $this;
}
This is it guys. If you need any help, just let me know. Thanks for your time.
for month and year list archive
public function addDateFilter($date) {
if ($date = trim($date)) {
$whereString = sprintf(
"main_table.created_time = %s OR main_table.created_time LIKE %s OR main_table.created_time LIKE %s ",
$this->getConnection()->quote($date), $this->getConnection()->quote($date . '-%'),
$this->getConnection()->quote('%-' . $date),$this->getConnection()->quote('%-' . $date . '-%')
);
$this->getSelect()->where($whereString);
}
return $this;
}
Examples:
foo.com/index.php/news/?date=2014 or bar.com/index.php/news/?date=2014-02

Drupal 7 - Overriding Basic Form HTML Mark-Up

I'm really struggling to get my head around Drupal Form API...actually Drupal as a whole.
Here's my problem, I've created a form with renders fine, however what I've like to do now is wrapper divs around certain form elements, this is so I style my form in a way that'll suit my site and not some box standard crap.
Can someone please help or at the least point in the right direction of a "good" tutorial and not some brief and very vague nonsense that is plastered all over the web?
thanks.
hook_form_alter is your friend here.
In your theme's template.php file you can add prefixes and suffixes to forms, form elements etc.
Below is an example from a site I did recently.
function bhha_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_login') {
$form['#prefix'] = '<div class="loginForm">';
$form['#suffix'] = '</div>';
$form['name']['#title'] = Null; // Change text on form
$form['name']['#description'] = Null; // Change text on form
$form['name']['#attributes'] = array('placeholder' => t('username'));
$form['name']['#size'] = '30';
$form['pass']['#title'] = Null;
$form['pass']['#description'] = Null; // Change text on form
$form['pass']['#attributes'] = array('placeholder' => t('password'));
$form['pass']['#size'] = '30';
//$form['actions']['submit']['#value'] = t('password');
$form['actions']['submit'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/Login.png');
$form['links']['#markup'] = '<a class="user-password" href="'.url('user/password').'">' . t('Forgot your password?') . '</a>'; // Remove Request New Password from Block form
$form['links']['#weight'] = 540;
}
}
Inspect your code to get the form you want to theme's id. Replace underscores with hyphens and you should be able to use the example above to do what you want.
At it's most basic I guess an example would be:
function THEME_NAME_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'FORM_ID') {
// Adds a wrapper div to the whole form
$form['#prefix'] = '<div class="loginForm">';
$form['#suffix'] = '</div>';
// Adds a wrapper div to the element NAME
$form['name']['#prefix'] = '<div class="formRow">';
$form['name']['#suffix'] = '</div>';
}
}
Several ways to do this. For example
If you are looking to overwrite the markup at field level, you could use field.tpl.php or template_preprocess_field().
If you want to change the enclosing markup of your form (although I'd wonder why as Drupal's standard markup is immensely style-able), you'd want to register theme functions and handle markup thusly. Here's a nice article that elaborates on this.

Joomla: Plugins that modify Categories

I am trying to make a plugin for Joomla that mimics all the changes you do on content categories in a menu item. So adding, deleting and editing the name of a category in a specific article will also make the same changes on a menu item.
A content plugin has events such as onBeforeContentSave and onAfterDisplayContent that allow you to process that data. How do I do the same thing for categories?
Unfortunately, there isn't an onCategorySave event. The best approach I can think of would be to create a system plugin and check the task and option request variables for values of save and com_categories. Your plugin would look something like this:
<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');
class plgSystemCategorysave extends JPlugin
{
function onAfterInitialise()
{
if (!JFactory::getApplication()->isAdmin()) {
return; // Dont run in frontend
}
$option = JRequest::getCmd('option', '');
$task = JRequest::getCmd('task', '');
if ($option == 'com_categories' && $task == 'save') {
// your processing code here
}
}
}