TYPO3 fill backend fields in content element with database values - php

I'm trying to distribute JSON data from inside a tt_content database field into the other existing fields, like the TYPO3 default input field header.
I tried finding a hook which lets me handle the distribution manually like I could while saving via
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][]
in my ext_localconf.php. I couldn't find one. So I took a look at the TCA to see if there are possible settings I can use, but I couldn't as well.
Do you know a way on how to do this data distribution manually?

I found the solution:
You have to do 2 things in your ext_localconf.php file
To change data before saving to the database you have to call:
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = \YourNamespace\Hooks\YourClass::class;
To handle data before it's being loaded to the backend fields:
$GLOBALS ['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][\YourNamespace\FormDataProvider\YourOtherClass::class]['depends'][0] = TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseEditRow::class;
For loading into the frontend or template you need in your setup typoscript:
tt_content {
your_content_element_name =< lib.contentElement
your_content_element_name {
templateRootPaths {
1 = EXT:your_extension_name/Resources/Private/Templates/
}
partialRootPaths {
1 = EXT:your_extension_name/Resources/Private/Partials/
}
templateName = YourTemplateName
dataProcessing {
1 = YourNamespace\DataProcessing\YourClassProcessor
}
}
}
All those classes can be compared to the corresponding core classes.
I hope this helps someone in the future.
Kind regards!

Related

Typo3 getting data and convert it to specific xml schema

i am new to typo3, so sorry, if this is too obvious.
I do not expect a complete solution, just the topics i would need to read about in order to solve the task would be perfectly enough. :)
Here the task:
I have a typo 3 installation with job advertisements in it. Now the company wants to publish that data in to a social website, which needs to have the job advertisement data put on a server in an xml feed, which looks like this: http://www.kununu.com/docs#jobfeed. Don't worry about what it says in there, it's just stuff like Job Title, Description etc.
Like i said, i am completely new to this and just have a vague idea.
My thoughts so far were something like this:
I probably need to write a plugin, which pulls the data out of typo3 by the push of a button
That Plugin need to establish a database connection to pull the data (probably it's mysql, but i am not entirely sure yet)
The data need to be formatted, which is either done by some string operations or by some kind of xml handler i assume.
Sidenote: I read something about TypoScript, but i'd like to avoid that, since it's a one time project and probably not worth the time to learn it. For me at least.
Thank you loads for your help in advance.
Cheers
you can handle that (basicly with typoscript). The other part has to come from PHP (F.e. extbase plugin) ... First part creates the XML output. Second part uses my Demo plugin to include data (Pages+special fields) from DB.
Within TS we are able to create a new typeNum. With that you can call your XML. ( ?type=1234 ) Within the BE you can select each page for output.
If you need help just contact me. I would send you the plugin.
sitemap = PAGE
sitemap {
typeNum = 1234
config {
# Set charset to utf-8
metaCharset = utf-8
# Deactivate TYPO3 Header Code
disableAllHeaderCode = 1
# Content-type settings
additionalHeaders = Content-type:text/xml;charset=utf-8
# Do not cache the page
no_cache = 1
# No xhtml cleaning trough TYPO3
xhtml_cleaning = 0
}
10 = USER_INT
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
pluginName = Sitemap
extensionName = Srcxmlprovider
controller = Sitemap
vendorName = Sourcecrew
action = exportXml
switchableControllerActions {
Sitemap {
1 = exportXml
}
}
}
}
Ich habe die EXT noch schnell ins TER gepushed. Ein Tutorial liegt innerhalb.
http://typo3.org/extensions/repository/view/srcxmlprovider

Drupal - fetch body text of a node via URL?

I'm trying to create a function to retrieve and display just the Body field of a Drupal node, based on a given URL.
Currently, I've extended the functionality of the standard Drupal RSS to do a detection method. This will happen if you enter the following url:
http://mysite.com/rss.xml/page=54
That last part is critical - it tells what node ID to load from. As far as code goes, I've modified the node_feed() function in /modules/node/node.module to do the following:
if (stristr($nids, 'page=') !== FALSE) {
$nid = substr($nids, stripos($nids, 'page=') + 5);
$result = NULL;
if ((string)(int)$nid === $nid) {
$result = db_result(db_query("SELECT `nid` FROM {node} WHERE `nid` = %s AND `type` = 'flashnode'", $nid));
}
if ($result) {
$item = node_load($result);
print($item->body);
}
exit;
}
While this works, we're worried about it for two reasons:
1) Do the results cache? This is a very heavy-load page that will be called a lot.
2) Is there an "official" way to do this? One that uses modules with caching, instead of a semi-hacky workaround?
Thanks in advance for any guidance.
-Tom
You should definitely not be hacking apart the RSS feed in order to create a URL that returns a node's body. You should create a very simple custom module: http://drupal.org/developing/modules
The Drupal module system is lets you set up a url so that something like /fetch_body/1234 calls the fetch_body() function with $nid=1234 as the parameter. As for caching, you have a lot of options in your custom module. The most obvious would be to use cache_get() and cache_set() to do simple caching on your own based on the node ID.
What version of Drupal are you using? I would highly recommend the book Pro Drupal Development, just make sure to get the edition that matches your drupal version.

