Bug #63777

ItemsProcFunc doesnt work on create record via IRRE

Added by André Wuttig over 4 years ago. Updated over 3 years ago.

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

0%

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()
                    ));
                }
            }
        }
    }
}


History

#1 Updated by Antoine Bouet about 4 years ago

I have the same problem.

Any ideas how to fix it ?

#2 Updated by Oliver Hader over 3 years ago

  • Assignee deleted (Oliver Hader)

Also available in: Atom PDF