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);
    }