Skip to content

Instantly share code, notes, and snippets.

@econic
Created November 4, 2013 13:47
Show Gist options
  • Save econic/7302684 to your computer and use it in GitHub Desktop.
Save econic/7302684 to your computer and use it in GitHub Desktop.
How to ignore the enablefields in an extbase 1:1 relation
<?php
namespace Example\Key\Domain\Model;
class Foo {
/**
* BarRepository
*
* @var \Example\Key\Domain\Repository\BarRepository
* @inject
*/
protected $barRepository;
/**
* save reference only as integer
*
* @var integer
*/
protected $bar;
/**
* Returns the Bar
*
* @return \Example\Key\Domain\Model\Bar $bar
*/
public function getBar() {
return $this->barRepository->findByUid($this->bar, true);
}
/**
* Sets the Bar
*
* @param \Example\Key\Domain\Model\Bar $bar
* @return this
*/
public function setBar(\Example\Key\Domain\Model\Bar $bar) {
$this->bar = $bar->getUid();
return $this;
}
}
<?php
namespace Example\Key\Domain\Repository;
class BarRepository {
/**
* Override default findByUid function to enable also the option to turn off
* the enableField setting
*
* @param integer $uid id of record
* @param boolean $ignoreEnableFields if set to true, hidden records are shown
* @return \Example\Key\Domain\Model\Bar
*/
public function findByUid($uid, $ignoreEnableFields = false) {
$query = $this->createQuery();
$query->getQuerySettings()->setIgnoreEnableFields($ignoreEnableFields);
return $query->matching(
$query->logicalAnd(
$query->equals('uid', $uid),
$query->equals('deleted', 0)
)
)->execute()->getFirst();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment