Project

General

Profile

Actions

Bug #63777

closed

ItemsProcFunc doesnt work on create record via IRRE

Added by André Wuttig over 9 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
FormEngine aka TCEforms
Target version:
-
Start date:
2014-12-11
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

I have a table called "tx_pxbmecat_domain_model_product" where i can create features which are stored in the table "tx_pxbmecat_domain_model_productfeature". Within this table is a field called "feature_template". The possible select-field values are retrieved via userFunc, because they are related on the category of the parent product (very special, but neccessary). When i edit a IRRE-Record everything works fine. When i create a new one, i should retrieve the product uid from gpVar ajax string which comes via as you used it in TYPO3\CMS\Backend\Form\Element\InlineElement. Then i also retrieve the allowed featureTemplates from db und set them via call by reference to $fConfig['items']. But nothing happens in the select-field :(


return array(
    'ctrl' => ...

    'columns' => array(       
        'features' => array(
            'exclude' => 1,
            'label' => 'LLL:EXT:px_bmecat/Resources/Private/Language/locallang_db.xlf:tx_pxbmecat_domain_model_product.features',
            'config' => array(
                'type' => 'inline',
                'foreign_table' => 'tx_pxbmecat_domain_model_productfeature',
                'foreign_field' => 'product',
                'maxitems'      => 9999,
                'appearance' => array(
                    'collapseAll' => 1,
                    'levelLinksPosition' => 'top',
                    'showSynchronizationLink' => 1,
                    'showPossibleLocalizationRecords' => 1,
                    'showAllLocalizationLink' => 1
                )
            )
        )
    )
);



<?php
if (!defined ('TYPO3_MODE')) {
    die ('Access denied.');
}

return array(
    'ctrl' => ...
    'columns' => array(        
        'feature_template' => array(
            'exclude' => 1,
            'label' => 'LLL:EXT:px_bmecat/Resources/Private/Language/locallang_db.xlf:tx_pxbmecat_domain_model_productfeature.feature_template',
            'config' => array(
                'type' => 'select',
                'multiple' => '1',
                'itemsProcFunc' => 'Portrino\PxBmecat\ItemsProcFunc\ProductFeature->getFeatureTemplates',
                'items' => array(),
                'size' => '10',
                'autosizemax' => '10',
                'maxitems' => '99',
                'minitems' => '0',
                'MM' => 'tx_pxbmecat_product_feature_feature_template_mm',
                'foreign_table' => 'tx_pxbmecat_domain_model_classificationgroupfeaturetemplate',
                'foreign_table_where' => 'ORDER BY tx_pxbmecat_domain_model_classificationgroupfeaturetemplate.name',
                'wizards' => array(
                    '_PADDING' => 5,
                    '_HORIZONTAL' => 1,
                    'suggest' => array(
                        'type' => 'suggest'
                    ),
                    'add' => array(
                        'type' => 'popup',
                        'title' => 'LLL:EXT:px_bmecat/Resources/Private/Language/locallang_db.xlf:tx_pxbmecat_domain_model_productfeature.feature_template.new',
                        'icon' => 'add.gif',
                        'params' => array(
                            'table'=>'tx_pxbmecat_domain_model_classificationgroupfeaturetemplate',
                            'pid' => '###PAGE_TSCONFIG_ID###',
                            'setValue' => 'prepend'
                        ),
                        'script' => 'wizard_add.php',
                        'JSopenParams' => 'height=600, width=800, status=0, menubar=0, scrollbars=1',
                    ),
                    'edit' => array(
                        'type' => 'popup',
                        'title' => 'LLL:EXT:px_bmecat/Resources/Private/Language/locallang_db.xlf:tx_pxbmecat_domain_model_productfeature.feature_template.edit',
                        'script' => 'wizard_edit.php',
                        'popup_onlyOpenIfSelected' => 1,
                        'icon' => 'edit2.gif',
                        'JSopenParams' => 'height=600, width=800, status=0, menubar=0, scrollbars=1',
                    )
                )
            )
        ),
    )
);



/**
 * Class ProductFeature
 *
 * @package Portrino\PxBmecat\Domain\ItemsProcFunc
 */
class ProductFeature {

    const Structure_Separator = '-';
    const FlexForm_Separator = '---';
    const FlexForm_Substitute = ':';
    const Prepend_Naming = 'data';

    /**
     * @param array $fConfig
     * @param \TYPO3\CMS\Backend\Form\FormEngine $fObj
     *
     * @return void
     */
    public function getFeatureTemplates(&$fConfig, $fObj) {
        $pluginConfiguration = array(
            'extensionName' => 'PxBmecat',
            'pluginName' => 'Fe1'
        );

        /** @var \TYPO3\CMS\Extbase\Core\Bootstrap $bootstrap */
        $bootstrap = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Core\\Bootstrap');
        $bootstrap->initialize($pluginConfiguration);
        /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
        $persistenceManager = $objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager');
        /** @var \Portrino\PxBmecat\Domain\Repository\ProductFeatureRepository $productRepository */
        $productRepository = $objectManager->get('Portrino\\PxBmecat\\Domain\\Repository\\ProductRepository');

            // unset old items array
        $gpVar = \TYPO3\CMS\Core\Utility\GeneralUtility::_GPmerged('ajax');
        if (isset($fConfig['row']['product'])) {
            $productUid = (int)$fConfig['row']['product'];
            $fConfig['items'] = array();
        } else if (count($gpVar) > 0 && isset($gpVar[1])) {
                // get the product from ajax gpVar, when record was created via IRRE
            $string = $gpVar[1];
                // Substitute FlexForm additon and make parsing a bit easier
            $string = str_replace(self::FlexForm_Separator, self::FlexForm_Substitute, $string);
                // The starting pattern of an object identifer (e.g. "data-<firstPidValue>-<anything>)
            $pattern = '/^' . self::Prepend_Naming . self::Structure_Separator . '(.+?)' . self::Structure_Separator . '(.+)$/';

            if (preg_match($pattern, $string, $match)) {
                $parts = explode(self::Structure_Separator, $match[2]);
                if ($parts[0] === 'tx_pxbmecat_domain_model_product') {
                    $productUid = (int)$parts[1];
                }
            }
        }

        if ($productUid) {
            /** @var \Portrino\PxBmecat\Domain\Model\Product $product */
            $product = $productRepository->findByUid($productUid);
            if ($product && $product->getCategory()) {
                /** @var \Portrino\PxBmecat\Domain\Model\ClassificationGroupFeatureTemplate $featureTemplate */
                foreach ($product->getCategory()->getFeatureTemplatesRecursive() as $featureTemplate) {
                    array_push($fConfig['items'], array(
                        $featureTemplate->getLabel(),
                        $featureTemplate->getUid()
                    ));
                }
            }
        }
    }
}


Actions #1

Updated by Antoine Bouet about 9 years ago

I have the same problem.

Any ideas how to fix it ?

Actions #2

Updated by Oliver Hader over 8 years ago

  • Assignee deleted (Oliver Hader)
Actions #3

Updated by Chris Müller over 4 years ago

The issue still exists in TYPO3 v9.

Problem: the ItemsProcFunc receives for a newly created IRRE child element an array, where the fields of the child record are almost empty (key "row"), only the fields pid, uid and l10n_parent are set. The configured parent field is empty.

Actions #4

Updated by Gerrit Code Review over 4 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61480

Actions #5

Updated by Gerrit Code Review over 4 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61480

Actions #6

Updated by Gerrit Code Review over 4 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61480

Actions #7

Updated by Gerrit Code Review over 4 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61480

Actions #8

Updated by Gerrit Code Review over 4 years ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61480

Actions #9

Updated by Chris Müller over 4 years ago

Additional information:
I need this fix in the (unpublished) extension https://github.com/brotkrueml/schema-records

There is a tx_schemarecords_domain_model_type.php record where you can select a schema_type. Dependent on that value, select options for an IRRE child (tx_schemarecords_domain_model_property.php record, field "name") are shown with the help of an ItemsProcFunc. This ItemsProcFunc reads the parent value of the current row. This works when the IRRE record still exists. But if it is new, the parent is empty, hence the options cannot be shown (I set them to default options when parent is empty because the field is required).

Actions #10

Updated by Gerrit Code Review over 4 years ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61480

Actions #11

Updated by Gerrit Code Review over 4 years ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61480

Actions #12

Updated by Gerrit Code Review over 4 years ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61480

Actions #13

Updated by Gerrit Code Review over 4 years ago

Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61480

Actions #14

Updated by Gerrit Code Review about 4 years ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63294

Actions #15

Updated by Chris Müller about 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #16

Updated by Benni Mack about 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF