Stephan Grass
Stephan Grass

Reputation: 132

Edit hidden records in frontend

I am building an extension to edit tt_news records in frontend. I set setIgnoreEnableFields(TRUE) in my repository. But if I try edit a hidden record, I get the error

Object with identity „12345" not found.

Any solution for this?

Upvotes: 0

Views: 543

Answers (2)

René Pflamm
René Pflamm

Reputation: 3354

The problem is the PropertyMapping. If extbase try to assign an uid (12345) to an Domain Object (tt_news) the "setEnableFields" setting of the Repository isn't respected. So you must fetch the object by yourself.

the simple solution is to do this in an initialize*Action for each "show" action. For editAction an example:

public function initializeEditAction() {
  if ($this->request->hasArgument('news')) {
    $newsUid = $this->request->getArgument('news');

    if (!$this->newsRepository->findByUid($newsUid)) {
      $defaultQuerySettings = $this->newsRepository->createQuery()->getQuerySettings();
      $defaultQuerySettings->setIgnoreEnableFields(TRUE);
      $this->newsRepository->setDefaultQuerySettings($defaultQuerySettings);

      if ($news = $this->newsRepository->findByUid($newsUid)) {
        $this->request->setArgument('news', $news);
      }
    }
  }
}

The Hard Part is to get the object to update. As I never try this I have found an TypeConverter to fetch also hidden Records at https://gist.github.com/helhum/58a406fbb846b56a8b50

Maybe Instead to register the TypeConverter for everything (like the example in ext_localconf.php) you can try to assign it only in the initializeUpdateAction

public function initializeUpdateAction() {
  if ($this->arguments->hasArgument('news')) {
    $this->arguments->getArgument('news')->getPropertyMappingConfiguration()
      ->setTypeConverter('MyVendor\\MyExtension\\Property\\TypeConverters\\MyPersistenObjectConverter')
  }
}

Upvotes: 1

Georg Ringer
Georg Ringer

Reputation: 7939

I am guessing you are using an action like

/**
 * Single view of a news record
 *
 * @param \Vendor\Ext\Domain\Model\News $news news item
 */
public function detailAction(\Vendor\Ext\Domain\Model\News $news = null)

Your problem is, that the Repository is not used to fetch the record.


As a solution, remove the argument, clear the caches and try something like that

/**
 * Single view of a news record
 *
 * @param \Vendor\Ext\Domain\Model\News $news news item
 */
public function detailAction() {
    $id = (int)$this->request->getArgument('news');
    if ($id) {
        $news = $this->newsRepository->findByUid($previewNewsId);
    }
}

Now you can manipulate the QuerySettings and use those.

Upvotes: 2

Related Questions