Project

General

Profile

Actions

Task #68157

closed

Extended TypeConverter PersistentObjectConverter to overload QuerySettings

Added by Manuel Selbach over 9 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Should have
Category:
Extbase
Target version:
-
Start date:
2015-07-15
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

Hi @ all,

e.g. if you would like to pass a hidden object to another action, you will run in an exception.

#1297759968: Exception while property mapping at property path "":Missing storage page ids

By default TYPO3 sets the QuerySettings to enable ignore fields, which is absolutely fine.
But in some special cases you would like to overload this behavior for an action in the controller.
Here we can use the initialize action, which is called before every action and set the QuerySettings for a certain object.

Attached you will find my patch to allow this.

Example after supplying the patch for a controller show action:


    public function initializeShowAction()
    {
        $modelConfiguration = $this->arguments->getArgument('object')->getPropertyMappingConfiguration();
        $modelConfiguration->setTypeConverterOptions(
            'TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
            array(
                \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::IGNORE_ENABLE_FIELDS => true,
                \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::RESPECT_STORAGE_PAGE => false,
                \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::RESPECT_SYS_LANGUAGE => false,
            )
        );
    }

    /**
     * show action
     *
     * @param \MyVendor\MyExtension\Domain\Model\Model $user
     */
    public function showAction(\MyVendor\MyExtension\Domain\Model\Model $model)
    {
        $this->view->assign('model', $model);
    }

Following options will be available with example data:

IGNORE_ENABLE_FIELDS = true|false
RESPECT_STORAGE_PAGE = true|false
RESPECT_SYS_LANGUAGE = true|false
ENABLE_FIELDS_TO_BE_IGNORED = hidden,starttime
INCLUDE_DELETED = true|false
SYS_LANGUAGE_UID = 2
STORAGE_PAGE_IDS = 1,2

Files

Actions #1

Updated by Manuel Selbach over 9 years ago

Sorry there is a typo at this line in the example code

- $modelConfiguration = $this->arguments->getArgument('object')->getPropertyMappingConfiguration();
+ $modelConfiguration = $this->arguments->getArgument('model')->getPropertyMappingConfiguration();

and at:

- * @param \MyVendor\MyExtension\Domain\Model\Model $user
+ * @param \MyVendor\MyExtension\Domain\Model\Model $model

Hope the example helps to understand how it could work.

Thanks to all

Actions #2

Updated by Anja Leichsenring over 9 years ago

  • Subject changed from Extended TypoConverter PersistentObjectConverter to overload QuerySettings to Extended TypeConverter PersistentObjectConverter to overload QuerySettings

Updated by Manuel Selbach over 9 years ago

To simplify the testing of the patch I provide an example extension here with some demo data.

Hope everything works.

Install the extension.
Include the static template and set a storage to the "FeUsers" sysFolder in the "Constant Editor" for the extension.

Test instruction:
- Disable the FeUser in the sysFolder
- Go to the page "patchtest"
- the form will be filled out to fasten up the testing process ;)
- proceed all steps
-> result should be an active FeUser with an email set, if you provide some in step two ;)

Actions #5

Updated by Gerrit Code Review over 9 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 http://review.typo3.org/41441

Actions #6

Updated by Frank Nägler over 8 years ago

  • Status changed from Under Review to New
Actions #7

Updated by Riccardo De Contardi about 6 years ago

  • Category set to Extbase
Actions #8

Updated by Susanne Moog over 5 years ago

  • Status changed from New to Needs Feedback
  • Assignee set to Manuel Selbach

@Manuel can you come up with a review / fix for this issue and is it still relevant?

Actions #9

Updated by Helmut Hummel over 5 years ago

  • Status changed from Needs Feedback to Accepted

@Susi: This is still relevant and there is a patch set already on Gerrit, which I'd consider good enough to build upon. It is abandoned, but should imho be restored.

Actions #10

Updated by Susanne Moog over 5 years ago

@Helmut Thanks for the feedback :)

Actions #11

Updated by Stefan Froemken over 1 year ago

  • Status changed from Accepted to Closed

Hello,

thank you for providing that issue.
Instead of modifying the QuerySettings at a further position I prefer registering the hidden object in the extbase session object:

...
protected Session $session;
...
public function injectSession(Session $session): void
{
    $this->session = $session;
}
...
public function initializeWhatEverAction(): void
{
    if ($this->request->hasArgument('product')) {
        $product = $this->request->getArgument('product');
        $this->session->registerObject($this->productRepository->findHiddenByUid((int)$product), (string)$product);
    }
}

and in the Repo:

public function findHiddenByUid(int $uid): Product
{
    $query = $this->createQuery();
    $query->getQuerySettings()->setEnableFieldsToBeIgnored(['disabled']);
    $query->getQuerySettings()->setIgnoreEnableFields(true);
    return $query->matching($query->equals('uid', $uid))->execute()->getFirst();
}

I will close the ticket now. If you feel this is the wrong decision, let me know, and I will re-open it.

Stefan

Actions #12

Updated by Helmut Hummel over 1 year ago

Stefan Froemken wrote in #note-11:

Instead of modifying the QuerySettings at a further position I prefer registering the hidden object in the extbase session object:

That is a quite clever workaround, which however does not work, when there is no repository class for the object that should be mapped,
or the repository class is third party code.

I will close the ticket now. If you feel this is the wrong decision, let me know, and I will re-open it.

Are there any blockers to implement a configurable PersistentObjectConverter?

Actions

Also available in: Atom PDF