Typo3 +TV not rendering content elements

I have installed typo3, templavoila and mapped a template.
Everything works fine, except my content elements. They just don't appear. They did before I installed templavoila and mapped a template.
Also, when using
10 = RECORDS
10 {
tables = tt_content
source = 9
}
it does not give me any output.
even nothing with:
10 = RECORDS
10 {
tables = tt_content
source = 9
conf.tt_content = TEXT
conf.tt_content.value = TEST
}
Does anyone have a clue as to what I might be doing wrong?
You must include the css styled content static template in your TS template.
In your ts page object you need to assign it to the templavoila object.
# Default PAGE object:
page = PAGE
page.typeNum = 0
page.10 = USER
page.10.userFunc = tx_templavoila_pi1->main_page
Probably the page, where tt_content is situated is not visible to regular visitor ?
In this case, following snippet will help.
10 = RECORDS
10.tables = tt_content
10.source = 9
10.dontCheckPid = 1
Finally we got it to work. Don't know what I did wrong, but I guess I learned not to do it again.
I'll put the "solution" here since someone might find it helpful and lose more than a day over this like I did.
Solution:
copy an existing content element in list mode, pasted it on a page via page mode
This was to test if that would do anything. Guess what, everything worked again. Not only the newly copied element but also ALL other test elements created via different ways on different pages and storage folders.
Thank you all for helping and thinking along.

Creating configurable product programmatically

I'm trying to create configurable products programmatically in Magento 1.5.1.
I understand I need first to create simple related products, what I did. Now I manage to associate these simple products to make a configurable one.
Here is the critical part...
I keep the ids and some of the attributes values in an array, so I can later make my configurable product, but some of them are missing, I don't know which method to call.
I found this entry in Magento Wiki, that helped me and seems to fit my needs.
However, at the end the author is setting two things :
$product->setConfigurableProductsData($data);
$product->setConfigurableAttributesData($data);
and the values in the arrays have been taken in the admin page source using Firebug....and then translated into PHP arrays (array example for the first call) :
"I’ve harcoded the values for my associated products and attribute
data. You can get attribute data by viewing the source through the
admin interface and using Firebug for Firefox."
$data = array('5791'=>array('0'=>array('attribute_id'=>'491', // I already got this
'label'=>'vhs', // this too
'value_index'=>'5', // but what is value_index ?
'is_percent'=>0,
'pricing_value'=>'')),
'5792'=>array('0'=>array('attribute_id'=>'491',
'label'=>'dvd',
'value_index'=>'6',
'is_percent'=>0,
'pricing_value'=>'')));
My question is : is there a way to retrieve these values without using Firebug (which in my script won't help me a lot !), but programmatically. I already found a way to retrieve attribute values, labels, etc... using its code, but one field I don't know is value_index.
I guess this may be the option position in an option list, but not sure.
Also if someone knows a good/better way to create a configurable product in Magento, please tell me.
Any help is welcome thank you.
It seems you're asking where to retrieve the value_index value where you already have the label. Here's what I had: I didn't test this on 1.5x.
function get_attribute_id($option, $type) {
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $type);
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute->getSource()->getAllOptions();
foreach ($attributeOptions as $opts_arr) {
if (strtoupper($opts_arr['label']) == strtoupper($option)) {
return $opts_arr['value'];
}
}
return FALSE;
}
$value_index = get_attribute_id('vhs', 'media_format');
No one else seemed to mention the easiest way to figure out what the value_index of vhs is: In the backend, under
Catalog > Manage > media_format > Manage Label/Options
Inspect the source of the individual form inputs. Where you have 'vhs' you should have an input named option[value][6]
As far as I understand your question, there are two options: a) create simple products by script, put the generated id's in an array and create the configurables using the ids or b) read the id's from the admin and put them in your script. Since programming is about automation I'd definately go for option a.

Difference between hook_node_type() and hook_nodeapi()

I'm trying to understand the difference between hook_node_type and hook_nodeapi
I've tried to use hook_node_type with the story node and a simple dsm but got nothing.
function mymod_node_story($op, $info){
dsm($info);
}
hook_node_type is made to hook into when a node type is changed. Fx if you want to allow comments on node type story etc.
hook_nodeapi is used to be able to hook into the different processes that can happen to an actual node, like when a node is saved, when it's being viewed etc.
There's not a hook for specific nodes, but instead you usually do something like this.
function module_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
if ($node->type == 'story') {
switch ($op) {
case 'load':
...
}
}
}
hook_node_type() is invoked each time a content type is deleted, or renamed. The purpose of the hook is to rename the Drupal variables used for the content type (which is automatically done for any form field included in the content type edit form, from node_type_form_submit()), or to delete the Drupal variables containing values for the content type that has been deleted.
hook_nodeapi() is invoked for each node when it's loaded from the database, the node edit form is shown, the node is visualized, when the node is being indexed from the search module, when a RSS feed, or the node is saved. A module should implement hook_nodeapi() to alter nodes for content types implemented by other modules.

Categories