Webiny\Component\Entity\Attribute\AbstractAttribute::getParent PHP Method

getParent() public method

Get entity instance this attribute belongs to
public getParent ( ) : AbstractEntity
return Webiny\Component\Entity\AbstractEntity
    public function getParent()
    {
        return $this->parent;
    }

Usage Example

Example #1
0
 /**
  * @inheritDoc
  */
 public function validate(AbstractAttribute $attribute, $data, $params = [])
 {
     if (empty($data)) {
         return;
     }
     $query = [$attribute->attr() => $data];
     $id = $attribute->getParent()->id;
     if ($id) {
         $query['id'] = ['$ne' => $id];
     }
     $exists = call_user_func_array([$attribute->getParent(), 'findOne'], [$query]);
     if ($exists) {
         throw new ValidationException('A record with this attribute value already exists.');
     }
 }