I'm using TYPO3 v8, how can I get the id of the current page that I'm editing in the backend?
You can get current PageId like this.
in Controller file.
$currentPid = $GLOBALS['TSFE']->id
Using Typoscript.
temp.page_uid = TEXT
temp.page_uid.field = uid
Example: In your controller:
$id = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
This depends on context, examples:
If you are extending FormEngine (editing records), the parent page record is in the data array, prepared by some rather early data provider.
If you are adding a feature to the 'info' module, the page id is a GET parameter, you should be able to access this in your controller.
Related
in my extension i'm using a custom PageTitleProvider for my detail view. It only works when the page is not cached. So i clear the cache then the title will be the name of the record when i reload the page i get the page title. I can't set the action to uncached because of the loading times.
My PageTitleProvider looks like this:
use TYPO3\CMS\Core\PageTitle\AbstractPageTitleProvider;
class CatalogPageTitleProvider extends AbstractPageTitleProvider
{
/**
* #param string $title
*/
public function setTitle(string $title)
{
$this->title = (string)$title.' | '.$GLOBALS['TSFE']->rootLine[0]['title'] ;
}
}
in the Controller i set the title like this:
$search = ['&npsp;', '' ];
$titleProvider = GeneralUtility::makeInstance(CatalogPageTitleProvider::class);
$titleProvider->setTitle( strip_tags(str_replace( $search, '', $service->getName())));
Anyone know if there is something missing or is this a know bug?
Best regards
die Knolle
There was a bugfix about a year ago with the aim to remove the seperate caches for meta tags and page titles: https://git.higidi.com/TYPO3/TYPO3.CMS/commit/44fe4992172ec0e18b28bc4a24c57a5c93b74121
From the bugfix description:
By concept for frontend rendering the page title and meta tags are not
meant to be stored in page cache in order to allow non cachable
plugins to modify those.
Currently both page title and meta tags are stored in separate cache
entries, which violates the concept above and unnecessarily tightly
couples those code parts to the TypoScriptFrontendController and
internal logic of it.
This patch removes these caches.
This fix was introduced in v 9.5.8.
I reverted the script to version 9.5.7 in my project and the page titles are correct again: https://github.com/TYPO3/TYPO3.CMS/blob/v9.5.7/typo3/sysext/core/Classes/PageTitle/PageTitleProviderManager.php
There must be a cleaner way to do this though, but I haven't found one yet.
I have written a small extension that provide news for Backend User.
Ist is just 2 Parts. One part showing the news for all BE User as a own Module, and the other part are create and edit functions provided by the TCA.
To work with the TCA forms and the default extbase getter, i need the correct storagePid. I can't set them via TypoScript, because I'm never in a page context.
My Idea was to use the Plugin settings with the file ext_conf_template.txt
# cat=persistence/enable; type=int; label=Storage pid
storagePid = 4457
But how can I tell TYPO3 to look at this Settings?
At least Repository->findAll() must respect it
Normally you would define this using TypoScript:
module.tx_yourextensionkey.persistence.storagePid = 123
Not being in a page context is not a blocker as long as you place the configuration on the first root TypoScript template (or include the TypoScript via other means which cause global inclusion not specific to any sys_template record or page tree location).
Maybe not the best solution, but it works.
I have written my own function in the repository with the pid as parameter.
I'm using the TYPO3 Query builder.
With $query->equals('pid', $pid); I get entries with my pid.
And with $query->getQuerySettings()->setRespectStoragePage(false); the default pid will be ignored.
And as the last step. My Controller gets the pid from the Settings, unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['my_extension']['storagePid']); an gives it to the function.
options=/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale='some_locale'
if I put locale=en-us it works fine,
How can I dynamically get the current page locale and pass it to the request parameter ?
So, your servlet requires locale as one of the parameters to retrieve dropdown values. I can think of 2 options to do this.
Invoke the servlet with $Path as one of the parameters. $Path will give you the complete page path, all the way till jcr:content. options=/bin/services/myservlet.GET_DROPDOWN_VALUES.json?compNode=$PATH.
In your servlet, construct page object using $PATH, then as #jwepurchase mentioned, get the locale using page.getLanguage(false).
String compNodePath = (String) request.getParameter("compNode");
String pagePath = StringUtils.substringBefore(compNodePath, "jcr:content");
PageManager pageMgr = request.getResourceResolver().adaptTo(PageManager.class);
Page page = pageMgr.getContainingPage(pagePath);
Locale pageLocale = page.getLanguage(false);
getLanguage will look for jcr:language property in currentpage or its ancestors. This property gets set when you set the Language field in page properties (advanced tab) of your page(usually set in the root locale page) to an appropriate value. eg: If you set the language to english(us), jcr:language will be en_us.
Similar steps as option 1, if value in page property is not set, you can use currentPage.getAbsoluteParent(DEPTH_VAL) to retrieve the locale value. Not a recommended soln though.
com.day.cq.wcm.api.Page.getLanguage(false) will return the value of the jcr:language property on the page or the first parent page where it is sent. Generally this isn't set on every page.
If you have included Adobe's global.jsp or used the <cq:defineObjects/> tag in your JSP, you should find that "currentPage" is already in scope, providing access to a Page object.
I generally have a custom taglib function to make it easier to access via EL. But as a scriptlet I expect the following would work:
<%= ((Page)getPageContext().getAttribute("currentPage")).getLanguage(false)%>
I have a problem with my front end admin update page. How can I retrieve values from a SiteTree page and populate it into a custom form? Is the setValue($values) function the only way? If yes, which is the best method to get the page variable?
I am using this:
$evens = Versioned::get_by_stage('PageCalendrierEvenement', 'Stage')->byID($evenID);
I'm getting values from an ID of a draft page. After I get variables and values like that:
$field = new TextField('Titre', 'Titre');
$field->setValue($evens->Titre);
or
new TextField('Titre','Titre', $evens->Titre);
Which is the better solution?
The solution is 2 part:
Use TextField::create($constructor, $args) instead of new (optional, but not doing so is a pet hate of mine).
Set all fields at once: http://api.silverstripe.org/3.1/class-Form.html#_loadDataFrom
I am creating a Joomla 2.5 component. In the backend I created a model/view/controller 'Members' which shows a grid. I also created an MVC 'Member' which is used to add or edit a member from the grid. So far so good.
Now, I would like to add a frontend view that is very similar to the 'Member' view in the backend, but this one is meant for visitors so they can subscribe themselves. It has to look more user friendly than the backend form, so I will create a slightly different 'Member' view in the frontend, but I would really like to reuse the form file (/administrator/components/mycomponent/models/forms/member.xml) from the backend!
So, my question is how my frontend view can find and use that backend form?
You definitely have to load it in the model. Your model has to extend JModelAdmin and then the getForm function has to load the form
public function getForm($data = array(), $loadData = true) {
// Get the form.
JForm::addFormPath(JPATH_COMPONENT_ADMINISTRATOR . '/models/forms');
JForm::addFieldPath(JPATH_COMPONENT_ADMINISTRATOR . '/models/fields');
$form = $this->loadForm('com_dpattachments.attachment', 'attachment', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
....
}
I'm using the same approach in my DPAttachments component, it is for Joomla 3.1 but the main code, to use the same model and form on the front and back, should also run on Joomla 2.5. Here is the link to the getForm function
https://github.com/Digital-Peak/DPAttachments/blob/master/com_dpattachments/admin/models/attachment.php#L102
If you are following Joomla MVC guidance your frontend should be able to pick-up the forms automatically.
In your view (though it should request it from the model actually) you can write:
$formsPath = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_mycom'.DS.'models'.DS.'forms';
$this->form = JForm::getInstance('myform', $formsPath.DS.'myform.xml');
You can also look at the summer of code cm_config project which pulls the config forms and the templateDetails form to the front end using JSON. https://github.com/Buddhima/joomla-cms/tree/gsoc_com_config or the com_services branch.