public function addOrRestore(array $data): \Translations\Model\Entity\Language
    {
        if (empty($data['code'])) {
            throw new InvalidArgumentException("Language data is missing 'code' key");
        }

        if (empty($data['is_rtl'])) {
            $data['is_rtl'] = $this->isRtl($data['code']);
        }

        if (empty($data['name'])) {
            $data['name'] = $this->getName($data['code']);
        }

        /**
         * @var \Cake\Datasource\EntityInterface $deletedEntity
         */
        $deletedEntity = $this->find('onlyTrashed')
            ->where(['code' => $data['code']])
            ->first();

        if (!empty($deletedEntity)) {
            return $this->restoreTrash($deletedEntity);
        }

        $newEntity = $this->newEntity();
        $newEntity = $this->patchEntity($newEntity, $data);
        /**
         * @var \Translations\Model\Entity\Language $result
         */
        $result = $this->save($newEntity);

        return $result;
    }
public function addOrRestore(array $data): \Translations\Model\Entity\Language
    {
        if (empty($data['code'])) {
            throw new InvalidArgumentException("Language data is missing 'code' key");
        }

        if (empty($data['is_rtl'])) {
            $data['is_rtl'] = $this->isRtl($data['code']);
        }

        if (empty($data['name'])) {
            $data['name'] = $this->getName($data['code']);
        }

        /**
         * @var \Cake\Datasource\EntityInterface $deletedEntity
         */
        $deletedEntity = $this->find('onlyTrashed')
            ->where(['code' => $data['code']])
            ->first();

        if (!empty($deletedEntity)) {
            return $this->restoreTrash($deletedEntity);
        }

        $newEntity = $this->newEntity();
        $newEntity = $this->patchEntity($newEntity, $data);
        /**
         * @var \Translations\Model\Entity\Language $result
         */
        $result = $this->save($newEntity);

        return $result;
    }
public function addOrRestore ( array $ data ) : \ Translations \ Model \ Entity \ Language { if ( empty ( $ data [ 'code' ] ) ) { throw new InvalidArgumentException ( "Language data is missing 'code' key" ) ; } if ( empty ( $ data [ 'is_rtl' ] ) ) { $ data [ 'is_rtl' ] = $ this -> isRtl ( $ data [ 'code' ] ) ; } if ( empty ( $ data [ 'name' ] ) ) { $ data [ 'name' ] = $ this -> getName ( $ data [ 'code' ] ) ; } /**
         * @var \Cake\Datasource\EntityInterface $deletedEntity
         */ $ deletedEntity = $ this -> find ( 'onlyTrashed' ) -> where ( [ 'code' => $ data [ 'code' ] ] ) -> first ( ) ; if ( ! empty ( $ deletedEntity ) ) { return $ this -> restoreTrash ( $ deletedEntity ) ; } $ newEntity = $ this -> newEntity ( ) ; $ newEntity = $ this -> patchEntity ( $ newEntity , $ data ) ; /**
         * @var \Translations\Model\Entity\Language $result
         */ $ result = $ this -> save ( $ newEntity ) ; return $ result ; }
Add a new language or restore a deleted one

@throws \InvalidArgumentException when data is wrong or incomplete
@param mixed[] $data Language data to populate Entity with
@return \Translations\Model\Entity\Language
Add a new language or restore a deleted one