/** * Check if value can be assigned to current attribute<br> * * If Entity has an ID and attribute 'once' flag is set and attribute has a value assigned to it * then a new value should not be assigned. * * @return bool */ protected function canAssign() { if ($this->entity->getId()->getValue() && $this->getOnce() && $this->value !== null) { return false; } return true; }
/** * Set or get attribute value * * @return bool|null|\Webiny\Component\Entity\EntityAbstract */ public function getValue() { if ($this->isNull($this->value)) { $query = [$this->relatedAttribute => $this->entity->getId()->getValue()]; $query = array_merge($query, $this->filter); $callable = [$this->entityClass, 'find']; $this->value = call_user_func_array($callable, [$query]); } return $this->value; }
/** * Get default list of entity attributes.<br> * Only simple and Many2One attributes are considered to be default attributes. * * @return string */ private function getDefaultAttributes() { $attributes = []; foreach ($this->entity->getAttributes() as $name => $attribute) { $isOne2Many = $this->isInstanceOf($attribute, AttributeType::ONE2MANY); $isMany2Many = $this->isInstanceOf($attribute, AttributeType::MANY2MANY); if ($isOne2Many || $isMany2Many) { continue; } $attributes[] = $name; } return $this->arr($attributes)->implode(',')->val(); }