protected function _attributesForEntity(EntityInterface $entity)
    {
        $bundle = $this->_resolveBundle($entity);
        $attrs = $this->_toolbox->attributes($bundle);
        $attrByIds = []; // attrs indexed by id
        $attrByNames = []; // attrs indexed by name

        foreach ($attrs as $name => $attr) {
            $attrByNames[$name] = $attr;
            $attrByIds[$attr->get('id')] = $attr;
            $attr->set(':value', null);
        }

        if (!empty($attrByIds)) {
            $instances = $this->Attributes->Instance
                ->find()
                ->where(['eav_attribute_id IN' => array_keys($attrByIds)])
                ->all();
            foreach ($instances as $instance) {
                if (!empty($attrByIds[$instance->get('eav_attribute_id')])) {
                    $attr = $attrByIds[$instance->get('eav_attribute_id')];
                    if (!$attr->has('instance')) {
                        $attr->set('instance', $instance);
                    }
                }
            }
        }

        $values = $this->_fetchValues($entity, array_keys($attrByNames));
        foreach ($values as $value) {
            if (!empty($attrByNames[$value->get('eav_attribute')->get('name')])) {
                $attrByNames[$value->get('eav_attribute')->get('name')]->set(':value', $value);
            }
        }

        return $this->_toolbox->attributes($bundle);
    }
protected function _attributesForEntity(EntityInterface $entity)
    {
        $bundle = $this->_resolveBundle($entity);
        $attrs = $this->_toolbox->attributes($bundle);
        $attrByIds = []; // attrs indexed by id
        $attrByNames = []; // attrs indexed by name

        foreach ($attrs as $name => $attr) {
            $attrByNames[$name] = $attr;
            $attrByIds[$attr->get('id')] = $attr;
            $attr->set(':value', null);
        }

        if (!empty($attrByIds)) {
            $instances = $this->Attributes->Instance
                ->find()
                ->where(['eav_attribute_id IN' => array_keys($attrByIds)])
                ->all();
            foreach ($instances as $instance) {
                if (!empty($attrByIds[$instance->get('eav_attribute_id')])) {
                    $attr = $attrByIds[$instance->get('eav_attribute_id')];
                    if (!$attr->has('instance')) {
                        $attr->set('instance', $instance);
                    }
                }
            }
        }

        $values = $this->_fetchValues($entity, array_keys($attrByNames));
        foreach ($values as $value) {
            if (!empty($attrByNames[$value->get('eav_attribute')->get('name')])) {
                $attrByNames[$value->get('eav_attribute')->get('name')]->set(':value', $value);
            }
        }

        return $this->_toolbox->attributes($bundle);
    }
protected function _attributesForEntity ( EntityInterface $ entity ) { $ bundle = $ this -> _resolveBundle ( $ entity ) ; $ attrs = $ this -> _toolbox -> attributes ( $ bundle ) ; $ attrByIds = [ ] ; // attrs indexed by id $ attrByNames = [ ] ; // attrs indexed by name foreach ( $ attrs as $ name => $ attr ) { $ attrByNames [ $ name ] = $ attr ; $ attrByIds [ $ attr -> get ( 'id' ) ] = $ attr ; $ attr -> set ( ':value' , null ) ; } if ( ! empty ( $ attrByIds ) ) { $ instances = $ this -> Attributes -> Instance -> find ( ) -> where ( [ 'eav_attribute_id IN' => array_keys ( $ attrByIds ) ] ) -> all ( ) ; foreach ( $ instances as $ instance ) { if ( ! empty ( $ attrByIds [ $ instance -> get ( 'eav_attribute_id' ) ] ) ) { $ attr = $ attrByIds [ $ instance -> get ( 'eav_attribute_id' ) ] ; if ( ! $ attr -> has ( 'instance' ) ) { $ attr -> set ( 'instance' , $ instance ) ; } } } } $ values = $ this -> _fetchValues ( $ entity , array_keys ( $ attrByNames ) ) ; foreach ( $ values as $ value ) { if ( ! empty ( $ attrByNames [ $ value -> get ( 'eav_attribute' ) -> get ( 'name' ) ] ) ) { $ attrByNames [ $ value -> get ( 'eav_attribute' ) -> get ( 'name' ) ] -> set ( ':value' , $ value ) ; } } return $ this -> _toolbox -> attributes ( $ bundle ) ; }
Gets all attributes that should be attached to the given entity, this entity
will be used as context to calculate the proper bundle.

@param \Cake\Datasource\EntityInterface $entity Entity context
@return array
Gets all attributes that should be attached to the given entity this entity will be used as context to calculate the proper bundle .