public function bootRunTime(Object $object, Configs $configs) { if (!$object->hasRelation($this->getFieldDefinition()->getId())) { $relation = new RelationDefinition(); $relation->setName($this->getFieldDefinition()->getId()); $relation->setType(AbstractStorage::ONE_TO_MANY); $relation->setForeignObjectKey('jarves/content'); $relation->setRefName($object->getId()); $object->addRelation($relation); $configs->addReboot('Added auto relation because of PageContents type.'); } if (!$object->hasField('layout')) { $field = new Field(); $field->setId('layout'); $field->setType('text'); $object->addField($field); $configs->addReboot('PageContents needs `layout` field.'); } if (!$object->hasField('theme')) { $field = new Field(); $field->setId('theme'); $field->setType('text'); $object->addField($field); $configs->addReboot('PageContents needs `theme field.'); } }
/** * * array( * 'items' => $items, * 'count' => $maxItems, * 'pages' => $maxPages * ); * * @param array $filter * @param integer $limit * @param integer $offset * @param string $query * @param string $fields * @param array $orderBy * * @param bool $withAcl * @param array $primaryKeys * * @return array * @throws ObjectNotFoundException * @throws \Exception */ public function getItems($filter = null, $limit = null, $offset = null, $query = '', $fields = null, $orderBy = [], $withAcl = false, array $primaryKeys = []) { $options = array(); $storageController = $this->objects->getStorageController($this->getObject()); $options['offset'] = $offset; $options['limit'] = $limit ? $limit : $this->defaultLimit; $condition = $this->getCondition(); if ($extraCondition = $this->getCustomListingCondition()) { $condition->mergeAnd($extraCondition); } $options['order'] = $orderBy ?: $this->getOrder(); $options['fields'] = $this->getItemsSelection($fields); $options['permissionCheck'] = $this->getPermissionCheck(); $aclRequest = ACLRequest::create($this->getObject())->onlyListingMode(); if ($this->getPermissionCheck() && !$this->acl->check($aclRequest)) { return null; } if ($limit = $this->getObjectDefinition()->getLimitDataSets()) { $condition->mergeAnd($limit); } if ($this->getMultiLanguage() && $this->getLanguage()) { if ($this->getObjectDefinition()->getNestedRootAsObject() && ($rootObjectKey = $this->getObjectDefinition()->getNestedRootObject())) { $rootObjects = $this->objects->getList($rootObjectKey, null, ['lang' => $this->getLanguage(), 'fields' => 'id']); $langConditions = new Condition(); foreach ($rootObjects as $item) { $langConditions->addOr(['domain', '=', $item['id']]); } $condition->addAnd($langConditions); } else { //does the object have a lang field? if ($this->objectDefinition->hasField('lang') && !isset($filter['lang'])) { $filter['lang'] = $this->getLanguage(); } } } if ($query) { if ($queryCondition = $this->getQueryCondition($query, $options['fields'])) { $condition->mergeAnd($queryCondition); } } if ($primaryKeys) { $primaryKeyCondition = Condition::create(); foreach ($primaryKeys as $pk) { $primaryKeyConditionItem = Condition::create(); foreach ($this->getObjectDefinition()->getPrimaryKeyNames() as $primaryKeyName) { if (!isset($pk[$primaryKeyName])) { throw new \LogicException(sprintf('Field %s not found in primaryKey parameter (%s)', $primaryKeyName, json_encode($pk))); } $primaryKeyConditionItem->addAnd([$primaryKeyName, '=', $pk[$primaryKeyName]]); } $primaryKeyCondition->mergeOr($primaryKeyConditionItem); } $condition->mergeAndBegin($primaryKeyCondition); } if ($this->getPermissionCheck() && ($aclCondition = $this->acl->getListingCondition($this->getObject()))) { $condition->mergeAndBegin($aclCondition); } $items = $storageController->getItems($filter, $condition, $options); if ($withAcl && is_array($items)) { foreach ($items as &$item) { if ($item) { $this->prepareRow($item); } } } return $items ?: null; }