public function getAttributes($entity)
    {
        if ($entity->has($this->idField)) {
            $hidden = array_merge($entity->getHidden(), [$this->idField]);
            $entity->setHidden($hidden);
        }

        $attributes = $entity->toArray();

        // remove associated data so it won't appear inside jsonapi `attributes`
        foreach ($this->_repository->associations() as $association) {
            $propertyName = $association->getProperty();

            if ($association->type() === Association::MANY_TO_ONE) {
                $foreignKey = $association->getForeignKey();
                unset($attributes[$foreignKey]);
            }

            unset($attributes[$propertyName]);
        }

        // dasherize attribute keys (like `created_by`) if need be
        if ($this->_view->viewVars['_inflect'] === 'dasherize') {
            foreach ($attributes as $key => $value) {
                $dasherizedKey = Inflector::dasherize($key);

                if (!array_key_exists($dasherizedKey, $attributes)) {
                    $attributes[$dasherizedKey] = $value;
                    unset($attributes[$key]);
                }
            }
        }

        return $attributes;
    }
public function getAttributes($entity)
    {
        if ($entity->has($this->idField)) {
            $hidden = array_merge($entity->getHidden(), [$this->idField]);
            $entity->setHidden($hidden);
        }

        $attributes = $entity->toArray();

        // remove associated data so it won't appear inside jsonapi `attributes`
        foreach ($this->_repository->associations() as $association) {
            $propertyName = $association->getProperty();

            if ($association->type() === Association::MANY_TO_ONE) {
                $foreignKey = $association->getForeignKey();
                unset($attributes[$foreignKey]);
            }

            unset($attributes[$propertyName]);
        }

        // dasherize attribute keys (like `created_by`) if need be
        if ($this->_view->viewVars['_inflect'] === 'dasherize') {
            foreach ($attributes as $key => $value) {
                $dasherizedKey = Inflector::dasherize($key);

                if (!array_key_exists($dasherizedKey, $attributes)) {
                    $attributes[$dasherizedKey] = $value;
                    unset($attributes[$key]);
                }
            }
        }

        return $attributes;
    }
public function getAttributes ( $ entity ) { if ( $ entity -> has ( $ this -> idField ) ) { $ hidden = array_merge ( $ entity -> getHidden ( ) , [ $ this -> idField ] ) ; $ entity -> setHidden ( $ hidden ) ; } $ attributes = $ entity -> toArray ( ) ; // remove associated data so it won't appear inside jsonapi `attributes` foreach ( $ this -> _repository -> associations ( ) as $ association ) { $ propertyName = $ association -> getProperty ( ) ; if ( $ association -> type ( ) === Association :: MANY_TO_ONE ) { $ foreignKey = $ association -> getForeignKey ( ) ; unset ( $ attributes [ $ foreignKey ] ) ; } unset ( $ attributes [ $ propertyName ] ) ; } // dasherize attribute keys (like `created_by`) if need be if ( $ this -> _view -> viewVars [ '_inflect' ] === 'dasherize' ) { foreach ( $ attributes as $ key => $ value ) { $ dasherizedKey = Inflector :: dasherize ( $ key ) ; if ( ! array_key_exists ( $ dasherizedKey , $ attributes ) ) { $ attributes [ $ dasherizedKey ] = $ value ; unset ( $ attributes [ $ key ] ) ; } } } return $ attributes ; }
NeoMerx override used to pass entity root properties to be shown
as JsonApi `attributes`.

@param \Cake\Datasource\EntityInterface $entity Entity
@return array
NeoMerx override used to pass entity root properties to be shown as JsonApi attributes .