-
-
Save econic/7302684 to your computer and use it in GitHub Desktop.
How to ignore the enablefields in an extbase 1:1 relation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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