Project

General

Profile

Actions

Bug #50551

closed

The itemsProcFunc configuration array has wrong pid from the 2nd content element on a page

Added by Tobias Klepp over 10 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Backend API
Target version:
-
Start date:
2013-07-30
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
5.3
Tags:
Complexity:
hard
Is Regression:
Sprint Focus:

Description

I use in my plugin flexform definition an items proc function to generate my items in a special way.

<tags>
  <TCEforms>
    <exclude>1</exclude>
    <label>LLL:EXT:extkey/locallang_db.xml:tt_content.pi_flexform.tags</label>
    <config>
      <type>select</type>
      <foreign_table>tx_extkey_tags</foreign_table>
      <foreign_table_where>ORDER BY tx_extkey_tags.sorting</foreign_table_where>
      <size>5</size>
      <minitems>0</minitems>
      <maxitems>99</maxitems>
      <itemsProcFunc>tx_extkey_tca->addTagItems</itemsProcFunc>
    </config>
  </TCEforms>
</tags>

The class looks like this:

final class tx_extkey_tca {

  public function addTagItems($config) {
    var_dump($config);
    return $config;
  }
}

If I add the plugin as the first content element on a page, the $config array look fine. $config['row']['pid'] is set to the current page id.

If I add the plugin a second time or more in the same page, $config['row']['pid'] is not set to the current page id. It is a strange negative value like -67.


Files

flexParentDatabaseRow.png (4.89 KB) flexParentDatabaseRow.png Andreas Kalkhoff, 2021-10-28 14:40

Related issues 1 (1 open0 closed)

Related to TYPO3 Core - Bug #95814: The itemsProcFunc configuration array has wrong pid from the 2nd content element on a pageNew2021-10-29

Actions
Actions #1

Updated by Philipp Gampe over 10 years ago

Can you ask on the dev list? Someone (you?) will need to debug this.

Actions #2

Updated by Ernesto Baschny over 10 years ago

  • Target version deleted (next-patchlevel)
Actions #3

Updated by Tobias Klepp over 10 years ago

If I would like to debug this, what data dou you need?

Actions #4

Updated by Philipp Gampe over 10 years ago

Well, we need to take a look at the code flow to figure out where the values are coming from. The code flow should be the same for both plugins, but as the result is different, there must be some kind of error in there.

The stacktrace should be a first hint, otherwise you have to move backwards from the wrong and right value.

Actions #5

Updated by Philipp Gampe over 10 years ago

  • Status changed from New to Needs Feedback
Actions #6

Updated by Tobias Klepp over 10 years ago

I looked into the code and find the problem. The problem is the wrong link parameter on the "Add new record at this place" button below an existing content element. If I compare the link parameters, it looks like this:

window.location.href='db_new_content_el.php?id=94&colPos=0&sys_language_uid=0&uid_pid=94&returnUrl=...
window.location.href='db_new_content_el.php?id=94&sys_language_uid=0&colPos=0&uid_pid=-68&returnUrl=...

I found the link generation in typo3\sysext\backend\Classes\View\PageLayoutView.php on line 479

$onClick = 'window.location.href=\'db_new_content_el.php?id=' . $row['pid'] . '&sys_language_uid=' . $row['sys_language_uid'] . '&colPos=' . $row['colPos'] . '&uid_pid=' . -$row['uid'] . '&returnUrl=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI')) . '\';';

This code is only used for the new content element icon below an existing content element. I didn't understand, why for the uid_pid parameter not $row['pid'] is used. If I jump to line 1454 the following code generate the params:

$onClick = 'window.location.href=\'db_new_content_el.php?id=' . $id . '&colPos=' . $colPos . '&sys_language_uid=' . $sys_language . '&uid_pid=' . $id . '&returnUrl=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI')) . '\';';

So in my eyes, there is a bug in the code in line 479 and the code must look like this:

$onClick = 'window.location.href=\'db_new_content_el.php?id=' . $row['pid'] . '&sys_language_uid=' . $row['sys_language_uid'] . '&colPos=' . $row['colPos'] . '&uid_pid=' . $row['pid'] . '&returnUrl=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI')) . '\';';

But I have not the big overview about the TYPO3 code to be sure with my solution. Also the step to negate the uid is not understandable for me. Please look also at line 481:

$params = '&edit[tt_content][' . -$row['uid'] . ']=new';

Here is also a negative uid used. Is that right?
Hopefully my research helps. If I used my solution, it works fine for me.

Actions #7

Updated by Philipp Gampe over 10 years ago

  • Category set to Backend API
  • Status changed from Needs Feedback to Accepted
  • Complexity set to hard

I do not know that code very well, thus I need to look into this myself.

Anyway, thanks for your findings. This helps a lot for further error analysis.

Actions #8

Updated by Klaus Moser about 10 years ago

Just found out that the negative id is the inverted uid of the previous content element on the same page.

To get the right page uid in the itemsProcFunc I used this pice of code:

$this->contentElementPid = $config['row']['pid'];

// if $config['row']['pid'] is < 0 then it points
// to the previous content element on the same page
if ($this->contentElementPid < 0) {
    $parentRec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord(
            'tt_content',
            abs($this->contentElementPid),
            'pid'
    );

    $this->contentElementPid = $parentRec['pid'];
}
Actions #9

Updated by Vitoandre D'Oria almost 9 years ago

Great findings Klaus Moser! Got the same problem in latest 6.2 :-)

Actions #10

Updated by Georg Ringer about 4 years ago

  • Status changed from Accepted to Resolved

the code base changed a lot since the report has been created. nowadays it is safe to use with something like $config['flexParentDatabaseRow']['pid']

Actions #11

Updated by Benni Mack about 4 years ago

  • Status changed from Resolved to Closed
Actions #12

Updated by Andreas Kalkhoff over 2 years ago

Seems like this problem has returned; ran into this problem with Typo3 10.4.21.
When I click "+ Content" after any element on a page "$config['flexParentDatabaseRow']['pid']" returns that prior element's uid as negative as pid. I do only get the proper pid on the topmost "+ Content" that's not affiliated to a content element.

E.g.:
On Page ID 345
(1) "+ Content"
(2) tt_content element uid 123 (any type, text or whatever)
(3) "+ Content"

(1) $config['flexParentDatabaseRow']['pid'] returns "345"
(3) $config['flexParentDatabaseRow']['pid'] returns "-123"

Actions #13

Updated by Andreas Kalkhoff over 2 years ago

  • Related to Bug #95814: The itemsProcFunc configuration array has wrong pid from the 2nd content element on a page added
Actions

Also available in: Atom PDF